From 09483b6c7c57fdc8fdc11484b9891fbad5a3f15a Mon Sep 17 00:00:00 2001 From: Martinez Date: Sat, 26 Dec 2015 20:41:51 +0100 Subject: [PATCH] add support for files with no video (i.e. audio files) fix stream selection (now in line with ffmpeg's logic) enlarge progress bars :-) --- over-video.py | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/over-video.py b/over-video.py index 41bdd8f..29e2c4e 100755 --- a/over-video.py +++ b/over-video.py @@ -155,7 +155,7 @@ if __name__ == '__main__': amount_vs = len(video_streams) amount_as = len(audio_streams) - if amount_vs != 1: + if amount_vs > 1: main.print('detected §r%d§/ video streams' %(amount_vs), prefix.fail) print(video_streams) main.exit(1) @@ -163,22 +163,28 @@ if __name__ == '__main__': if amount_as > 1: main.print('detected §y%d§/ audio streams, picking the "best" one (see man 1 ffmpeg, section STREAM SELECTION)' %(amount_as), prefix.warn) - video = video_streams[0] - - info.video_codec = video['codec_name'] - info.video_size_x = video['width'] - info.video_size_y = video['height'] - info.video_fps = over.core.text.Unit(parse_fps(video['r_frame_rate']), 'Hz') - - if 'bit_rate' in video: - info.video_bitrate = over.core.text.Unit(video['bit_rate'], 'b/s') - elif 'tags' in video and 'BPS' in video['tags']: - info.video_bitrate = over.core.text.Unit(int(video['tags']['BPS']), 'b/s') + if video_streams: + # ffmpeg picks the stream with the highest pixel count and then the lowest index + video_streams.sort(key=lambda s: s['width'] * s['height'], reverse=True) + video = video_streams[0] + info.video_codec = video['codec_name'] + info.video_size_x = video['width'] + info.video_size_y = video['height'] + info.video_fps = over.core.text.Unit(parse_fps(video['r_frame_rate']), 'Hz') + + if 'bit_rate' in video: + info.video_bitrate = over.core.text.Unit(video['bit_rate'], 'b/s') + elif 'tags' in video and 'BPS' in video['tags']: + info.video_bitrate = over.core.text.Unit(int(video['tags']['BPS']), 'b/s') + else: + info.video_bitrate = '§r??§/' + info.pixel_fmt = video['pix_fmt'] else: - info.video_bitrate = '§r??§/' - info.pixel_fmt = video['pix_fmt'] + info.video_fps = 30 # faked for progress bars if audio_streams: + # ffmpeg picks the stream with the most channels and then the lowest index + audio_streams.sort(key=lambda s: s['channels'], reverse=True) audio = audio_streams[0] info.audio_codec = audio['codec_name'] info.audio_channels = audio['channels'] @@ -191,8 +197,10 @@ if __name__ == '__main__': print(identify_dict) raise - # TODO wordify :-) - main.print('§mvideo§/: size=§b%d§/x§b%d§/ px, framerate=%s, codec=%s, bitrate=%s' %(info.video_size_x, info.video_size_y, info.video_fps, info.video_codec, info.video_bitrate)) + if video_streams: + main.print('§mvideo§/: size=§b%d§/x§b%d§/ px, framerate=%s, codec=%s, bitrate=%s' %(info.video_size_x, info.video_size_y, info.video_fps, info.video_codec, info.video_bitrate)) + else: + main.print('§mvideo§/: §yNone§/', prefix.warn) if audio_streams: main.print('§caudio§/: channels=§b%d§/, samplerate=%s, codec=%s, bitrate=%s, language=%s' %(info.audio_channels, info.audio_samplerate, info.audio_codec, info.audio_bitrate, info.audio_language)) @@ -210,7 +218,7 @@ if __name__ == '__main__': command.normalize_prepass.INFILE = 'file:' + str(files.infile) command.normalize_prepass.run(stderr=True) - pb = over.core.text.ProgressBar(60, int(info.video_fps.value * info.duration), 'frames') + pb = over.core.text.ProgressBar(120, info.duration, 's') output_buffer = [] @@ -224,7 +232,7 @@ if __name__ == '__main__': if b'frame=' in out: frame_id = re.findall(b'frame= *(\d+) ', out)[0] - pb.update(int(frame_id)) + pb.update(int(frame_id) / info.video_fps.value) elif out is None: break @@ -331,7 +339,7 @@ if __name__ == '__main__': main.print('will encode into §B%s§/' %(files.tmpfile)) if main.cfg.armed: - pb = over.core.text.ProgressBar(60, int(info.video_fps.value * info.duration), 'frames') + pb = over.core.text.ProgressBar(120, int(info.video_fps.value * info.duration), 'frames') encode_cmd.run(stderr=True)