
Some videos come with audio and video in one file and subtitles in another. To merge everything together into a single MKV file:
ffmpeg -i VIDEO.mp4 -i SUBTITLES.srt -c:v copy -c:a copy -c:s srt -metadata:s:s language=eng OUTPUT.mkv
Some MKV video files are huge, with high video bitrates, high frames-per-second rates, and many subtitle streams. To shrink the file and remove the extra subtitle streams:
ffmpeg -i VIDEO.mkv -c:v libx265 -cq 35 -r 29.97 -c:a copy -c:s copy -map 0:0 -map 0:1 -map 0:3 -map_metadata:s -1 -metadata:s:s language=eng OUTPUT.mkv
If the machine doing the encoding has an NVIDIA GPU with the CUDA drivers installed then replace “libx265” with “hevc_nvenc” as the video codec in the command above. This will significantly speed up the process.
To merge a video and two subtitle files while dropping all the metadata from the input files, giving each subtitle stream a different title, and having the first subtitle stream play by default:
ffmpeg -i VIDEO.mkv -i SUBTITLE_1.srt -i SUBTITLE_2.srt -map 0:0 -map 0:1 -map 1:0 -map 2:0 -c:v libx265 -cq 35 -c:a copy -c:s copy -map_metadata -1 -metadata:s:s:0 language=eng -metadata:s:s:0 title=English -metadata:s:s:1 language=eng -metadata:s:s:1 title="English (SDH)" -disposition:s:0 default OUTPUT.mkv
If the machine doing the encoding has an NVIDIA GPU with the CUDA drivers installed then replace “libx265” with “hevc_nvenc” as the video codec in the command above. This will significantly speed up the process.