class Transcode < XMorph::Base SCALE_TO_720x480_4_3 = "720x480_4_3" SCALE_TO_720x480_16_9 = "720x480_16_9" SCALE_TO_1920x1080_16_9 = "1920x1080_16_9" SCALE_TO_720x480_3_2 = "720x480_3_2" def set_profiles self.profiles = { SCALE_TO_720x480_4_3 => "ffmpeg -y -i %{IN} -map 0:v:0 -map 0:a:0 -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -vf \"fps=fps=29.970000,scale=720x480,setdar=dar=4/3\" -pix_fmt yuv420p -g 13 -bf 2 -profile:v high -vb 12000000 -minrate:v 12000k -maxrate:v 12000k -bufsize:v 24000k -muxrate 13000k -x264opts nal-hrd=cbr -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -vsync 1 -async 1 %{OUT} 2>&1", SCALE_TO_720x480_16_9 => "ffmpeg -y -i %{IN} -map 0:v:0 -map 0:a:0 -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -vf \"fps=fps=29.970000,scale=720x480,setdar=dar=16/9\" -pix_fmt yuv420p -g 13 -bf 2 -profile:v high -vb 12000000 -minrate:v 12000k -maxrate:v 12000k -bufsize:v 24000k -muxrate 13000k -x264opts nal-hrd=cbr -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -vsync 1 -async 1 %{OUT} 2>&1", SCALE_TO_1920x1080_16_9 => "ffmpeg -y -i %{IN} -map 0:v:0 -map 0:a:0 -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -vf \"fps=fps=29.970000,scale=1920x1080,setdar=dar=16/9\" -pix_fmt yuv420p -g 13 -bf 2 -profile:v high -vb 12000000 -minrate:v 12000k -maxrate:v 12000k -bufsize:v 24000k -muxrate 13000k -x264opts nal-hrd=cbr -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -vsync 1 -async 1 %{OUT} 2>&1", SCALE_TO_720x480_3_2 => "ffmpeg -y -i %{IN} -map 0:v:0 -map 0:a:0 -acodec libfdk_aac -profile:a aac_low -ac 2 -ar 48000 -ab 192k -vcodec libx264 -vf \"fps=fps=29.970000,scale=720x480,setdar=dar=4/3\" -pix_fmt yuv420p -g 13 -bf 2 -profile:v high -vb 12000000 -minrate:v 12000k -maxrate:v 12000k -bufsize:v 24000k -muxrate 13000k -x264opts nal-hrd=cbr -pes_payload_size 16 -streamid 0:2064 -streamid 1:2068 -vsync 1 -async 1 %{OUT} 2>&1", } end def video_checks { ALLOWED_ASPECT_RATIO => ["4:3", "16:9", "16:10", "3:2"], ALLOWED_HEIGHT => (400..1080), ALLOWED_WIDTH => (640..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], ALLOWED_AUDIO_CODECS => ["pcm", "aac"], ALLOWED_AUDIO_BIT_RATE => IGNORE, #kbps ALLOWED_NUMBER_OF_AUDIO_CHANNELS => [2, 6], } end # Classification is based on Height, Width and aspect ratio # 4:3 Aspect Ratio & SD (720 * (xyz)) & SD (640 * 480): scaled to 720x480 wih 4:3 # 16:9 Aspect Ratio & SD (720 * (xyz)): scaled to 720x480 wih 16:9 # 16:9 Aspect Ratio & HD ( 1080p & 720p ): scaled to 1920x1080 wih 16:9 # 3:2 Aspect Ratio and (720 * (xyz)): scaled to 720x480 with 4:3 def set_profile_name self.profile_name = nil self.error = 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(/ /,"").to_i width = (video_info["Original_width"] || video_info["Width"]).split("pixels")[0].gsub(/ /,"").to_i if aspect_ratio == "4:3" if width == 640 if height == 480 self.profile_name = SCALE_TO_720x480_4_3 else self.error = "Got unexpected height #{height} for video with width-#{width} and AR-#{aspect_ratio}, expected height: 480" end elsif width == 720 if (400..600).include? height self.profile_name = SCALE_TO_720x480_4_3 else self.error = "Got unexpected height #{height} for video with width-#{width} and AR-#{aspect_ratio}, expected height to be 400-600" end else self.error = "Got unexpected width-#{width} for video with AR-#{aspect_ratio}, expected width: 640 or 720" end elsif ["16:9", "16:10"].include? aspect_ratio if width == 720 self.profile_name = SCALE_TO_720x480_16_9 elsif (width == 1920 and height == 1080) or (width == 1280 and height == 720) self.profile_name = SCALE_TO_1920x1080_16_9 else self.error = "Got unexpected width #{width} and height #{height} for video with AR-#{aspect_ratio}, expected : 720x(*) or 1920x1080 or 1280x720" end elsif aspect_ratio == "3:2" if width == 720 if (400..600).include? height self.profile_name = SCALE_TO_720x480_3_2 else self.error = "Got unexpected height #{height} for video with width-#{width} and AR-#{aspect_ratio}, expected height to be 400-600" end else self.error = "Got unexpected width-#{width} for video with AR-#{aspect_ratio}, expected width: 720" end end XMorph::Base.logger.debug("XMorph#set_profile_name#Cinedigm: using profile #{self.profile_name}") unless self.profile_name.nil? return true end end