add support for files with no video (i.e. audio files)
fix stream selection (now in line with ffmpeg's logic) enlarge progress bars :-)
This commit is contained in:
parent
5de735234d
commit
09483b6c7c
1 changed files with 27 additions and 19 deletions
|
@ -155,7 +155,7 @@ if __name__ == '__main__':
|
||||||
amount_vs = len(video_streams)
|
amount_vs = len(video_streams)
|
||||||
amount_as = len(audio_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)
|
main.print('detected §r%d§/ video streams' %(amount_vs), prefix.fail)
|
||||||
print(video_streams)
|
print(video_streams)
|
||||||
main.exit(1)
|
main.exit(1)
|
||||||
|
@ -163,22 +163,28 @@ if __name__ == '__main__':
|
||||||
if amount_as > 1:
|
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)
|
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]
|
if video_streams:
|
||||||
|
# ffmpeg picks the stream with the highest pixel count and then the lowest index
|
||||||
info.video_codec = video['codec_name']
|
video_streams.sort(key=lambda s: s['width'] * s['height'], reverse=True)
|
||||||
info.video_size_x = video['width']
|
video = video_streams[0]
|
||||||
info.video_size_y = video['height']
|
info.video_codec = video['codec_name']
|
||||||
info.video_fps = over.core.text.Unit(parse_fps(video['r_frame_rate']), 'Hz')
|
info.video_size_x = video['width']
|
||||||
|
info.video_size_y = video['height']
|
||||||
if 'bit_rate' in video:
|
info.video_fps = over.core.text.Unit(parse_fps(video['r_frame_rate']), 'Hz')
|
||||||
info.video_bitrate = over.core.text.Unit(video['bit_rate'], 'b/s')
|
|
||||||
elif 'tags' in video and 'BPS' in video['tags']:
|
if 'bit_rate' in video:
|
||||||
info.video_bitrate = over.core.text.Unit(int(video['tags']['BPS']), 'b/s')
|
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:
|
else:
|
||||||
info.video_bitrate = '§r??§/'
|
info.video_fps = 30 # faked for progress bars
|
||||||
info.pixel_fmt = video['pix_fmt']
|
|
||||||
|
|
||||||
if audio_streams:
|
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]
|
audio = audio_streams[0]
|
||||||
info.audio_codec = audio['codec_name']
|
info.audio_codec = audio['codec_name']
|
||||||
info.audio_channels = audio['channels']
|
info.audio_channels = audio['channels']
|
||||||
|
@ -191,8 +197,10 @@ if __name__ == '__main__':
|
||||||
print(identify_dict)
|
print(identify_dict)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# TODO wordify :-)
|
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))
|
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:
|
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))
|
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.INFILE = 'file:' + str(files.infile)
|
||||||
command.normalize_prepass.run(stderr=True)
|
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 = []
|
output_buffer = []
|
||||||
|
|
||||||
|
@ -224,7 +232,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
if b'frame=' in out:
|
if b'frame=' in out:
|
||||||
frame_id = re.findall(b'frame= *(\d+) ', out)[0]
|
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:
|
elif out is None:
|
||||||
break
|
break
|
||||||
|
@ -331,7 +339,7 @@ if __name__ == '__main__':
|
||||||
main.print('will encode into §B%s§/' %(files.tmpfile))
|
main.print('will encode into §B%s§/' %(files.tmpfile))
|
||||||
|
|
||||||
if main.cfg.armed:
|
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)
|
encode_cmd.run(stderr=True)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue