Added actual video transcoding functionality

This commit is contained in:
Gregory Ballantine 2022-08-31 13:35:07 -04:00
parent bc799ff2cb
commit 92fcfd30f2

View File

@ -1,3 +1,5 @@
require 'pathname'
# Handles the actual transcoding. # Handles the actual transcoding.
class Transcoder class Transcoder
@ -13,12 +15,40 @@ class Transcoder
ingest_files = @repository.search_ingest() ingest_files = @repository.search_ingest()
ingest_files.each { |ifile| ingest_files.each { |ifile|
# archive the file # archive the file
@repository.archive_file(ifile) #@repository.archive_file(ifile)
# perform the transcode # perform the transcode
# // TODO self.transcode(ifile) self.transcode(ifile)
# clean up the file from ingest # clean up the file from ingest
@repository.cleanup_file(ifile) #@repository.cleanup_file(ifile)
} }
end 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 end