我应该如何选择要在 Web、Android 和 iOS 上播放的视频格式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26172770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:06:13  来源:igfitidea点击:

How should I choose a video format to be played on Web, Android & iOS?

androidiosvideobrowser

提问by cannabis

I am working on a video sharing project and wonder what if there's a video format that is compatible with most players on Web, Android & iOS.

我正在做一个视频共享项目,想知道是否有一种视频格式与 Web、Android 和 iOS 上的大多数播放器兼容。

The app will work like this:

该应用程序将像这样工作:

  1. users can take videos from mobile devices (iOS and Android)
  2. other users can play videos on mobile devices (iOS and Android) and web browsers.
  1. 用户可以从移动设备(iOS 和 Android)拍摄视频
  2. 其他用户可以在移动设备(iOS 和 Android)和网络浏览器上播放视频。

I am not familiar with different video formats. I noticed that .mov and .mp4 are used in iOS. But I assume .mov cannot be played on Android and web browsers except Safari? Could anyone give a hint?

我不熟悉不同的视频格式。我注意到 iOS 中使用了 .mov 和 .mp4。但我认为 .mov 不能在 Android 和网络浏览器上播放,除了 Safari?谁能给个提示?

回答by Andrew T.

From Android Developer - Supported media formats,

来自Android Developer - 支持的媒体格式

Type  | Format /  | Supported File Type(s) /
      | Codec     | Container Formats
------+-----------+----------------------------------------------------------
Video | H.263     | 3GPP     (.3gp)
      |           | MPEG-4   (.mp4)
      +-----------+----------------------------------------------------------
      | H.264 AVC | 3GPP     (.3gp)
      |           | MPEG-4   (.mp4)
      |           | MPEG-TS  (.ts, AAC audio only, not seekable, Android 3.0+)
      +-----------+----------------------------------------------------------
      | H.265 HEVC| MPEG-4   (.mp4, Android 5.0+)
      +-----------+------------------------------------------------------
      | MPEG-4 SP | 3GPP     (.3gp)
      +-----------+----------------------------------------------------------
      | VP8       | WebM     (.webm)
      |           | Matroska (.mkv, Android 4.0+)
      +-----------+----------------------------------------------------------
      | VP9       | WebM     (.webm)
      |           | Matroska (.mkv, Android 4.0+)

On the other hand, from iOS Developer Library - Media Layer,

另一方面,从iOS Developer Library - Media Layer

iOS supports many industry-standard video formats and compression standards, including the following:

  • H.264 video, up to 1.5 Mbps, 640 by 480 pixels, 30 frames per second, Low-Complexity version of the H.264 Baseline Profile with AAC-LC audio up to 160 Kbps, 48 kHz, stereo audio in .m4v, .mp4, and .mov file formats

  • H.264 video, up to 768 Kbps, 320 by 240 pixels, 30 frames per second, Baseline Profile up to Level 1.3 with AAC-LC audio up to 160 Kbps, 48 kHz, stereo audio in .m4v, .mp4, and .mov file formats

  • MPEG-4 video, up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps, 48 kHz, stereo audio in .m4v, .mp4, and .mov file formats

  • Numerous audio formats, including the ones listed in Audio Technologies

iOS 支持许多行业标准的视频格式和压缩标准,包括:

  • H.264 视频,高达 1.5 Mbps,640 x 480 像素,每秒 30 帧,H.264 基线配置文件的低复杂度版本,具有高达 160 Kbps、48 kHz 的 AAC-LC 音频,.m4v 中的立体声音频, .mp4 和 .mov 文件格式

  • H.264 视频,高达 768 Kbps,320 x 240 像素,每秒 30 帧,基线配置文件高达 1.3 级,AAC-LC 音频高达 160 Kbps,48 kHz,立体声音频为 .m4v、.mp4 和 . mov 文件格式

  • MPEG-4 视频,最高 2.5 Mbps,640 x 480 像素,每秒 30 帧,带有 AAC-LC 音频的简单配置文件,最高 160 Kbps,48 kHz,.m4v、.mp4 和 .mov 文件格式的立体声音频

  • 多种音频格式,包括音频技术中列出的格式

Also, from MDN - Media formats supported by the HTML audio and video elements(<video>tag in HTML5),

此外,来自MDN - HTML 音频和视频元素支持的媒体格式<video>HTML5 中的标签),

  • <video>: VP8 and Vorbis in WebM
  • <video>: VP9 and Opus in WebM
  • <video>: Streaming WebM via MSE
  • <video>: Theora and Vorbis in Ogg
  • <video>: H.264 and MP3 in MP4
  • <video>: H.264 and AAC in MP4
  • <video>: FLAC in MP4
  • <video>: WebM 中的 VP8 和 Vorbis
  • <video>: WebM 中的 VP9 和 Opus
  • <video>: 通过 MSE 流式传输 WebM
  • <video>: Theora and Vorbis in Ogg
  • <video>: MP4 中的 H.264 和 MP3
  • <video>: MP4 中的 H.264 和 AAC
  • <video>: MP4 中的 FLAC

From all data, it seems that .mp4(to be exact, H.264 video, AAC audio, in MPEG-4) is the choice here, since it's supported in all platforms (iOS, Android, web browser). However, take note that you still have to check for compatibility issues on each platform (different version of Android, different web browser), which is explained on each site.

从所有数据来看,似乎.mp4(确切地说,H.264 视频,AAC 音频,在 MPEG-4 中)是这里的选择,因为它在所有平台(iOS、Android、Web 浏览器)中都受支持。但是,请注意,您仍然需要检查每个平台(不同版本的 Android、不同的网络浏览器)上的兼容性问题,这在每个站点上都有说明。

回答by Chintan Soni

Adding more info from Andrew T.'s answer.

从 Andrew T. 的回答中添加更多信息。

To set the parameters from Andrew's conclusion:

从 Andrew 的结论中设置参数:

// To Set Audio Encoder: AAC
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

// To set Video Encoder: H264
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

// To set Output Video format: mp4
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

Hope it helps...!!!

希望能帮助到你...!!!