From 92fcfd30f25ef91b9b84c9249678787992720a09 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Wed, 31 Aug 2022 13:35:07 -0400 Subject: [PATCH] Added actual video transcoding functionality --- src/transcoder.rb | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/transcoder.rb b/src/transcoder.rb index a12375a..cd08d2c 100644 --- a/src/transcoder.rb +++ b/src/transcoder.rb @@ -1,3 +1,5 @@ +require 'pathname' + # Handles the actual transcoding. class Transcoder @@ -13,12 +15,40 @@ class Transcoder ingest_files = @repository.search_ingest() ingest_files.each { |ifile| # archive the file - @repository.archive_file(ifile) + #@repository.archive_file(ifile) # perform the transcode - # // TODO self.transcode(ifile) + self.transcode(ifile) # clean up the file from ingest - @repository.cleanup_file(ifile) + #@repository.cleanup_file(ifile) } end + def transcode(ingest_file) + # create the ingest and output file paths + ingest_path = File.join(@config.get('transcoder.repository'), 'ingest', ingest_file) + out_name = File.basename(ingest_file, File.extname(ingest_file)) + '.' + @config.get('transcoder.video_format') + output_path = File.join(@config.get('transcoder.repository'), 'output', out_name) + + # put together the ffmpeg command + ffmpeg_cmd = '/usr/bin/ffmpeg' + + " -i #{ingest_path}" + + ' -y' + + " -f #{@config.get('transcoder.video_format')}" + + " -c:v #{@config.get('transcoder.video_codec')}" + + " -s #{@config.get('transcoder.video_resolution')}" + + " -r #{@config.get('transcoder.video_framerate')}" + + " -vf 'format=#{@config.get('transcoder.video_color')}'" + + " -profile:v #{@config.get('transcoder.video_profile')}" + + " -c:a #{@config.get('transcoder.audio_codec')}" + + " #{output_path}" + + # execute the FFMPEG command + puts "Transcoding #{ingest_path} to #{output_path}." + result = `#{ffmpeg_cmd} 2>&1 >/dev/null` + + if result.end_with?("Conversion failed!\n") + abort "Transcoding failed with error:\n#{result}" + end + end + end