Skip to content

Instantly share code, notes, and snippets.

@marpada

marpada/faststart_dir.rb

Last active Aug 29, 2015
Embed
What would you like to do?
Use qt-faststart to move the moov atom on all mp4 files in a given folder
#!/usr/bin/env ruby
require 'fileutils'
QT_FASTSTART='/usr/local/bin/qt-faststart'
if ARGV.count != 1
puts "Usage: #{__FILE__} folder"
exit 1
end
base_dir = File.realdirpath ARGV[0]
unless Dir.exists? base_dir
puts "#{ARGV[0]} is not a directory. Existing"
exit 1
end
Dir[base_dir + File::Separator + '**' + File::Separator + '*.mp4'].each do |f|
cmd = "#{QT_FASTSTART} \"#{f}\" \"#{f}.tmp\""
puts cmd
begin
puts `#{cmd}`
FileUtils.mv("#{f}.tmp", f) if $?.exitstatus == 0 && (File.exists? "#{f}.tmp")
rescue StandardError => e
puts "Something went wrong processing #{f} : #{e}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment