为什么不能在iOS上播放此加密的HLS视频(但可以通过hls.js库在Windows Chrome上运行)? [英] Why won't this encrypted HLS video play on iOS (but works on Windows Chrome via hls.js library)?

查看:786
本文介绍了为什么不能在iOS上播放此加密的HLS视频(但可以通过hls.js库在Windows Chrome上运行)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原始视频是 https://www.appsloveworld.com/download-sample-mp4-video-mp4-test-videos/.

我的/home/vagrant/Code/example/public/hls_hls.keyInfo是:

https://example.com/hls.key
/home/vagrant/Code/example/public/hls_hls.key
467216aae8a26fb699080812628031955e304a66e9e4480f9b70d31d8fe94e9a

我的/home/vagrant/Code/example/public/hls_hls.key是使用PHP生成的:hex2bin('467216aae8a26fb699080812628031955e304a66e9e4480f9b70d31d8fe94e9a')

My /home/vagrant/Code/example/public/hls_hls.key was generated using PHP: hex2bin('467216aae8a26fb699080812628031955e304a66e9e4480f9b70d31d8fe94e9a')

ffmpeg 命令,用于使用"ts"将视频加密为HLS播放列表个文件:

The ffmpeg command for encrypting the video as HLS playlist with "ts" files:

'/usr/bin/ffmpeg' '-y' '-i' 'storage/app/sample_media2/2020-02-27/Sample_Videos_5.mp4' 
'-c:v' 'libx264' '-s:v' '1920x1080' '-crf' '20' '-sc_threshold' '0' '-g' '48' 
'-keyint_min' '48' '-hls_list_size' '0' 
'-hls_time' '10' '-hls_allow_cache' '0' '-b:v' '4889k' '-maxrate' '5866k' 
'-hls_segment_type' 'mpegts' '-hls_fmp4_init_filename' 'output_init.mp4' 
'-hls_segment_filename' 'storage/app/public/test/output_1080p_%04d.ts' 
'-hls_key_info_file' '/home/vagrant/Code/example/public/hls_hls.keyInfo' 
'-strict' '-2' '-threads' '12' 'storage/app/public/test/output_1080p.m3u8'

然后,我从 https://caniuse.com/#search=hls 知道Windows Chrome无法在没有库的情况下播放HLS视频,因此我使用 https: //github.com/video-dev/hls.js/,并且 Windows Chrome浏览器成功播放了加密的视频!

Then, I know from https://caniuse.com/#search=hls that Windows Chrome won't be able to play the HLS video without a library, so I use https://github.com/video-dev/hls.js/, and Windows Chrome successfully plays the encrypted video!

但是,iOS Safari无法播放它(带有或不带有hls.js库).

在iOS Safari上,当我尝试播放视频时,我只瞥了一眼(不到一秒钟),其中屏幕显示0:15,因此它必须进行足够的读取和解密才能知道正确的视频的持续时间.

On iOS Safari, when I try to play the video, I see just a quick glimpse (less than a second) where the screen shows 0:15, so it must be reading and decrypting enough to know the correct duration of the video.

因此,为了调试,我记录了事件:

So, to debug, I log events:

const nativeHlsEvents = ['play', 'playing', 'abort', 'error', 'canplaythrough', 'waiting', 'loadeddata', 'loadstart', 'progress', 'timeupdate', 'volumechange'];
$.each(nativeHlsEvents, function (i, eventType) {
    video.addEventListener(eventType, (event) => {//https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement
        console.log(eventType, event);
        if (eventType === 'error') {
            console.error(video.error);//https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/error
        }
    });
});

我在控制台日志中看到:

I see in the console log:

loadstart, {"isTrusted":true}
progress, {"isTrusted":true}
play, {"isTrusted":true}
waiting, {"isTrusted":true}
error, {"isTrusted":true}
video.error, {}

我不知道如何找到有关该错误的更多详细信息.

I don't know how to find more details about the error.

请注意,即使Windows Chrome成功播放了视频,它也会在控制台日志中显示警告:

Note that even though Windows Chrome successfully plays the video, it too shows warnings in the console log:

{"type":"mediaError","details":"fragParsingError","fatal":false,"reason":"TS packet did not start with 0x47","frag":{"...
{"type":"mediaError","details":"fragParsingError","fatal":false,"reason":"no audio/video samples found","frag":{...

我的问题在哪里?

推荐答案

我需要购买较新的iPhone.

我在 https://en.wikipedia.org/wiki/IPhone_6#Software https://support.apple.com/guide/iphone/supported-iphone-models-iphe3fa5df43/ios 表示"6s"是iOS 13支持的最旧硬件,并且 https://caniuse.com/#search=hls 说,HLS需要> = 13.2.

I see at https://en.wikipedia.org/wiki/IPhone_6#Software and https://support.apple.com/guide/iphone/supported-iphone-models-iphe3fa5df43/ios that "6s" is the oldest hardware that iOS 13 supports, and https://caniuse.com/#search=hls says HLS needs >=13.2.

这篇关于为什么不能在iOS上播放此加密的HLS视频(但可以通过hls.js库在Windows Chrome上运行)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆