简体   繁体   English

在Android和IOS上加载了什么h.264格式?

[英]What h.264 format loads on android AND IOS?

Theoretically both IOS and ANDROID will play h.264 files, but I can't figure out a setting to encode them so they actually work cross platform. 从理论上讲,IOS和ANDROID都会播放h.264文件,但我无法找出对它们进行编码的设置,因此它们实际上可以跨平台工作。 Does anybody know how to encode for both Android and IOS using one file? 有人知道如何使用一个文件对Android和IOS进行编码吗?

ps I know all about html5 video and the fallback sources, I just don't want to encode and host a new video for every device that comes down the pike. ps我知道关于html5视频和后备源的所有内容,我只是不想为每个下来的派克设备编码和托管新视频。

Here's the ffmpeg command line we use to transcode to MPEG-4 h.264 in our production environment. 这是我们在生产环境中用于转码为MPEG-4 h.264的ffmpeg命令行。 We've tested the output on several Android devices, as well as iOS. 我们已经在几个Android设备以及iOS上测试了输出。 You can use this as a starting point, just tweaking things like frame size/frame rate and qfactor. 您可以将此作为起点,只需调整帧大小/帧速率和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}

Some of the important options affecting Android compatibility are: 影响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

After we encode our video with this ffmpeg recipe, we also pass the video through qt-faststart . 在使用此ffmpeg配方对视频进行编码后,我们还通过qt-faststart传递视频。 This step rechunks the video for streaming. 此步骤重新播放视频以进行流式传输。 We stream it over HTTP to an embedded VideoView within our Android app. 我们通过HTTP将其流式传输到Android应用中的嵌入式VideoView。 No problems streaming to any Android device we're aware of. 没有问题流式传输到我们知道的任何Android设备。

Update 2013-06-17: I just wanted to add a note that it's best to stick with "baseline" profile for H.264 encoding for maximum compatibility across all Android devices. 更新2013-06-17:我只想添加一条说明,最好坚持使用H.264编码的“基线”配置文件,以便在所有Android设备上实现最大兼容性。 The above command line doesn't explicitly specify an H.264 profile, but ffmpeg does have a -profile command line flag that is useful if you are using its presets . 上面的命令行没有明确指定H.264配置文件,但ffmpeg确实有一个-profile 命令行标志,如果您使用它的预设,它会很有用 You probably shouldn't mess with -profile . 你可能不应该-profile I have encoded videos for my ASUS Transformer 300 tablet (Android 4.2) using "main" rather than "baseline" profile (via Handbrake). 我使用“主要”而不是“基线”配置文件(通过Handbrake)为我的ASUS Transformer 300平板电脑(Android 4.2)编码了视频。 The "main" profile gave problems with audio getting out of sync with video on playback. “主要”配置文件存在音频与播放时视频不同步的问题。

I used this to make an Android and iOS app with embedded videos. 我用这个来制作带有嵌入式视频的Android和iOS应用程序。 The videos played in both versions. 这两个版本都播放了视频。 ( Android example ) ( iOS example ) Android示例 )( iOS示例

Supplemental answer 补充答案

This answer is a supplement to the accepted answer explaining some of the parameters. 这个答案是对接受的答案的补充,解释了一些参数。

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

Feel free to edit this if you can fill in some of the details I wasn't sure about. 如果您可以填写我不确定的一些细节,请随意编辑。

Here it is again in a cut-and-paste format. 这里再次采用剪切和粘贴格式。 (I also had to add the -strict -2 parameter to get aac to work on my computer.) (我还必须添加-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

Further Study 进一步研究

Most of this information I found at the following links: 我在以下链接中找到的大部分信息:

See also 也可以看看

See Android Supported Media Formats , which states that h.264 is only supported in Android 3.0+. 请参阅Android支持的媒体格式 其中指出h.264仅在Android 3.0+中受支持。 Earlier versions of Android support h.263. 早期版本的Android支持h.263。 EDIT : As mportuesisf mentions below, I misinterpreted the linked table. 编辑 :正如下面提到的mportuesisf,我误解了链接表。 Ignore this answer. 忽略这个答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM