How to pick proper video dimension based on device resolution - ios

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.

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)

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

Related

Does AVPlayer support webm URL in iOS?

I have created player in iOS. It works well for URLs such as mp4 and m3u8.
But I have one webm extension URL. AVPlayer is not working for this.
Sample url:
http://images.all-free-download.com/footage_preview/webm/dead_trees_146.webm
Is there any reason? Or can we make something possible to play this url?
From the apple docs:
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.
It doesn't support WebM. You may try using a library like OGVKit to play WebM videos.

-11855 error code when using AVFoundation with high res video. What resolution should I use?

Using react-native-video to play a simple video it fails at resolutions greater than 1024x768 on older devices (ipad 2, ipad 3rd gen (A1416)) with the error below.
{
"target": 4,
"error": {
"code": -11855,
"domain": "AVFoundationErrorDomain"
}
}
I can't find this error in the list of AVFoundation error constants. It stops at -11852.
I have found through testing that the maximum resolution I can use on 2nd or 3rd gen ipads is 1024x768, but I can't find this documented anywhere. An ipad mini 2 can play video at 2048x2048 without trouble.
What resolution can I use that will work with all iPads?
Can I display different media like 1x and 2x images on iPads that have different capabilities?
iPad 2 has the following specifications:
Video formats supported:
H.264 video up to 1080p, 30 frames per second, High Profile level 4.1
with AAC-LC audio up to 160 Kbps, 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 per channel, 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
Source: https://support.apple.com/kb/sp622?locale=en_GB
iPad 3 has the following specifications:
Video formats supported:
H.264 video up to 1080p, 30 frames per second, High Profile level 4.1
with AAC-LC audio up to 160 Kbps, 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 per channel, 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
Source: https://support.apple.com/kb/sp647?locale=en_GB
As you can see, it doesn't support resolution greater than 1080p i.e. 1920 by 1080 so 2048 by 2048 won't work.
-18555 error description is in file AVError.h (https://developer.apple.com/reference/avfoundation/averror/averrorundecodablemediadata)
AVErrorUndecodableMediaData NS_AVAILABLE(10_10, 8_0) = -11855,
Though there is not enough description given to give a concrete conclusion but from the name we can say that it means it cannot decode the video as it's beyond device capability.

How to play a .h264 file in iOS (or) How to convert .h264 file in to .mp4 file programmatically

I have a .h264 file in my project bundle and i have to play it. I searched for long time and everybody suggested FFMPEG but there is no proper guidance. In another way at least suggest me how to convert this .h264 file in to .mp4 file programmatically by that way at least i can depend on MPMoviePlayer. Please suggest me.
Thank you.
Use the native AVFoundation framework
https://developer.apple.com/av-foundation/
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

Unable to play higher resolution video on some iPads

I'm trying to play a video using MPMoviePlayerController. On some iPads, the video plays, on other iPads it does not.
Here is the code:
NSURL *url = [NSURL fileURLWithPath:[self videoPath]];
self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
self.moviePlayerController.view.frame = self.view.bounds;
self.moviePlayerController.repeatMode = MPMovieRepeatModeOne;
self.moviePlayerController.controlStyle = MPMovieControlStyleNone;
[self.moviePlayerController prepareToPlay];
... add to subview, play ...
MPMoviePlayerController lists the following compression restrictions:
H.264 Baseline Profile Level 3.0 video, up to 640 x 480 at 30 fps.
(The Baseline profile does not support B frames.)
MPEG-4 Part 2 video (Simple Profile)
Originally, we were using H.264 at a higher resolution and the video worked with some our testers. Unfortunately, I was unable to get the video to play on my iPad (4th Generation). We kept the existing resolution and tried MPEG-4 Part 2 video but again, the video did not work. The only way we could get the video to work reliably was drastically reducing the resolution down to 480 x 640. The result looks horrible.
I added the notifications to monitor the load state and for the videos that failed to work, the modes would go from MPMovieLoadStateUnknown to MPMovieLoadStatePlayable back to MPMovieLoadStateUnknown. The videos that worked fine would go from MPMovieLoadStateUnknown to MPMovieLoadStatePlayable to MPMovieLoadStatePlayable|MPMovieLoadStatePlaythroughOK.
I checked the errorLogs and accessLogs and they were both empty.
Any thoughts on what I might check next in order to get the higher resolution video to work on the iPads?
Okay, so Apple's MPMoviePlayerController documentation is a bit out of date. I referred to each iPad's technical specs and it revealed the source of the issue:
Video formats supported: H.264 video up to 1080p, 30 frames per
second, High Profile level 4.1 with AAC-LC audio up to 160 Kbps,
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 per channel, 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
I was using videos at a higher resolution than 1080p using H.264 compression, and MPEG-4 higher than the supported resolution. Once we lowered the resolution everything worked perfectly.

Can we play .flv files in html5 video tags in ipad?

We currently have a system working on chrome,ie7 and mozilla. We have jwplayer that plays .flv videos on these browsers. We have now to support the play of videos in ipad. Will it be possible if we upgrade the jwplayer to version 5 which supports html5 video tags. Will html5 video tags in ipad be able to support play of .flv files?
The jwplayer works fine on the iPad but you will need another video type for ipad support. The iPad will not play FLV file types, as shown on the iPad Video specs page:
Video formats supported: H.264 video up to 1080p, 30 frames per second, High Profile level 4.1 with AAC-LC audio up to 160 Kbps, 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 per channel, 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

Resources