Skip to content

Instantly share code, notes, and snippets.

@tvararu
Last active August 29, 2015 13:57
Show Gist options
  • Save tvararu/9597402 to your computer and use it in GitHub Desktop.
Save tvararu/9597402 to your computer and use it in GitHub Desktop.
Compresses everything in a folder with ffmpeg using some arbitrary parameters. Outputs to a different folder. 85% savings in my experience, with no major loss in quality.
# How to run:
#
# $ cd ~/folder/that/contains/videos/in/original
# $ cd ..
# $ ls original/
# video1.mp4 video2.mp4
#
# $ ruby ffmpeg_compress.rb
# $ ls compressed/
# video1.mp4 video2.mp4
#
ORIGINAL_FOLDER = 'original'
COMPRESSED_FOLDER = 'compressed'
files = Dir["#{ORIGINAL_FOLDER}/*"]
files.each do |path|
newPath = path.sub(ORIGINAL_FOLDER, COMPRESSED_FOLDER)
cmd = "export INPUT=\"#{path}\" OUTPUT=\"#{newPath}\" && ffmpeg -y -i $INPUT -r 30000/1001 -b:v 400k -bt 500k -vcodec libx264 -acodec libfaac -ac 2 -ar 44100 -ab 128k $OUTPUT"
system(cmd)
end
@paulbalogh
Copy link

very useful! :)

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