Skip to content

Instantly share code, notes, and snippets.

@marianposaceanu
Last active May 19, 2016 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marianposaceanu/bbdd7794bbeec036fae67c9b120d2786 to your computer and use it in GitHub Desktop.
Save marianposaceanu/bbdd7794bbeec036fae67c9b120d2786 to your computer and use it in GitHub Desktop.
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