【发布时间】:2011-09-15 21:22:57
【问题描述】:
理论上,IOS 和 ANDROID 都可以播放 h.264 文件,但我无法确定对它们进行编码的设置,因此它们实际上可以跨平台工作。有人知道如何使用一个文件同时为 Android 和 IOS 进行编码吗?
附言我对 html5 视频和后备资源了如指掌,我只是不想为每台出现故障的设备编码和托管新视频。
【问题讨论】:
标签: iphone android ffmpeg html5-video h.264
理论上,IOS 和 ANDROID 都可以播放 h.264 文件,但我无法确定对它们进行编码的设置,因此它们实际上可以跨平台工作。有人知道如何使用一个文件同时为 Android 和 IOS 进行编码吗?
附言我对 html5 视频和后备资源了如指掌,我只是不想为每台出现故障的设备编码和托管新视频。
【问题讨论】:
标签: iphone android ffmpeg html5-video h.264
这是我们在生产环境中用于转码为 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。此步骤重新分块视频以进行流式传输。我们通过 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 混淆。我使用“主”而不是“基线”配置文件(通过手刹)为我的华硕 Transformer 300 平板电脑(Android 4.2)编码了视频。 “主要”配置文件会出现音频与播放视频不同步的问题。
【讨论】:
我用它制作了一个带有嵌入式视频的 Android 和 iOS 应用程序。在两个版本中播放的视频。 (Android example) (iOS example)
此答案是对解释某些参数的已接受答案的补充。
ffmpeg
-y # Overwrite output files without asking.
-i input_filename # input file name
-s 432x320 # size of output file
-b:v 384k # bitrate for video
-vcodec libx264 # use H.264 video codec
-flags +loop+mv4 # use loop filter and four motion vector by macroblock
-cmp 256 # ??? Full pel motion estimation compare function
-partitions +parti4x4+parti8x8+partp4x4+partp8x8 #???
-subq 6 # determines algorythms for subpixel motion searching and partition decision
-trellis 0 # optimal rounding choices
-refs 5 # number of frames referenced prior to current frame
-bf 0 # turn of B-frames, something to do with H.264 and Baseline Profile
-flags2 +mixed_refs # ??? gave me an error so I just deleted it
-coder 0 # turn of the CABAC entropy encoder
-me_range 16 # max range of the motion search
-g 250 # GOP length (250 is the recommended default)
-keyint_min 25 # Minimum GOP length (25 is the recommended default)
-sc_threshold 40 # adjusts sensitivity of x264's scenecut detection (default is 40)
-i_qfactor 0.71 # Qscale difference between I-frames and P-frames (0.71 is the recommended default)
-qmin 10 -qmax 51 # min and max quantizer (10 and 51 are the recommended defaults)
-qdiff 4 # max QP step (4 is recommended default)
-c:a aac # Set the audio codec to use AAC
-ac 1 # number of audio channels
-ar 16000 # audio sampling frequency
-r 13 # frames per second
-ab 32000 # audio bitrate
-aspect 3:2 # sample aspect ratio
output_filename # name of the output file
如果您可以填写一些我不确定的细节,请随时编辑。
这里又是剪切粘贴格式。 (我还必须添加-strict -2 参数才能让aac 在我的计算机上工作。)
ffmpeg -y -i input_file.avi -s 432x320 -b:v 384k -vcodec libx264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8 -subq 6 -trellis 0 -refs 5 -bf 0 -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -c:a aac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 -strict -2 output_file.mp4
我在以下链接中找到了大部分信息:
【讨论】:
请参阅Android Supported Media Formats,其中指出仅在 Android 3.0+ 中支持 h.264。早期版本的 Android 支持 h.263。 编辑:正如 mportuesisf 在下面提到的,我误解了链接表。忽略这个答案。
【讨论】: