class Transcode < XMorph::Base PRO_1080_16_TRACKS = "1080_16" PRO_1080_14_TRACKS = "1080_14" PRO_1080_8_TRACKS = "1080_8" PRO_1080_2_TRACKS = "1080_2" PRO_1080_STEREO = "1080_stereo" PRO_720_STEREO = "720_stereo" def set_profiles self.profiles = { PRO_1080_16_TRACKS => "ffmpeg -y -i %{IN} -vf \"fps=25.000000,scale=1920x1080\" -filter_complex \"[0:a:8][0:a:9]amerge=inputs=2[aout0]\" -pix_fmt yuv420p -vcodec h264 -g 13 -bf 2 -x264opts nal-hrd=cbr -profile:v high -flags +ilme+ildct -top 1 -vb 10000000 -minrate:v 10000000 -maxrate:v 10000000 -bufsize:v 20000000 -acodec libfdk_aac -profile:a aac_low -ab 192k -map 0:v -map \"[aout0]\" -muxrate 11211200 -streamid 0:2064 -streamid 1:2068 %{OUT} 2>&1", PRO_1080_14_TRACKS => "ffmpeg -y -i %{IN} -vf \"fps=25.000000,scale=1920x1080\" -filter_complex \"[0:a:6][0:a:7]amerge=inputs=2[aout0]\" -pix_fmt yuv420p -vcodec h264 -g 13 -bf 2 -x264opts nal-hrd=cbr -profile:v high -flags +ilme+ildct -top 1 -vb 10000000 -minrate:v 10000000 -maxrate:v 10000000 -bufsize:v 20000000 -acodec libfdk_aac -profile:a aac_low -ab 192k -map 0:v -map \"[aout0]\" -muxrate 11211200 -streamid 0:2064 -streamid 1:2068 %{OUT} 2>&1", PRO_1080_8_TRACKS => "ffmpeg -y -i %{IN} -vf \"fps=25.000000,scale=1920x1080\" -filter_complex \"[0:a:6][0:a:7]amerge=inputs=2[aout0]\" -pix_fmt yuv420p -vcodec h264 -g 13 -bf 2 -x264opts nal-hrd=cbr -profile:v high -flags +ilme+ildct -top 1 -vb 10000000 -minrate:v 10000000 -maxrate:v 10000000 -bufsize:v 20000000 -acodec libfdk_aac -profile:a aac_low -ab 192k -map 0:v -map \"[aout0]\" -muxrate 11211200 -streamid 0:2064 -streamid 1:2068 %{OUT} 2>&1", PRO_1080_2_TRACKS => "ffmpeg -y -i %{IN} -vf \"fps=25.000000,scale=1920x1080\" -filter_complex \"[0:a:1][0:a:2]amerge=inputs=2[aout0]\" -pix_fmt yuv420p -vcodec h264 -g 13 -bf 2 -x264opts nal-hrd=cbr -profile:v high -flags +ilme+ildct -top 1 -vb 10000000 -minrate:v 10000000 -maxrate:v 10000000 -bufsize:v 20000000 -acodec libfdk_aac -profile:a aac_low -ab 192k -map 0:v -map \"[aout0]\" -muxrate 11211200 -streamid 0:2064 -streamid 1:2068 %{OUT} 2>&1", PRO_1080_STEREO => "ffmpeg -y -i %{IN} -vf \"fps=25.000000,scale=1920x1080\" -pix_fmt yuv420p -vcodec h264 -g 13 -bf 2 -x264opts nal-hrd=cbr -profile:v high -flags +ilme+ildct -top 1 -vb 10000000 -minrate:v 10000000 -maxrate:v 10000000 -bufsize:v 20000000 -acodec libfdk_aac -profile:a aac_low -ab 192k -map 0:v -map 0:a:0 -muxrate 11211200 -streamid 0:2064 -streamid 1:2068 -vsync 1 -async 1 %{OUT} 2>&1", PRO_720_STEREO => "ffmpeg -y -i %{IN} -vf \"fps=25.000000,scale=1920x1080\" -pix_fmt yuv420p -vcodec h264 -g 13 -bf 2 -x264opts nal-hrd=cbr -profile:v high -flags +ilme+ildct -top 1 -vb 10000000 -minrate:v 10000000 -maxrate:v 10000000 -bufsize:v 20000000 -acodec libfdk_aac -profile:a aac_low -ab 192k -map 0:v -map 0:a:0 -muxrate 11211200 -streamid 0:2064 -streamid 1:2068 -vsync 1 -async 1 %{OUT} 2>&1", } end def video_checks { ALLOWED_ASPECT_RATIO => ["4:3", "16:9"], ALLOWED_HEIGHT => [720, 1080], ALLOWED_WIDTH => [1280, 1920], ALLOWED_FRAME_RATE => IGNORE, ALLOWED_VIDEO_BIT_RATE => IGNORE, #Mbps ALLOWED_SCAN_TYPE => IGNORE, #all downcased } end def audio_checks { PRESENCE_OF_AUDIO_TRACK => VALIDATE, ALLOWED_NUMBER_OF_AUDIO_TRACKS => [1, 4, 8, 14, 16], ALLOWED_AUDIO_CODECS => ["aac", "pcm"], ALLOWED_AUDIO_BIT_RATE => IGNORE, ALLOWED_NUMBER_OF_AUDIO_CHANNELS => [1, 2], } end #profiles are classified based on height and number of audio tracks #1. height can either be 720 or 1080 #2. if height is 720, one of the audio track must be stereo #3. if height is 1080, one of the audio track can be stereo, or it can have, 2,8,14,16 audio tracks def set_profile_name self.profile_name = nil self.error = nil mediainfo = self.mediainfo_output height = (mediainfo["Video"]["Original_height"] || mediainfo["Video"]["Height"]).split("pixels")[0].gsub(/ /,"") stereo = false audio_tracks = mediainfo["Audio"] audio_tracks.each do |track| stereo = true if track["Channel_s_"] =~ /2/ end profile_name = (stereo ? height + "_stereo" : height + "_" + audio_tracks.size.to_s + "_tracks") self.profile_name = self.class.const_get(("pro_" + profile_name).upcase) rescue nil unless self.profiles.keys.include? self.profile_name if height == "720" and !stereo self.error = "Media with height 720 is supported only if it has a stereo track." end if height == "1080" and !([16,14,8,2].include? audio_tracks.size) self.error = "Media with height 1080 is supported only with 16, 14, 8 or 2 audio tracks. But media has #{audio_tracks.size} tracks and is not stereo." end return false end unless self.profile_name.nil? XMorph::Base.logger.debug("XMorph#set_profile_name#gusto: using profile #{self.profile_name}") end return true end end