Android 和 IOS 上加载什么 h.264 格式?
理论上,IOS 和 ANDROID 都可以播放 h.264 文件,但我无法找到对它们进行编码的设置,以便它们实际上可以跨平台工作。有人知道如何使用一个文件同时为 Android 和 IOS 进行编码吗?
ps 我了解 html5 视频和后备源的所有信息,我只是不想为每个设备编码和托管新视频。
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. Does anybody know how to encode for both Android and IOS using one file?
p.s. 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我们在生产环境中用于转码为 MPEG-4 h.264 的 ffmpeg 命令行。我们已经在多种 Android 设备以及 iOS 设备上测试了输出。您可以使用它作为起点,只需调整帧大小/帧速率和 qfactor 等内容。
影响 Android 兼容性的一些重要选项包括:
使用此 ffmpeg 配方对视频进行编码后,我们还通过 qt- 传递视频快速启动。此步骤将重新分块视频以进行流式传输。我们通过 HTTP 将其流式传输到 Android 应用程序中的嵌入式 VideoView。流式传输到我们所知的任何 Android 设备都没有问题。
2013-06-17 更新:我只是想添加一条注释,即最好坚持使用 H.264 编码的“基线”配置文件,以便在所有 Android 设备上实现最大兼容性。上面的命令行没有明确指定 H.264 配置文件,但 ffmpeg 确实有一个
-profile
如果您使用其预设,则命令行标志非常有用。您可能不应该弄乱-profile
。我使用“main”而不是“baseline”配置文件(通过 Handbrake)为我的 ASUS Transformer 300 平板电脑(Android 4.2)编码视频。 “主要”配置文件出现了播放时音频与视频不同步的问题。Here's the ffmpeg command line we use to transcode to MPEG-4 h.264 in our production environment. We've tested the output on several Android devices, as well as iOS. You can use this as a starting point, just tweaking things like frame size/frame rate and qfactor.
Some of the important options affecting Android compatibility are:
After we encode our video with this ffmpeg recipe, we also pass the video through qt-faststart. This step rechunks the video for streaming. We stream it over HTTP to an embedded VideoView within our Android app. No problems streaming to any Android device we're aware of.
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. 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. You probably shouldn't mess with-profile
. I have encoded videos for my ASUS Transformer 300 tablet (Android 4.2) using "main" rather than "baseline" profile (via Handbrake). The "main" profile gave problems with audio getting out of sync with video on playback.我用它制作了一个带有嵌入式视频的 Android 和 iOS 应用程序。视频在两个版本中均播放。 (Android 示例)(iOS示例)
补充答案
此答案是对解释某些参数的已接受答案的补充。
如果您可以填写一些我不确定的详细信息,请随时编辑此内容。
这里再次采用剪切粘贴格式。 (我还必须添加
-strict -2
参数才能使aac
在我的计算机上工作。)进一步研究
我在以下链接中找到了大部分信息:
另请参阅
I used this to make an Android and iOS app with embedded videos. The videos played in both versions. (Android example) (iOS example)
Supplemental answer
This answer is a supplement to the accepted answer explaining some of the parameters.
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 getaac
to work on my computer.)Further Study
Most of this information I found at the following links:
See also
请参阅 Android 支持的媒体格式,
其中指出 h.264仅在 Android 3.0+ 中受支持。早期版本的 Android 支持 h.263。编辑:正如 mportuesisf 下面提到的,我误解了链接表。忽略这个答案。See Android Supported Media Formats,
which states that h.264 is only supported in Android 3.0+. Earlier versions of Android support h.263.EDIT: As mportuesisf mentions below, I misinterpreted the linked table. Ignore this answer.