def _scan_video(self, ae_type, ae_path): mpeg_info = check_video(ae_path, self.vod_config.mediainfo_path) # Calculate the run time of the video duration_s = int(round(float(mpeg_info["General"]["Duration"]) / 1000)) duration_h, duration_s = divmod(duration_s, 3600) duration_m, duration_s = divmod(duration_s, 60) duration_h = format(duration_h, "02") duration_m = format(duration_m, "02") duration_s = format(duration_s, "02") # For the movie asset, the Run_Time and Display_Run_Time are given as # part of the title's metadata. For the preview asset, the Run_Time is # given as part of the preview's metadata if ae_type == "movie": self.D_app["title"]["Run_Time"] = "{}:{}:{}".format( duration_h, duration_m, duration_s) self.D_app["title"]["Display_Run_Time"] = "{}:{}".format( duration_h, duration_m) elif ae_type == "preview": self.D_app["preview"]["Run_Time"] = "{}:{}:{}".format( duration_h, duration_m, duration_s) # Determine the audio type audio_type = int(mpeg_info["Audio"].get("Channel(s)", 0)) self.D_app[ae_type]["Audio_Type"] = ("Stereo" if (audio_type > 1) else "Mono") if self.vod_config.ecn_2009: # Determine the movie's codec commercial_name = mpeg_info["Video"]["Commercial name"] format_profile = mpeg_info["Video"]["Format profile"] if commercial_name == "MPEG-2 Video": self.D_app[ae_type]["Codec"] = "MPEG2" elif commercial_name == "AVC": avc_profile = format_profile[0] avc_level = format_profile.split('@')[1][1:] avc_level = format(float(avc_level), '0.1f').replace('.', '') codec = "AVC {}P@L{}".format(avc_profile, avc_level) self.D_app[ae_type]["Codec"] = codec else: raise InvalidMpeg("Could not determine codec for {}".format( self.D_content[ae_type])) # Determine the geometry movie_resolution_height = mpeg_info["Video"]["Height"] move_resolution_scan = mpeg_info["Video"]["Scan type"][0].lower() self.D_app[ae_type]["Resolution"] = "{}{}".format( movie_resolution_height, move_resolution_scan) # Determine the movie's frame rate frame_rate = float(mpeg_info["Video"]["Frame rate"]) self.D_app[ae_type]["Frame_Rate"] = format(frame_rate, '.0f') # Determine the movie's bitrate (actually kilobit rate) bit_rate = float(mpeg_info["General"]["Overall bit rate"]) / 1000 self.D_app[ae_type]["Bit_Rate"] = format(bit_rate, '.0f')
def test_check_video(self, mock_call_MediaInfo): # No modification -> should return normally mock_call_MediaInfo.return_value = self.D_reference self.assertEqual(check_video(reference_mp4), self.D_reference) # No General or Video section -> should fail for key in self.D_reference.keys(): D = deepcopy(self.D_reference) del D[key] mock_call_MediaInfo.return_value = D with self.assertRaises(MediaInfoError): check_video(reference_mp4) # Missing keys -> should fail for section in ("General", "Video"): for key in self.D_reference[section]: D = deepcopy(self.D_reference) del D[section][key] mock_call_MediaInfo.return_value = D with self.assertRaises(MediaInfoError): check_video(reference_mp4)
def _scan_video(self, ae_type, ae_path): mpeg_info = check_video(ae_path, self.vod_config.mediainfo_path) # Calculate the run time of the video duration_s = int(round(float(mpeg_info["General"]["Duration"]) / 1000)) duration_h, duration_s = divmod(duration_s, 3600) duration_m, duration_s = divmod(duration_s, 60) duration_h = format(duration_h, "02") duration_m = format(duration_m, "02") duration_s = format(duration_s, "02") # For the movie asset, the Run_Time and Display_Run_Time are given as # part of the title's metadata. For the preview asset, the Run_Time is # given as part of the preview's metadata if ae_type == "movie": self.D_app["title"]["Run_Time"] = "{}:{}:{}".format(duration_h, duration_m, duration_s) self.D_app["title"]["Display_Run_Time"] = "{}:{}".format(duration_h, duration_m) elif ae_type == "preview": self.D_app["preview"]["Run_Time"] = "{}:{}:{}".format(duration_h, duration_m, duration_s) # Determine the audio type audio_type = int(mpeg_info["Audio"].get("Channel(s)", 0)) self.D_app[ae_type]["Audio_Type"] = "Stereo" if (audio_type > 1) else "Mono" if self.vod_config.ecn_2009: # Determine the movie's codec commercial_name = mpeg_info["Video"]["Commercial name"] format_profile = mpeg_info["Video"]["Format profile"] if commercial_name == "MPEG-2 Video": self.D_app[ae_type]["Codec"] = "MPEG2" elif commercial_name == "AVC": avc_profile = format_profile[0] avc_level = format_profile.split("@")[1][1:] avc_level = format(float(avc_level), "0.1f").replace(".", "") codec = "AVC {}P@L{}".format(avc_profile, avc_level) self.D_app[ae_type]["Codec"] = codec else: raise InvalidMpeg("Could not determine codec for {}".format(self.D_content[ae_type])) # Determine the geometry movie_resolution_height = mpeg_info["Video"]["Height"] move_resolution_scan = mpeg_info["Video"]["Scan type"][0].lower() self.D_app[ae_type]["Resolution"] = "{}{}".format(movie_resolution_height, move_resolution_scan) # Determine the movie's frame rate frame_rate = float(mpeg_info["Video"]["Frame rate"]) self.D_app[ae_type]["Frame_Rate"] = format(frame_rate, ".0f") # Determine the movie's bitrate (actually kilobit rate) bit_rate = float(mpeg_info["General"]["Overall bit rate"]) / 1000 self.D_app[ae_type]["Bit_Rate"] = format(bit_rate, ".0f")