Class: FfmpegTranscodeJob
- Inherits:
-
Object
- Object
- FfmpegTranscodeJob
- Extended by:
- Open3
- Defined in:
- lib/sufia/jobs/ffmpeg_transcode_job.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#datastream ⇒ Object
Returns the value of attribute datastream.
-
#datastream_in ⇒ Object
Returns the value of attribute datastream_in.
-
#generic_file ⇒ Object
Returns the value of attribute generic_file.
-
#generic_file_id ⇒ Object
Returns the value of attribute generic_file_id.
Class Method Summary collapse
Instance Method Summary collapse
- #encode_datastream(dest_dsid, mime_type, options) ⇒ Object
-
#initialize(generic_file_id, datastream_in) ⇒ FfmpegTranscodeJob
constructor
A new instance of FfmpegTranscodeJob.
- #process ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(generic_file_id, datastream_in) ⇒ FfmpegTranscodeJob
Returns a new instance of FfmpegTranscodeJob.
12 13 14 15 |
# File 'lib/sufia/jobs/ffmpeg_transcode_job.rb', line 12 def initialize(generic_file_id, datastream_in) self.generic_file_id = generic_file_id self.datastream_in = datastream_in end |
Instance Attribute Details
#datastream ⇒ Object
Returns the value of attribute datastream.
10 11 12 |
# File 'lib/sufia/jobs/ffmpeg_transcode_job.rb', line 10 def datastream @datastream end |
#datastream_in ⇒ Object
Returns the value of attribute datastream_in.
10 11 12 |
# File 'lib/sufia/jobs/ffmpeg_transcode_job.rb', line 10 def datastream_in @datastream_in end |
#generic_file ⇒ Object
Returns the value of attribute generic_file.
10 11 12 |
# File 'lib/sufia/jobs/ffmpeg_transcode_job.rb', line 10 def generic_file @generic_file end |
#generic_file_id ⇒ Object
Returns the value of attribute generic_file_id.
10 11 12 |
# File 'lib/sufia/jobs/ffmpeg_transcode_job.rb', line 10 def generic_file_id @generic_file_id end |
Class Method Details
.encode(path, options, output_file) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sufia/jobs/ffmpeg_transcode_job.rb', line 45 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
#encode_datastream(dest_dsid, mime_type, options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sufia/jobs/ffmpeg_transcode_job.rb', line 33 def encode_datastream(dest_dsid, mime_type, ) file_suffix = dest_dsid out_file = nil output_file = Dir::Tmpname.create(['sufia', ".#{file_suffix}"], Sufia::Engine.config.temp_file_base){} 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 |
#process ⇒ Object
17 18 19 |
# File 'lib/sufia/jobs/ffmpeg_transcode_job.rb', line 17 def process raise "You attempted to call process() on an abstract class. Implement process() on the concrete class" end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sufia/jobs/ffmpeg_transcode_job.rb', line 21 def run return unless Sufia::Engine.config.enable_ffmpeg self.generic_file = GenericFile.find(generic_file_id) self.datastream = generic_file.datastreams[datastream_in] if datastream process generic_file.save! else logger.warn "No datastream for transcoding!!!!! pid: #{generic_file_id} dsid: #{datastream_in}" end end |