理论上,IOS 和 ANDROID 都可以播放 h.264 文件,但我无法确定对它们进行编码的设置,因此它们实际上可以跨平台工作。有人知道如何使用一个文件同时为 Android 和 IOS 进行编码吗?
附言我对 html5 视频和后备资源了如指掌,我只是不想为每台出现故障的设备编码和托管新视频。
最佳答案
这是我们在生产环境中用于转码为 MPEG-4 h.264 的 ffmpeg 命令行。我们已经在多个 Android 设备以及 iOS 上测试了输出。您可以以此为起点,只需调整帧大小/帧速率和 qfactor 等内容。
ffmpeg -y
-i #{input_file}
-s 432x320
-b 384k
-vcodec libx264
-flags +loop+mv4
-cmp 256
-partitions +parti4x4+parti8x8+partp4x4+partp8x8
-subq 6
-trellis 0
-refs 5
-bf 0
-flags2 +mixed_refs
-coder 0
-me_range 16
-g 250
-keyint_min 25
-sc_threshold 40
-i_qfactor 0.71
-qmin 10 -qmax 51
-qdiff 4
-acodec libfaac
-ac 1
-ar 16000
-r 13
-ab 32000
-aspect 3:2
#{output_file}
影响 Android 兼容性的一些重要选项是:
-coder 0 Uses CAVLAC rather than CABAC entropy encoding (CABAC not supported on Android)
-trellis 0 Should be shut off, requires CABAC
-bf 0 Turns off B-frames, not supported on Android or other h.264 Baseline Profile devices
-subq 6 Determines what algorithms are used for subpixel motion searching. 7 applies to B-frames, not supported on Android.
-refs 5 Determines how many frames are referenced prior to the current frame. Increasing this number could affect compatibility
在我们使用这个 ffmpeg 配方对视频进行编码后,我们还将视频通过 qt-faststart .此步骤重新分 block 视频以进行流式传输。我们通过 HTTP 将其流式传输到我们的 Android 应用程序中的嵌入式 VideoView。流式传输到我们知道的任何 Android 设备都没有问题。
2013-06-17 更新:我只是想补充一点,最好坚持使用 H.264 编码的“基线”配置文件,以便在所有 Android 设备上实现最大兼容性。上面的命令行没有明确指定 H.264 配置文件,但是 ffmpeg 确实有一个 -profile
command line flag that is useful if you are using its presets .你可能不应该弄乱-profile
。我使用“main”而不是“baseline”配置文件(通过 Handbrake)为我的 ASUS Transformer 300 平板电脑(Android 4.2)编码了视频。 “主要”配置文件会出现音频与播放视频不同步的问题。
关于iphone - android 和 IOS 上加载什么 h.264 格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6364190/