Skip to content

Instantly share code, notes, and snippets.

@jimmac
Created January 26, 2009 10:19
Show Gist options
  • Save jimmac/52775 to your computer and use it in GitHub Desktop.
Save jimmac/52775 to your computer and use it in GitHub Desktop.
Transcode videos to PS3
#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
def ffmpegit(infile,outfile,twopass,title)
title = title.nil? ? infile.gsub(/\.[^.]+$/,'').capitalize : title
if twopass
cmd = "ffmpeg -i #{infile} -y -an -pass 1 -vcodec libx264 -b 1024k -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 1 -trellis 0 -refs 1 -bf 16 -b_strategy 1 -threads 2 -level 31 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -rc_eq blurCplx^\\(1-qComp\\) -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 #{outfile}"
#-flags2 +brdo+dct8x8+wpred+mixed_refs
cmd += " && ffmpeg -i #{infile} -y -acodec libfaac -title #{title} -ac 2 -ab 128k -pass 2 -vcodec libx264 -b 1024k -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 -subq 7 -trellis 1 -refs 6 -bf 16 -b_strategy 1 -threads 2 -level 31 -directpred 3 -bidir_refine 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -rc_eq blurCplx^\\(1-qComp\\) -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 #{outfile}"
else
cmd = "ffmpeg -i #{infile} -acodec libfaac -title #{title} -ac 2 -ab 128k -y -vcodec libx264 -b 1536k -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 1 -trellis 0 -refs 1 -bf 16 -b_strategy 1 -threads 2 -level 31 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 #{outfile}"
end
system cmd
#puts cmd
end
options = OpenStruct.new
options.title = nil
options.twopass = false
OptionParser.new do |opts|
opts.banner = "Usage: video2ps3 [options]"
opts.on("-2", "--twopass", "Run in two passes. Slow but better quality.") do
options.twopass = true
end
opts.on("-t", "--title [TITLE]", String, "Set movie title metadata.") do |t|
options.title = t
end
end.parse!
if ARGV.length < 1
puts "Error parsing commandline. run video2ps3 -h to see syntax."
exit 0
end
#working on a single file or a dir?
if File.directory?(indir = ARGV[0])
puts "Will convert all videos in #{indir} to #{indir}/out-mp4/"
Dir.foreach(indir) do |file|
if /(\.avi$)|(\.mpeg$)|(\.mpg$)|(\.vob$)/i.match(file)
infile = "#{indir}/#{file}"
if File.directory?("#{indir}/out-mp4")
puts "target directory exists. Exiting to prevent file overwrites."
exit 0
else
Dir.mkdir "#{indir}/out-mp4"
end
outfile = "#{indir}/out-mp4/" + file.gsub(/(^[^.]+)((\.[^.]+)$|$)/,'\1.mp4')
ffmpegit(infile,outfile,options.twopass,options.title)
end
end
puts "done"
else
#operating on a single file
ARGV.each do |infile|
outfile = infile.gsub(/(^[^.]+)((\.[^.]+)$|$)/,'\1.mp4')
ffmpegit(infile,outfile,options.twopass,options.title)
end
end
#p options
#p ARGV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment