Using FFmpeg is more art than science. Every time I reach for it, I find myself trawling the internet for various incantations of the command that result in a playable video. These are commands that have worked for me.
Blu-ray
ffmpeg -i input.mkv -c:v libx265 -crf 18 -c:a aac -b:a 160k -tag:v hvc1 -ac 6 output.mp4
This results in an mp4 container with h265 video and aac sound. The file should be playable on Apple devices. The resulting file will also be significantly smaller than the original.
Without the -ac 6
parameter the resulting video would play in VLC but would play without sound in Apple previews.
UHD
ffmpeg -i input.mkv -c:v copy -c:a copy -tag:v hvc1 -map 0:a:1 -map 0:v:0 -ac 6 output.mp4
This results in an mp4 container with h265 video (no transcoding). Audio is copied from the second stream in the original file. Because video and audio are copied rather than transcoded, the original will need to contain formats compatible with Apple devices (h265 and aac).
The trick here was to copy the second stream, as the first audio stream was TrueHD and isnt’ playable by default on Apple devices.
Just the first few minutes
ffmpeg -i input.mkv -ss 0 -t 120 -c:v libx265 -crf 18 -c:a aac -b:a 160k -tag:v hvc1 -ac 6 output.mp4
Process just the first couple of minutes of a video by using the following options, -ss 0 -t 120
. This is useful when confirming the desired formats will work.
Viewing available stream formats
ffprobe input.mkv
Use ffprobe
to view a list of the audio and video streams available within a container.