How to pick proper video dimension based on device resolution

蹲街弑〆低调 提交于 2019-12-25 09:28:23

问题


We've a demo video provided by design team with three different dimension (1024*768), (2048*1536) and (2732, 2048). I'm trying to pick proper video based on current device resolution (supported format).

For eg: If it its first generation iPad its resolution is (1024 * 768) it can play video format upto 720p more than that it will not play, likewise iPad3 (Retina) resolution is (2048 * 1536) but it can play video format upto 1080p. Similar iPad pro I guess it will play upto 4k videos.

I afraid system will not pick proper video on its own if we name it to 1x, 2x or 3x like in image.

If we are passing high dimension video to low resolution devices it is not playing. So what is the general approach in iOS to pick proper video based on its support format.


回答1:


If you did have the option to stream from a server then HLS streaming and the media player would take care of selecting the best bit rate for the device and the current network conditions.

If not then, as far as I am aware, iOS does not support different video resolutions in the same way it does images as you note above.

You can still do this yourself by querying the device resolution and choosing the appropriate video at run time based on the result. To query the screen size:

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

See here for the source of the above and for handling split screen mode: https://stackoverflow.com/a/5678199/334402

You will have to include multiple versions of your videos which will increase you bundle size, but, again, if you could stream instead you would avoid this.

To find a particular devices capabilities takes a little effort.

Firstly, you will commonly see quoted the general iOS video support information that apple provides:

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

As you point out, however, this is not the full story as different devices have different capabilities. To find the video supported for a particular devices you need to look at the info on the device tech specs page here: https://support.apple.com/specs/

For example for a first generation iPad it shows:

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

And for iPad 5th generation it shows:

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

To actually detect the device there seems to be some discussion around the best way, but it looks like someone is keeping this approach here more or less up to date: https://stackoverflow.com/a/10481095/334402 (it includes up to iPad 4 and iPhone 6 at the time of writing)




回答2:


I created a working solution for this problem by embedded m4v video data inside a PNG and then decoding and resaving the .m4v file in the tmp dir on device. Have a peek at this SO answer for details: https://stackoverflow.com/a/56383999/763355



来源:https://stackoverflow.com/questions/44000497/how-to-pick-proper-video-dimension-based-on-device-resolution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!