Categories: Linux

Bash script to batch-convert MKV to MP4 (Linux)

I have been looking a simple way to convert my *.mkv TV series collections to *.mp4 so I can watch it on my TV. Luckily, I stumbled upon a post in stackoverflow about it. So I took the code and modified it a bit so it can automatically find all *.mkv files in a directory (recursively), convert them to *.mp4 and place it the same directory. The only dependency you need is avconv which can be installed easily on Debian/Ubuntu by sudo apt-get install libav-tools and you are ready to run the script:

#!/bin/sh
findpath=$1
: ${findpath:="."}
find "$findpath" -name '*.mkv' | while read f ; do
    dir=$(dirname "$f");
    file=$(basename "$f");
    # ext="${filename##*.}";
    name="${file%.*}";
    # echo "avconv -i \"$f\" -codec copy \"$dir/$name.mp4\"";
    avconv -i "$f" -codec copy "$dir/$name.mp4" </dev/null;
    # rm -f "$f";
done
0 0 votes
Article Rating
yohanes.gultom@gmail.com

Share
Published by
yohanes.gultom@gmail.com
Tags: linuxscript

Recent Posts

Get Unverified SSL Certificate Expiry Date with Python

Getting verified SSL information with Python (3.x) is very easy. Code examples for it are…

3 years ago

Spring Data Couchbase 4 Multibuckets in Spring Boot 2

By default, Spring Data Couchbase implements single-bucket configuration. In this default implementation, all POJO (Plain…

4 years ago

Firebase Auth Emulator with Python

Last year, Google released Firebase Auth Emulator as a new component in Firebase Emulator. In…

4 years ago

Google OIDC token generation/validation

One of the authentication protocol that is supported by most of Google Cloud services is…

4 years ago

Fast geolocation query with PostGIS

If you need to to add a spatial information querying in your application, PostGIS is…

4 years ago

Auto speech-to-text (Indonesian) with AWS Transcribe and Python

Amazon Web Service Transcribe provides API to automatically convert an audio speech file (mp3/wav) into…

5 years ago