Created
July 24, 2010 01:34
-
-
Save portertech/488292 to your computer and use it in GitHub Desktop.
This file contains 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
require 'net/ftp' | |
load 'aws.rb' | |
def execute_ffmpeg(command) | |
progress = nil | |
IO.popen(command) do |pipe| | |
pipe.each("r") do |line| | |
if line =~ /Duration: (d{2}):(d{2}):(d{2}).(d{1})/ | |
duration = (($1.to_i * 60 + $2.to_i) * 60 + $3.to_i) * 10 + $4.to_i | |
end | |
if line =~ /time=(d+).(d+)/ | |
if not duration.nil? and duration != 0 | |
p = ($1.to_i * 10 + $2.to_i) * 100 / duration | |
else | |
p = 0 | |
end | |
p = 100 if p > 100 | |
if progress != p | |
progress = p | |
print "PROGRESS: #{progress}n" | |
$defout.flush | |
end | |
end | |
end | |
end | |
raise MediaFormatException if $?.exitstatus != 0 | |
end | |
until QUEUE.size == 0 | |
input_file = QUEUE.pop | |
output_file = input_file.gsub(/flv/, "mp4") | |
# get the original from the chrome FTP | |
ftp = Net::FTP.new('') | |
ftp.login(user = '', passwd = '') | |
files = ftp.chdir('') | |
ftp.getbinaryfile(file, '/tmp/' + input_file, 1024) | |
ftp.close | |
# convert the video | |
command = "ffmpeg -i /tmp/#{input_file} -acodec libfaac -ab 96k -ac 2 -vcodec libx264 -vpre slow -vpre ipod640 -crf 26 -threads 0 /tmp/#{output_file} 2>&1" | |
execute_ffmpeg(command) | |
# upload the converted video to S3 | |
relative_video_path = '/video/' + output_file | |
begin | |
# check to see if the video already exists on S3 | |
AWS::S3::S3Object.find relative_video_path, 'myauto.evox' | |
rescue AWS::S3::NoSuchKey | |
# if the video doesn't exist on S3, upload it | |
AWS::S3::S3Object.store(relative_video_path, open('/tmp/' + output_file), 'myauto.evox') | |
puts "Uploaded '#{relative_video_path}' to S3." | |
end | |
File.delete('/tmp/' + input_file) | |
puts "#{input_file} => #{output_file} => S3 :: Done!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment