Create a gist now

Instantly share code, notes, and snippets.

@dakull /mkvit.rb
Last active May 19, 2016

What would you like to do?
Convert videos to H.264 mkv easily (using ffmpeg)
# _ _ _
# | | (_)| |
# _ __ ___ | | ____ __ ______ _ | |_
# | '_ ` _ \ | |/ /\ \ / /|______|| || __|
# | | | | | || < \ V / | || |_
# |_| |_| |_||_|\_\ \_/ |_| \__|
#
# Simple script to convert your old video files to H.264 mantaining their quality
#
# Usage:
# ruby mkvit.rb [extension]
# this will convert all the videos with the provided ext. in the current dir
#
# Notes:
# uses: https://trac.ffmpeg.org/wiki/Encode/H.264
#
ext = ARGV[0]
files_to_convert = Dir["*.#{ext}"]
files_to_convert.each do |file_name|
puts "Started encoding to h264 #{file_name}"
output = `ffmpeg -i "#{file_name}" -c:v libx264 -preset slow -crf 22 -c:a copy "#{file_name.gsub(/\.(.*)/, '.mkv')}"`
puts output
puts "File encoded"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment