Last active
August 29, 2015 13:57
-
-
Save colewinans/9486307 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
class VideoWorker | |
include Sidekiq::Worker | |
def perform(id, s3_key) | |
# Get the video | |
video = Video.find(id) | |
# Call ffmpeg to measure duration | |
duration = `ffmpeg -i '#{video.ffmpeg_url}' 2>&1 | grep Duration | awk '{print $2}' | tr -d ,` | |
# Parse duration timestamp into seconds | |
t = Time.parse(duration) | |
sec = t.hour*3600 + t.min*60 + t.sec | |
# If video duration <= 30s, encode it | |
if sec <= 60 | |
zencoder_response = Zencoder::Job.create({ | |
:input => video.s3_key, | |
:test => true, | |
:notifications => "[]", | |
:pass_through => video.id, | |
:outputs => [ | |
{ | |
:credentials => "[]", | |
:public => true, | |
:base_url => video.base_url, | |
:label => 'webmp4', | |
:format => 'mp4', | |
:audio_codec => 'aac', | |
:video_codec => 'h264', | |
:size => '440x440', | |
:upscale => true, | |
:aspect_mode => "crop" | |
}, | |
{ | |
:credentials => "[]", | |
:public => true, | |
:base_url => video.base_url, | |
:label => 'webwebm', | |
:format => 'webm', | |
:audio_codec => 'vorbis', | |
:video_codec => 'vp8', | |
:size => '440x440', | |
:upscale => true, | |
:aspect_mode => "crop" | |
}, | |
{ | |
:thumbnails => { | |
:credentials => "[]", | |
:public => true, | |
:base_url => video.base_url, | |
:times => [1], | |
:size => '440x440', | |
:aspect_mode => "crop" | |
} | |
} | |
] | |
}) | |
else | |
# If video duration is > 30s, destroy it | |
video.destroy | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment