Skip to content

Instantly share code, notes, and snippets.

@mattzab
Last active October 21, 2021 22:45
Show Gist options
  • Save mattzab/7f222ec4a6c49e7c89336980129aeec9 to your computer and use it in GitHub Desktop.
Save mattzab/7f222ec4a6c49e7c89336980129aeec9 to your computer and use it in GitHub Desktop.

Easily Convert MKV to MP4 with Terminal

I always have trouble converting mkv to mp4, even with ffmpeg.

The Code that never works for me:

ffmpeg -c copy -i file.mkv file.mp4 Try it. Maybe it'll work for you. But if not...

The One-Liner that works:

HandBrakeCLI -Z "Vimeo YouTube 720p30" -s scan -F --subtitle-burned -N eng -i file.mkv -o file.mp4

Batch Convert all the mkv files in this folder and upload with rclone

for f in *; do cp "$f" ~/work -P; HandBrakeCLI -Z "Vimeo YouTube 720p30" -s scan -F --subtitle-burned -N eng -i "$f" -o ~/work/"${f%.*}.mp4"; rm ~/work/*; rclone move ~/work plex:720 -P; done

Explained Line-By-Line for f in *.mkv; do Apply the following to all MKV files in the current directory, using a for loop rclone copy "$f" ~/work -P; using rclone instead of cp because I can easily see the progress with -P HandBrakeCLI -Z "Vimeo YouTube 720p30" -s scan -F --subtitle-burned -N eng -i "$f" -o ~/work/"${f%.mkv}.mp4"; Actual Conversion... Stripping out the .mkv filename so that it doesn't end up being movie.mkv.mp4 rm ~/work/*.mkv; because I don't want to upload the old junkins MKV file rclone move ~/work plex:Transcoded -P; Get it to the cloud where I want it done close the for loop

In particular, the directory I ran this in is my rclone mount, which is why I moved the files to ~/work before conversion.

@StrangeRanger
Copy link

You're supposed to use ffmpeg -i file.mkv file.mp4, not ffmpeg -c copy -i file.mkv file.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment