class Transcode < XMorph::Base PRO_4_3_STEREO = "4_3_STEREO" PRO_4_3_MORE_CH_4 = "4_3_MORE_CH_4" PRO_4_3_MORE_CH_8 = "4_3_MORE_CH_8" PRO_4_3_2_TRACKS = "4_3_2_TRACKS" PRO_4_3_4_TRACKS = "4_3_4_TRACKS" PRO_4_3_6_TRACKS = "4_3_6_TRACKS" PRO_4_3_8_TRACKS = "4_3_8_TRACKS" PRO_16_9_STEREO = "16_9_STEREO" PRO_16_9_MORE_CH_4 = "16_9_MORE_CH_4" PRO_16_9_MORE_CH_8 = "16_9_MORE_CH_8" PRO_16_9_2_TRACKS = "16_9_2_TRACKS" PRO_16_9_4_TRACKS = "16_9_4_TRACKS" PRO_16_9_6_TRACKS = "16_9_6_TRACKS" PRO_16_9_8_TRACKS = "16_9_8_TRACKS" PRO_1080_STEREO = "1080_STEREO" PRO_1080_MORE_CH_4 = "1080_MORE_CH_4" PRO_1080_MORE_CH_8 = "1080_MORE_CH_8" PRO_1080_2_TRACKS = "1080_2_TRACKS" PRO_1080_4_TRACKS = "1080_4_TRACKS" PRO_1080_6_TRACKS = "1080_6_TRACKS" PRO_1080_8_TRACKS = "1080_8_TRACKS" def set_profiles self.profiles = { PRO_4_3_STEREO => "ffmpeg -y -i %{IN} -map 0:v -map 0:a -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -bf 2 -profile:v high -aspect 4:3 -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 -streamid 5:2072 -streamid 6:2073 -streamid 7:2074 -streamid 8:2075 %{OUT} 2>&1", PRO_4_3_MORE_CH_4 => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0]pan=stereo|c0=c0|c1=c1[a];[0]pan=stereo|c0=c2|c1=c3[b]\" -map \"[a]\" -map \"[b]\" -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 4:3 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 %{OUT} 2>&1", PRO_4_3_MORE_CH_8 => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0]pan=stereo|c0=c0|c1=c1[a];[0]pan=stereo|c0=c2|c1=c3[b];[0]pan=stereo|c0=c4|c1=c5[c];[0]pan=stereo|c0=c6|c1=c7[d]\" -map \"[a]\" -map \"[b]\" -map \"[c]\" -map \"[d]\" -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 4:3 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 -streamid 5:2072 -streamid 6:2073 -streamid 7:2074 -streamid 8:2075 %{OUT} 2>&1", PRO_4_3_2_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -aspect 4:3 -g 13 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_4_3_4_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -filter_complex \"[0:a:2][0:a:3] amerge=inputs=2[audio2]\" -map [audio2] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -aspect 4:3 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_4_3_6_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -filter_complex \"[0:a:2][0:a:3] amerge=inputs=2[audio2]\" -map [audio2] -filter_complex \"[0:a:4][0:a:5] amerge=inputs=2[audio3]\" -map [audio3] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 4:3 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_4_3_8_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -filter_complex \"[0:a:2][0:a:3] amerge=inputs=2[audio2]\" -map [audio2] -filter_complex \"[0:a:4][0:a:5] amerge=inputs=2[audio3]\" -map [audio3] -filter_complex \"[0:a:6][0:a:7] amerge=inputs=2[audio4]\" -map [audio4] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 4:3 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_16_9_STEREO => "ffmpeg -y -i %{IN} -map 0:v -map 0:a -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -bf 2 -profile:v high -aspect 16:9 -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 -streamid 5:2072 -streamid 6:2073 -streamid 7:2074 -streamid 8:2075 %{OUT} 2>&1", PRO_16_9_MORE_CH_4 => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0]pan=stereo|c0=c0|c1=c1[a];[0]pan=stereo|c0=c2|c1=c3[b]\" -map \"[a]\" -map \"[b]\" -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 %{OUT} 2>&1", PRO_16_9_MORE_CH_8 => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0]pan=stereo|c0=c0|c1=c1[a];[0]pan=stereo|c0=c2|c1=c3[b];[0]pan=stereo|c0=c4|c1=c5[c];[0]pan=stereo|c0=c6|c1=c7[d]\" -map \"[a]\" -map \"[b]\" -map \"[c]\" -map \"[d]\" -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 -streamid 5:2072 -streamid 6:2073 -streamid 7:2074 -streamid 8:2075 %{OUT} 2>&1", PRO_16_9_2_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_16_9_4_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -filter_complex \"[0:a:2][0:a:3] amerge=inputs=2[audio2]\" -map [audio2] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_16_9_6_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -filter_complex \"[0:a:2][0:a:3] amerge=inputs=2[audio2]\" -map [audio2] -filter_complex \"[0:a:4][0:a:5] amerge=inputs=2[audio3]\" -map [audio3] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_16_9_8_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -filter_complex \"[0:a:2][0:a:3] amerge=inputs=2[audio2]\" -map [audio2] -filter_complex \"[0:a:4][0:a:5] amerge=inputs=2[audio3]\" -map [audio3] -filter_complex \"[0:a:6][0:a:7] amerge=inputs=2[audio4]\" -map [audio4] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -filter:v \"crop=720:576:0:32\" -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_1080_STEREO => "ffmpeg -y -i %{IN} -map 0:v -map 0:a -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_1080_MORE_CH_4 => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0]pan=stereo|c0=c0|c1=c1[a];[0]pan=stereo|c0=c2|c1=c3[b]\" -map \"[a]\" -map \"[b]\" -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 %{OUT} 2>&1", PRO_1080_MORE_CH_8 => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0]pan=stereo|c0=c0|c1=c1[a];[0]pan=stereo|c0=c2|c1=c3[b];[0]pan=stereo|c0=c4|c1=c5[c];[0]pan=stereo|c0=c6|c1=c7[d]\" -map \"[a]\" -map \"[b]\" -map \"[c]\" -map \"[d]\" -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 -streamid 5:2072 -streamid 6:2073 -streamid 7:2074 -streamid 8:2075 %{OUT} 2>&1", PRO_1080_2_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_1080_4_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -filter_complex \"[0:a:2][0:a:3] amerge=inputs=2[audio2]\" -map [audio2] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_1080_6_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -filter_complex \"[0:a:2][0:a:3] amerge=inputs=2[audio2]\" -map [audio2] -filter_complex \"[0:a:4][0:a:5] amerge=inputs=2[audio3]\" -map [audio3] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", PRO_1080_8_TRACKS => "ffmpeg -y -i %{IN} -map 0:v -filter_complex \"[0:a:0][0:a:1] amerge=inputs=2[audio1]\" -map [audio1] -filter_complex \"[0:a:2][0:a:3] amerge=inputs=2[audio2]\" -map [audio2] -filter_complex \"[0:a:4][0:a:5] amerge=inputs=2[audio3]\" -map [audio3] -filter_complex \"[0:a:6][0:a:7] amerge=inputs=2[audio4]\" -map [audio4] -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -pix_fmt yuv420p -flags +ilme+ildct -x264opts tff=1 -x264opts nal-hrd=cbr -g 13 -aspect 16:9 -bf 2 -profile:v high -b:v 12M -minrate:v 12M -maxrate:v 12M -muxrate 14M -bufsize:v 25M -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -streamid 2:2069 -streamid 3:2070 -streamid 4:2071 %{OUT} 2>&1", } end def video_checks { ALLOWED_ASPECT_RATIO => ["16:9", "4:3"], ALLOWED_HEIGHT => [576, 608, 1080], ALLOWED_WIDTH => [720, 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, 2, 3, 4, 5, 8], ALLOWED_AUDIO_CODECS => ["aac", "pcm", "dolby e"], ALLOWED_AUDIO_BIT_RATE => IGNORE, ALLOWED_NUMBER_OF_AUDIO_CHANNELS => [1, 2, 4, 6, 8], } end #profiles are classified based on aspect ratio, height and number of audio channels #1. height is 1080 and audio tracks could be (1 track with stereo), (2, 4, 6, 8 tracks and all mono), (1 track with 4, 8 channels) #2. line 1 applies with aspect ration as 4:3 and 16:9 def set_profile_name self.profile_name = nil mediainfo = self.mediainfo_output video_info = mediainfo["Video"] aspect_ratio = video_info["Display_aspect_ratio"] height = (video_info["Original_height"] || video_info["Height"]).split("pixels")[0].gsub(/ /,"") height = aspect_ratio.gsub(":","_") if height != "1080" stereo = false audio_tracks = mediainfo["Audio"] audio_tracks.each do |audio| stereo = true if audio["Channel_s_"] =~ /2/ end more_than_two_chans = audio_tracks.size == 1 && (audio_tracks[0]["Channel_s__Original"]||audio_tracks[0]["Channel_s_"]).match(/(4|8)/) ret = stereo ? height + "_stereo" : height + "_" + audio_tracks.size.to_s + "_tracks" profile_name = more_than_two_chans ? height + "_more_ch_" + (audio_tracks[0]["Channel_s__Original"]||audio_tracks[0]["Channel_s_"]).match(/(4|8)/).to_s : ret self.profile_name = self.class.const_get(("pro_" + profile_name).upcase) rescue nil unless self.profiles.keys.include? self.profile_name errors = [] channels = [] audio_tracks.each {|info| channels << (info["Channel_s__Original"] || info["Channel_s_"]).split("channels")[0].strip} if audio_tracks.size == 1 and !((channels-["2","4","8"]).empty?) errors << "Number of channels allowed if there's only 1 audio track is 2,4,8. But media has #{channels.join} channels" end if audio_tracks.size != 1 and !([2,4,6,8].include? audio_tracks.size) and !stereo #todo think of better error msg errors << "If the number of audio tracks is odd. One of the track must be stereo" end self.error = errors.join(" ; ") unless errors.empty? return false end XMorph::Base.logger.debug("XMorph#set_profile_name#TurnerNordic: using profile #{self.profile_name}") unless self.profile_name.nil? return true end end