Last active
August 29, 2015 14:01
-
-
Save marpada/12e7d4a093aec402a989 to your computer and use it in GitHub Desktop.
Use qt-faststart to move the moov atom on all mp4 files in a given folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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