如何根据设备分辨率选择合适的视频尺寸

How to pick proper video dimension based on device resolution

我们有设计团队提供的演示视频,具有三个不同的尺寸(1024*768)、(2048*1536)和(2732、2048)。我正在尝试根据当前设备分辨率(支持的格式)选择合适的视频。

例如:如果它是第一代 iPad 它的分辨率是 (1024 * 768) 它可以播放高达 720p 的视频格式超过它不会播放,同样 iPad3 (Retina ) 分辨率为 (2048 * 1536) 但它可以播放高达 1080p 的视频格式。类似 iPad pro 我猜它最多可以播放 4k 视频。

如果我们将它命名为 1x、2x 或 3x,我担心系统不会自行选择合适的视频。

如果我们将高维视频传递给低分辨率设备,则它不会播放。那么 iOS 根据其支持的格式选择合适的视频的一般方法是什么。

如果您确实可以选择从服务器进行流式传输,那么 HLS 流式传输和媒体播放器将负责为设备和当前网络条件选择最佳比特率。

如果不是,那么据我所知,iOS 不支持不同的视频分辨率,就像上面提到的图像一样。

您仍然可以通过查询设备分辨率并根据结果在 运行 时间选择合适的视频来自己完成此操作。查询屏幕尺寸:

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

以上内容的来源和分屏模式的处理请看这里:

您将必须包含多个版本的视频,这会增加您的捆绑包大小,但是,如果您可以流式传输,您就可以避免这种情况。

要找到特定的设备功能需要一点努力。

首先,您通常会看到引用苹果提供的一般iOS视频支持信息:

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

然而,正如您所指出的,这并不是全部,因为不同的设备具有不同的功能。要查找特定设备支持的视频,您需要在此处查看设备技术规格页面上的信息:https://support.apple.com/specs/

例如第一代 iPad 它显示:

TV and video

  • Support for 1024 by 768 pixels with Dock Connector to VGA Adapter; 576p and 480p with Apple Component AV Cable; 576i and 480i with Apple Composite AV Cable
  • H.264 video up to 720p, 30 frames per second, Main Profile level 3.1 with AAC-LC audio up to 160 Kbps per channel, 48kHz, 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, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats; Motion JPEG (M-JPEG) up to 35 Mbps, 1280 by 720 pixels, 30 frames per second, audio in ulaw, PCM stereo audio in .avi file format

iPad 第 5 代显示:

TV and Video

  • AirPlay Mirroring, photos, audio, and video out to Apple TV (2nd generation or later)
  • Video mirroring and video out support: Up to 1080p through Lightning Digital AV Adapter and Lightning to VGA Adapter (adapters sold separately)
  • Video formats supported: H.264 video up to 4K, 30 frames per second, High Profile level 4.2 with AAC‑LC audio up to 160 Kbps, 48kHz, stereo audio or Dolby Audio up to 1008 Kbps, 48kHz, stereo or multichannel 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 per channel, 48kHz, stereo audio or Dolby Audio up to 1008 Kbps, 48kHz, stereo or multichannel audio, in .m4v, .mp4, and .mov file formats; Motion JPEG (M‑JPEG) up to 35 Mbps, 1280 by 720 pixels, 30 frames per second, audio in ulaw, PCM stereo audio in .avi file format

为了实际检测设备,似乎围绕最佳方法进行了一些讨论,但看起来有人或多或少地在此处保持这种方法的最新状态:(它包括最多 iPad 4 和 iPhone 6 在撰写本文时)

我通过在 PNG 中嵌入 m4v 视频数据,然后解码并重新保存设备上 tmp 目录中的 .m4v 文件,为这个问题创建了一个可行的解决方案。查看此 SO 答案以获取详细信息: