class Transcode < XMorph::Base HIGH_DEFINITION = "HIGH_DEFINITION" STANDARD_DEFINITION = "STANDARD_DEFINITION" def set_profiles self.profiles = { HIGH_DEFINITION => "ffmpeg -y -i %{IN} -vf \"fps=fps=29.970000,scale=1920x1080,setdar=dar=16/9\" -pix_fmt yuv420p -vcodec h264 -g 13 -bf 2 -x264opts nal-hrd=cbr -profile:v high -vb 12000000 -minrate:v 12000000 -maxrate:v 12000000 -bufsize:v 24000000 -acodec libfdk_aac -profile:a aac_low -ab 192k -ar 48000 -map 0:v -map 0:a:0 -muxrate 13411200 -streamid 0:2064 -streamid 1:2068 -vsync 1 -async 1 %{OUT} 2>&1", STANDARD_DEFINITION => "ffmpeg -y -i %{IN} -vf \"fps=fps=29.970000,scale=720x480,setdar=dar=4/3\" -pix_fmt yuv420p -vcodec h264 -g 13 -bf 2 -x264opts nal-hrd=cbr -profile:v high -vb 8000000 -minrate:v 8000000 -maxrate:v 8000000 -bufsize:v 24000000 -acodec libfdk_aac -profile:a aac_low -ab 192k -ar 48000 -map 0:v -map 0:a:0 -muxrate 8600000 -streamid 0:2064 -streamid 1:2068 -vsync 1 -async 1 %{OUT} 2>&1" } end def video_checks { ALLOWED_ASPECT_RATIO => IGNORE, ALLOWED_HEIGHT => (360..1080), ALLOWED_WIDTH => (480..1280), 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], ALLOWED_AUDIO_CODECS => ["aac", "pcm", "mpeg audio"], ALLOWED_AUDIO_BIT_RATE => IGNORE, ALLOWED_NUMBER_OF_AUDIO_CHANNELS => [2], } end # Classification is based on Video Resoltion # HD Videos & 720P Videos are transcoded as 1920x1080 with 16:9 Aspect Ratio # SD Videos are transcoded as 720x480 with 4:3 Aspect Ratio # Aspect Ratio is forced as 16:9 & 4:3 for HD & SD respectively 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(/ /,"") width = (video_info["Original_width"] || video_info["Width"]).split("pixels")[0].gsub(/ /,"") XMorph::Base.logger.debug("XMorph#set_profile_name#shoutfactory: Got Aspect Ratio: #{aspect_ratio}, Height: #{height}, Width: #{width}") if height.present? and width.present? # HD assets if (width.to_i == 1920) and (height.to_i == 1080) self.profile_name = HIGH_DEFINITION # 720P assets are upscaled to HD asset elsif (width.to_i == 1280) and (height.to_i == 720) self.profile_name = HIGH_DEFINITION # Non HD & 720P assets are forced to SD elsif (width.to_i > 0) and (height.to_i > 0) and (width.to_i < 1920) and (height.to_i < 1080) self.profile_name = STANDARD_DEFINITION else self.error = "Got Unexpected Resolution #{width}x#{height}. No transcoding profile available for this." XMorph::Base.logger.debug("XMorph#set_profile_name#shoutfactory: Got something unexpected! No Transcoding profile is available for this.") return false end XMorph::Base.logger.debug("XMorph#set_profile_name#shoutfactory: Converting the file to #{self.profile_name}") else self.error = "Couldn't find Resolution of the Video correctly" end return true end end