lib/rest-ftp-daemon/jobs/video.rb in rest-ftp-daemon-0.410.2 vs lib/rest-ftp-daemon/jobs/video.rb in rest-ftp-daemon-0.410.4

- old
+ new

@@ -6,24 +6,32 @@ require 'streamio-ffmpeg' module RestFtpDaemon class JobVideo < Job + protected + # Process job - def before + def do_before log_info "JobVideo.before source_loc.path: #{@source_loc.path}" log_info "JobVideo.before target_loc.path: #{@target_loc.path}" + # Ensure FFMPEG lib is available + ffmpeg_binary_path = FFMPEG.ffmpeg_binary + unless ffmpeg_binary_path && File.exists?(ffmpeg_binary_path) + raise RestFtpDaemon::MissingFfmpegLibraries, ffmpeg_binary_path + end + # Ensure source and target are FILE raise RestFtpDaemon::SourceNotSupported, @source_loc.scheme unless source_uri.is_a? URI::FILE raise RestFtpDaemon::TargetNotSupported, @target.scheme unless target_uri.is_a? URI::FILE end - def work + def do_work # Guess source files from disk set_status JOB_STATUS_TRANSFORMING - sources = scan_local_paths @source_loc.path + sources = @source_loc.scan_files raise RestFtpDaemon::SourceNotFound if sources.empty? # Add the source file name if none found in the target path target_final = @target_loc.clone target_final.name = @source_loc.name unless target_final.name @@ -33,42 +41,38 @@ log_info "JobVideo.work mkdir_p [#{@target_loc.dir}]" FileUtils.mkdir_p @target_loc.dir # Do the work, for each file set_info :source, :current, @source_loc.name - video_command @source_loc, target_final + ffmpeg_command @source_loc, target_final # Done set_info :source, :current, nil - - rescue FFMPEG::Error => exception - return oops :ended, exception, "ffmpeg_error" end - def after + def do_after # Done set_info :source, :current, nil end - protected - - def video_command source, target - log_info "JobVideo.video_command [#{source.name}]: [#{source.path}] > [#{target.path}]" + def ffmpeg_command source, target set_info :source, :current, source.name # Read info about source file movie = FFMPEG::Movie.new(source.path) # Build options - ffmpeg_custom_options = { - audio_codec: @video_ac, - video_codec: @video_vc, - custom: ffmpeg_custom_option_array, - } - set_info :work, :ffmpeg_custom_options, ffmpeg_custom_options + options = {} + options[:audio_codec] = @video_ac unless @video_ac.to_s.empty? + options[:video_codec] = @video_vc unless @video_vc.to_s.empty? + options[:custom] = @ffmpeg_custom_option_array if @ffmpeg_custom_option_array + set_info :work, :ffmpeg_options, options + # Announce contexte + log_info "JobVideo.ffmpeg_command [#{FFMPEG.ffmpeg_binary}] [#{source.name}] > [#{target.name}]", options + # Build command - movie.transcode(target.path, ffmpeg_custom_options) do |ffmpeg_progress| + movie.transcode(target.path, options) do |ffmpeg_progress| set_info :work, :ffmpeg_progress, ffmpeg_progress percent0 = (100.0 * ffmpeg_progress).round(0) set_info :work, :progress, percent0