Skip to content

Instantly share code, notes, and snippets.

@czj
Created October 5, 2011 07:39
Show Gist options
  • Save czj/1263872 to your computer and use it in GitHub Desktop.
Save czj/1263872 to your computer and use it in GitHub Desktop.
Script to encode with HandbrakeCLI (x264) 720p, high image quality, low file size
#!/usr/bin/env ruby
# encoding: utf-8
# x264 presets guide : https://forum.handbrake.fr/viewtopic.php?f=6&t=19426
X264 = "b-adapt=2:rc-lookahead=50:me=umh:bframes=5:ref=6:direct=auto:trellis=2:subq=10:psy-rd=1.0,0.10:analyse=all"
FORMAT = "--optimize --format mp4"
QUALITY = "--ab 64 --mixdown mono --quality 23 -e x264 -x '#{X264}'"
SIZE = "--width 1280 --height 720"
ARGV.each do |param|
Dir.glob(param) do |entry|
next unless File.file?(entry)
# Open the source file
# Needed to get its mtime
source_file = File.new(entry)
# Use a sanitized filename with -720p extension
destination = source_file.path.gsub(/(.*)[.][a-zA-Z0-9]+$/, "\\1-720p.mp4")
# Compress video file
# -v0 flag disabled most of the verbosity
system "/Applications/HandBrakeCLI -v0 -i '#{source_file.path}' -o '#{destination}' #{FORMAT} #{QUALITY} #{SIZE}}"
# Set original file's modification time + current time for access time
File.utime(Time.now, source_file.mtime, destination)
end
end
@rowdyrotifer
Copy link

Good stuff!

@kalabiyau
Copy link

-mixdown mono wut?

@nilankadesilva
Copy link

How do I use this script?

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