Class: TranscodeVideoJob
- Inherits:
-
Object
- Object
- TranscodeVideoJob
- Extended by:
- Open3
- Defined in:
- lib/sufia/jobs/transcode_video_job.rb
Instance Attribute Summary collapse
-
#datastream_in ⇒ Object
Returns the value of attribute datastream_in.
-
#generic_file_id ⇒ Object
Returns the value of attribute generic_file_id.
Class Method Summary collapse
-
.encode(path, options, output_file) ⇒ Object
TODO tmp file for output.
- .ffmpeg_path ⇒ Object
Instance Method Summary collapse
- #audio_attributes ⇒ Object
- #encode_datastream(dest_dsid, mime_type, options) ⇒ Object
- #encode_mp4 ⇒ Object
- #encode_webm ⇒ Object
-
#initialize(generic_file_id, datastream_in) ⇒ TranscodeVideoJob
constructor
A new instance of TranscodeVideoJob.
- #queue_name ⇒ Object
- #run ⇒ Object
- #size_attributes ⇒ Object
Constructor Details
#initialize(generic_file_id, datastream_in) ⇒ TranscodeVideoJob
Returns a new instance of TranscodeVideoJob.
15 16 17 18 |
# File 'lib/sufia/jobs/transcode_video_job.rb', line 15 def initialize(generic_file_id, datastream_in) self.generic_file_id = generic_file_id self.datastream_in = datastream_in end |
Instance Attribute Details
#datastream_in ⇒ Object
Returns the value of attribute datastream_in.
13 14 15 |
# File 'lib/sufia/jobs/transcode_video_job.rb', line 13 def datastream_in @datastream_in end |
#generic_file_id ⇒ Object
Returns the value of attribute generic_file_id.
13 14 15 |
# File 'lib/sufia/jobs/transcode_video_job.rb', line 13 def generic_file_id @generic_file_id end |
Class Method Details
.encode(path, options, output_file) ⇒ Object
TODO tmp file for output
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sufia/jobs/transcode_video_job.rb', line 64 def self.encode(path, , output_file) command = "#{ffmpeg_path} -y -i #{path} #{} #{output_file}" stdin, stdout, stderr, wait_thr = popen3(command) stdin.close out = stdout.read stdout.close err = stderr.read stderr.close raise "Unable to execute command \"#{command}\"\n#{err}" unless wait_thr.value.success? end |
Instance Method Details
#audio_attributes ⇒ Object
47 48 49 |
# File 'lib/sufia/jobs/transcode_video_job.rb', line 47 def audio_attributes "-ac 2 -ab 96k -ar 44100" end |
#encode_datastream(dest_dsid, mime_type, options) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sufia/jobs/transcode_video_job.rb', line 51 def encode_datastream(dest_dsid, mime_type, ) file_suffix = dest_dsid out_file = nil output_file = Dir::Tmpname.create('sufia'){} + ".#{file_suffix}" @datastream.to_tempfile do |f| self.class.encode(f.path, , output_file) end out_file = File.open(output_file, "rb") @generic_file.add_file_datastream(out_file.read, :dsid=>dest_dsid, :mimeType=>mime_type) File.unlink(output_file) end |
#encode_mp4 ⇒ Object
37 38 39 40 |
# File 'lib/sufia/jobs/transcode_video_job.rb', line 37 def encode_mp4 opts = "#{size_attributes} -b:v 345k -vcodec libx264 -acodec libfaac #{audio_attributes} " encode_datastream('mp4', 'video/mp4', opts) end |
#encode_webm ⇒ Object
32 33 34 35 |
# File 'lib/sufia/jobs/transcode_video_job.rb', line 32 def encode_webm opts = "#{size_attributes} -b:v 345k -acodec libvorbis #{audio_attributes}" encode_datastream('webm', 'video/webm', opts) end |
#queue_name ⇒ Object
9 10 11 |
# File 'lib/sufia/jobs/transcode_video_job.rb', line 9 def queue_name :video end |
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sufia/jobs/transcode_video_job.rb', line 20 def run @generic_file = GenericFile.find(generic_file_id) @datastream = @generic_file.datastreams[datastream_in] if @datastream encode_mp4() encode_webm() @generic_file.save! else logger.warn "No datastream for transcoding!!!!! pid: #{generic_file_id} dsid: #{datastream_in}" end end |
#size_attributes ⇒ Object
43 44 45 |
# File 'lib/sufia/jobs/transcode_video_job.rb', line 43 def size_attributes "-s 320x240" end |