【问题标题】:What h.264 format loads on android AND IOS?android 和 IOS 上加载什么 h.264 格式?
【发布时间】:2011-09-15 21:22:57
【问题描述】:

理论上,IOS 和 ANDROID 都可以播放 h.264 文件,但我无法确定对它们进行编码的设置,因此它们实际上可以跨平台工作。有人知道如何使用一个文件同时为 Android 和 IOS 进行编码吗?

附言我对 html5 视频和后备资源了如指掌,我只是不想为每台出现故障的设备编码和托管新视频。

【问题讨论】:

    标签: iphone android ffmpeg html5-video h.264


    【解决方案1】:

    这是我们在生产环境中用于转码为 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)编码了视频。 “主要”配置文件会出现音频与播放视频不同步的问题。

    【讨论】:

    • 这是一篇极好的帖子。谢谢!
    • 只是想补充一点,尽管它在我测试过的大多数机器人(lg ally、Droid X、HTC evo、nexus s)上都能在 iPhone 上完美运行,但视频显示了一条消息,要求进行蒸汽或下载,如果你选择流它会失败。可能只是需要一些调整设置,我不知道为什么它至少没有进行渐进式下载,可能只是 android 浏览器。
    • 我在原始答案中添加了关于流兼容性的先前评论,以使其更加完整。
    • +1 对于 ffmpeg 命令行,althgouth,所有这些设置真的有必要吗?
    • 我想提供一套完整的命令行参数。有时你真的想明确地说明一些事情,而不是对 ffmpeg 默认值进行(可能的)更改,从而得到与你想要的不同的输出。
    【解决方案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
    

    进一步研究

    我在以下链接中找到了大部分信息:

    另见

    【讨论】:

      【解决方案3】:

      请参阅Android Supported Media Formats,其中指出仅在 Android 3.0+ 中支持 h.264。早期版本的 Android 支持 h.263。 编辑:正如 mportuesisf 在下面提到的,我误解了链接表。忽略这个答案。

      【讨论】:

      • 这是不正确的。 Android 3.0+ 添加了对编码的 h.264 支持。早期版本的 Android 可以正常播放 h.264。在对内容进行编码以在 Android 上播放时,您需要仔细选择编码参数,这是 OP 所要求的。通常,您希望使用“基线配置文件”进行编码,以便与 Android 设备兼容。
      • Android 2.1+ 支持解码h.264。
      • @mportuesisf:你是对的,我的错误。我忽略了“编码器”列,并假设“Android 3.0+”注释适用于编码和解码。
      猜你喜欢
      • 2013-10-21
      • 2022-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-06
      • 2018-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多