FFMPEG Video Encoding Settings for iOS/iPhone/iPad

deanvangreunen

New Member
Joined
Aug 22, 2019
Messages
8
Reaction score
2
What is the recommended FFMPEG settings for encoding a video which can play on all apple devices, old and new.

I would like the format to be in mp4 so that the video file is also compatible to android, windows (phone / pc) and linux.


These are the current settings I have used and they do not work on iOS, These settings work great on Windows and Android but not on iOS.

Code Block

ffmpeg -i input_video.mp4 -c:v libx264 -crf 23 -profile:v baseline -level 3.0 -pix_fmt yuv420p -c:a aac -ac 2 -b:a 128k -movflags faststart -o output_video.mp4



I'm new to developing for iPhone/iOS.

so thanks in advance.
 
Well, it's kind of an awkward question because all these OSes can't play video natively, it's up to codecs and media players to take care of that. Those settings for that mp4 work fine for Infuse and VLC for example but maybe not iOS Gallery, same for VP9, x.265 etc. and it's all software rendered.
 
Well, it's kind of an awkward question because all these OSes can't play video natively, it's up to codecs and media players to take care of that. Those settings for that mp4 work fine for Infuse and VLC for example but maybe not iOS Gallery, same for VP9, x.265 etc. and it's all software rendered.
I know that some x264 videos play on iOS but not all. I'm trying to find the perfect settings which will allow the video to play on all devices/platforms...

got any code sample or encoding settings that i could try
 
I know that some x264 videos play on iOS but not all. I'm trying to find the perfect settings which will allow the video to play on all devices/platforms...

got any code sample or encoding settings that i could try
Oh! Apologies, yeah you're right. Apart from iTunes converting it perfectly for iOS with their Quicktime framework, I'm also not sure what the "right" settings are, some of my mkv's with vp9 also exhibit this behaviour. I think it's safe to play around until you find a combo that works all the time, because the flags you picked are the recommend ones and they seem to fail sometimes too. Once you do, the other platforms shouldn't have an issue.
 
Oh! Apologies, yeah you're right. Apart from iTunes converting it perfectly for iOS with their Quicktime framework, I'm also not sure what the "right" settings are, some of my mkv's with vp9 also exhibit this behaviour. I think it's safe to play around until you find a combo that works all the time, because the flags you picked are the recommend ones and they seem to fail sometimes too. Once you do, the other platforms shouldn't have an issue.
I read that some videos play while others don't, it's super weird, like the settings I'm using are recommended yet they don't work. I'm in dire need to find a solution. even if you have anything which would help me, please send it. I'd be very gratefull.
 
I read that some videos play while others don't, it's super weird, like the settings I'm using are recommended yet they don't work. I'm in dire need to find a solution. even if you have anything which would help me, please send it. I'd be very gratefull.
I think I might've found something, but according to your flags again this shouldn't be a problem. The videos that don't play on my iOS device are using the pixel format yuv420p10 as opposed to just yuv420p. That's as far as I can tell the only difference I can see from these videos, that's stumping me now :/
 
Well, it's kind of an awkward question because all these OSes can't play video natively, it's up to codecs and media players to take care of that. Those settings for that mp4 work fine for Infuse and VLC for example but maybe not iOS Gallery, same for VP9, x.265 etc. and it's all software rendered.

Not true. Both Android and iOS have native hardware video support for H.263, H.264, H.265, VP8, VP9, MP4 and even the new AV1.

Your odd setting might be some weird MKV off The Pirate Bay, but both Android and iOS support most modern codecs natively.
 
I think I might've found something, but according to your flags again this shouldn't be a problem. The videos that don't play on my iOS device are using the pixel format yuv420p10 as opposed to just yuv420p. That's as far as I can tell the only difference I can see from these videos, that's stumping me now :/



YUV20P10 is not a Pixel format. It's just colour space support and is device irrelevant.

Older devices will revert to YUV420 if it can display YUV420p10. It just tells the device, "Hey I can display 10 bit colour, you keen? if so say yes..."
 
Not true. Both Android and iOS have native hardware video support for H.263, H.264, H.265, VP8, VP9, MP4 and even the new AV1.

Your odd setting might be some weird MKV off The Pirate Bay, but both Android and iOS support most modern codecs natively.
Correct on both accounts, I was thinking OP meant in terms of development but that completely flew past my mind. I don't play movies on mobile devices, these were ffmpeg conversions from home and YouTube clips that play fine elsewhere but that's irrelevant. Yeah I also should've said colour depth, the media players lump them together as pixel format erroneously :P
 
Correct on both accounts, I was thinking OP meant in terms of development but that completely flew past my mind. I don't play movies on mobile devices, these were ffmpeg conversions from home and YouTube clips that play fine elsewhere but that's irrelevant. Yeah I also should've said colour depth, the media players lump them together as pixel format erroneously :p
So you two are saying that I should use "yuv420p10" as my color space and "H.264" as my video codec?
 
So you two are saying that I should use "yuv420p10" as my color space and "H.264" as my video codec?
Oh heavens no, we're still figuring that out. You can try though and it should play that codec + depth in theory but so should the other flags
 
So you two are saying that I should use "yuv420p10" as my color space and "H.264" as my video codec?

No. You can't choose the video codec, also the colour space is not the issue, as no matter what your device supports, it will always show an image, albieit washed out. Ignore Crumbl0x - no offense but he seems a bit out of his depths on this one.

Download Handbrake, drop in your media - make sure H.264 is selected as your format and export. It will work on any device.

If you really want to get the best of Handbrake and its video quality settings, you can watch this tutorial and tweak as need be;

 
No. You can't choose the video codec, also the colour space is not the issue, as no matter what your device supports, it will always show an image, albieit washed out. Ignore Crumbl0x - no offense but he seems a bit out of his depths on this one.

Download Handbrake, drop in your media - make sure H.264 is selected as your format and export. It will work on any device.

If you really want to get the best of Handbrake and its video quality settings, you can watch this tutorial and tweak as need be;

I beg your pardon? This was the exact advise I suggested first and began exploring which flags would yield the most consistent playback. What do you mean you can't choose the codec, that's a false statement.
 
I beg your pardon? This was the exact advise I suggested first and began exploring which flags would yield the most consistent playback. What do you mean you can't choose the codec, that's a false statement.

Apologies, maybe this is getting lost in translation and I misinterpreted what you were saying? Might seem so.
 
So you two are saying that I should use "yuv420p10" as my color space and "H.264" as my video codec?
Did you try x265 yet? This person here: https://brandur.org/fragments/ffmpeg-h265 seems to have found a good combo for consistent results, and assuming your devices are moderately recent, they shouldn't be a problem there too.
Oh and keep your `-c:a aac -ac 2 -b:a 128k` for now until we're sure everything goes smoothly.
Otherwise if the scope is for really old devices as well, we can bump to vp8 without a substantial hit to image quality. I'm still looking out for why some videos flat out refuse to play despite the same flags.
 
Last edited:
@Crumbl0x In my haste reading I see that this is code encoding and not typical GUI encoding - Ignore what I said and disregard my comments as complete and utter bullsh*t.

My humblest apologies.
 
@Crumbl0x In my haste reading I see that this is code encoding and not typical GUI encoding - Ignore what I said and disregard my comments as complete bullsh*t.

My humblest apologies.
I also apologise for misunderstanding the initial post too, you're still absolutely right about the hardware codecs and support^^
This finicky iOS issue got us both acting up a bit hehe
 
I also apologise for misunderstanding the initial post too, you're still absolutely right about the hardware codecs and support^^
This finicky iOS issue got us both acting up a bit hehe

No man, I was quick to jump on as a "codec expert", but you were right - I unfortunately have no clue with flags, and it seems you tackled what I suggested - an I'm definitely out of my depths with this one. I'll keep my eager mouth in check next time. :p
 
Did you try x265 yet? This person here: https://brandur.org/fragments/ffmpeg-h265 seems to have found a good combo for consistent results, and assuming your devices are moderately recent, they shouldn't be a problem there too.
Oh and keep your `-c:a aac -ac 2 -b:a 128k` for now until we're sure everything goes smoothly.
Otherwise if the scope is for really old devices as well, we can bump to vp8 without a substantial hit to image quality. I'm still looking out for why some videos flat out refuse to play despite the same flags.
I'll give this a try in a bit, will keep you guys updated. thanks for the help so far guys.
 
Top
Sign up to the MyBroadband newsletter
X