为什么这个加密的HLS视频不能在iOS上播放(但可以通过hls.js库在Windows Chrome上播放)?

k2fxgqgv  于 2023-05-19  发布在  iOS
关注(0)|答案(2)|浏览(346)

我正在尝试播放MP4测试视频。
我的/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')
用于将视频加密为具有“ts”文件的HLS播放列表的ffmpeg命令:

'/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'

然后,我从www.example.com了解到https://caniuse.com/#search=hls,如果没有库,Windows Chrome将无法播放HLS视频,所以我使用https://github.com/video-dev/hls.js/Windows Chrome成功播放了加密视频!

但是,iOS Safari无法播放(无论是否使用hls.js库)。

在iOS Safari上,当我尝试播放视频时,我只看到一个快速的一瞥(不到一秒),其中**屏幕显示0:15,因此它必须阅读和解密足够的时间才能知道视频的正确持续时间。
所以,为了调试,我记录事件:

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
        }
    });
});

我在控制台日志中看到:

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

我不知道如何找到有关错误的更多详细信息。
请注意,即使Windows Chrome成功播放视频,它也会在控制台日志中显示警告:

{"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":{...

我的问题在哪里?

yh2wf1be

yh2wf1be1#

我需要购买新的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。

jtjikinw

jtjikinw2#

iPhone设备不支持媒体源扩展。
你应该通过用户代理检查有没有iPhone?
如果是正确的,你应该使用iPhone本地视频播放器播放hls视频类型或更多的视频类型

相关问题