def parse_ffmpeginfo(self, sfile): ''' get ffmpeg video info ''' result = { 'video_map':'0:0', 'audio_map':'0:1' } args = self.ffmpeg_run + " -i " + str(sfile) + " 2>info_video.txt" os.popen(args).readlines() stdout = '' if os.path.isfile('info_video.txt') == True: fp = open('info_video.txt', 'r') stdout = fp.readlines() fp.close() mode = 'none' for line in stdout: line = line.strip() if 'Stream' in line: if line.find('Video') > 0: value = line[8:11] value = value.replace('.', ':') func.set_par(result, 'video_map', value) if line.find('Audio') > 0: value = line[8:11] func.set_par(result, 'audio_map', value) value = value.replace('.', ':') break self.ffmpeg_info = result return result
def parse_mediainfo(self, sfile): ''' get mediainfo video info ''' args = [self.mediainfo_run, '-f', sfile] output = subprocess.Popen(args, stdout=subprocess.PIPE).stdout data = output.readlines() output.close() mode = 'none' iscomplete = 0 result = { 'general_format' : '', 'general_codec' : '', 'general_size' : None, 'general_bitrate' : None, 'general_duration' : None, 'is_general':'', 'video_format' : '', 'video_codec_id' : '', 'video_codec' : '', 'video_bitrate' : None, 'video_width' : None, 'video_height' : None, 'video_displayaspect' : None, 'video_pixelaspect' : None, 'video_scantype' : '', 'video_framerate': '', 'video_colorspace': '', 'video_chromasubsampling':'', 'is_video':'', 'audio_format' : '', 'audio_codec_id' : '', 'audio_codec' : '', 'audio_bitrate' : None, 'audio_channels' : None, 'audio_samplerate' : None, 'audio_resolution' : None, 'audio_language' : '', 'is_audio':'' } for line in data: if not ':' in line: if 'General' in line: mode = 'General' elif 'Video' in line: mode = 'Video' elif 'Audio' in line: mode = 'Audio' elif 'Text' in line: mode = 'Text' else: key, sep, value = line.partition(':') key = key.strip() value = value.strip() if mode == 'General': if key == 'Format': func.set_par(result, 'general_format', value) if key == 'Codec': func.set_par(result,'general_codec', value) if key == 'File size': func.set_par(result,'general_size', value) if key == 'Overall bit rate': func.set_par(result,'general_bitrate', value) if key == 'Duration': func.set_par(result,'general_duration', value) func.set_par(result,'is_general', 1) if mode == 'Video': if key == 'Format': func.set_par(result,'video_format', value) if key == 'Codec ID': func.set_par(result,'video_codec_id', value) if key == 'Codec': func.set_par(result,'video_codec', value) if key == 'Nominal bit rate': func.set_par(result,'video_bitrate', value) if key == 'Width': func.set_par(result,'video_width', value) if key == 'Height': func.set_par(result,'video_height', value) if key == 'Display aspect ratio': func.set_par(result,'video_displayaspect', value) if key == 'Pixel Aspect Ratio': func.set_par(result,'video_pixelaspect', value) if key == 'Scan type': func.set_par(result,'video_scantype', value) if key == 'Nominal frame rate': func.set_par(result,'audio_language', value) if key == 'Frame rate': func.set_par(result,'video_framerate', value) if key == 'Color space': func.set_par(result,'video_colorspace', value) if key == 'Chroma subsampling': func.set_par(result,'video_chromasubsampling', value) func.set_par(result,'is_video', 1) if mode == 'Audio': if key == 'Format': func.set_par(result,'audio_format', value) if key == 'Codec ID': func.set_par(result,'audio_codec_id', value) if key == 'Codec': func.set_par(result,'audio_codec', value) if key == 'Bit rate': func.set_par(result,'audio_bitrate', value) if key == 'Channel(s)': func.set_par(result,'audio_channels', value) if key == 'Sampling rate': func.set_par(result,'audio_samplerate', value) if key == 'Resolution': func.set_par(result,'audio_resolution', value) if key == 'Language': func.set_par(result,'audio_language', value) func.set_par(result,'is_audio', 1) self.mediainfo_info = result return result