为什么这个加密的 HLS 视频不能在 iOS 上播放(但可以通过 hls.js 库在 Windows Chrome 上播放)?
Why won't this encrypted HLS video play on iOS (but works on Windows Chrome via hls.js library)?
原始视频来自https://www.appsloveworld.com/download-sample-mp4-video-mp4-test-videos/。"Sample Video 5"。
我的/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')
用于将视频加密为 HLS 播放列表 "ts" 个文件的 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'
然后,我从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/得知,WindowsChrome成功播放加密视频!
但是,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":{...
我的问题在哪里?
我需要购买更新的 iPhone。
我在 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 看到说 HLS 需要 >=13.2。
Iphone 设备不支持媒体源扩展。
你应该通过用户代理检查有iphone?
如果正确,您应该使用 iphone 原生视频播放器来播放 hls 视频类型或更多视频类型
原始视频来自https://www.appsloveworld.com/download-sample-mp4-video-mp4-test-videos/。"Sample Video 5"。
我的/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')
用于将视频加密为 HLS 播放列表 "ts" 个文件的 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'
然后,我从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/得知,WindowsChrome成功播放加密视频!
但是,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":{...
我的问题在哪里?
我需要购买更新的 iPhone。
我在 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 看到说 HLS 需要 >=13.2。
Iphone 设备不支持媒体源扩展。
你应该通过用户代理检查有iphone?
如果正确,您应该使用 iphone 原生视频播放器来播放 hls 视频类型或更多视频类型