After a few experiments, I’ve found that it’s necessary to be specific about which profile you’re using when encoding 4K video for delivery over the web. It specifically requires High Profile, Level 4.2. Any lower than that and 4K video won’t play in Safari. It might play if stored on the device, but other apps like iMovie and Photos seem to baulk at it too.
Doing this is fairly simple. As an extremely simplistic example:
ffmpeg -i inputfile.mp4 -c:v libx264 output.mp4
ffmpeg -i inputfile.mp4 -c:v libx264 -profile high -level 4.2 output.mp4
Output from the first command doesn’t play, output from the second command does.
Most MKVs contain a h.264 video track, some kind of audio track (usually AAC or AC3) and possibly some subtitles. iOS devices can usually support these but they can’t support the MKV container. A container is simply an envelope in which video, audio and other tracks are stored.
iOS can, however, support the MP4 container. So, it should be a simple matter to take them out of one envelope and put them into another. You can use ffmpeg to do this. This isn’t a guide to how to install ffmpeg, I assume you already have it installed and can access it from the command line.
A simple command to do this:
ffmpeg -i yourinputfile.mkv -c:v copy -movflags +faststart -strict experimental -c:a aac -ac 2 -ab 256K youroutputfile.mp4
To break down what this does:
- -i inputfile.mkv tells ffmpeg to use your MKV file as an input source.
- -c:v copy tells ffmpeg to copy the first video track it finds to the output file without modifying it.
- -movflags +faststart is not strictly necessary but moves some data to the start of the file which makes it start faster when streamed over a network.
- -strict experimental tells ffmpeg to use experimental codecs that would normally be disabled. This is necessary because ffmpeg’s AAC encoder is not classified as ‘done’ yet.
- -c:a aac -ac 2 -ab 256K specifies the parameters for encoding the audio. In this case, we’re using the AAC audio encoder to create a two channel (i.e. stereo) track with an average 256Kbps bitrate. If your input file has an AC3 track (otherwise known as Dolby Digital 5.1) this will downmix that track to stereo. iOS only supports stereo audio playback.
- youroutputfile.mp4 – the name of your output file.
This will take around a minute, depending on the speed of your computer. Unlike using Handbrake or one of the many other tools available on the Internet for this, there is no need to alter the video which drastically cuts down the time it takes to prepare the final file.