added --normalize-override: Volume correction to use instead of computing the required value in a (lengthy) pre-pass.
This commit is contained in:
parent
3fff52fedc
commit
ae18e7a6ef
1 changed files with 41 additions and 33 deletions
|
@ -43,7 +43,8 @@ if __name__ == '__main__':
|
|||
main.add_option('video', 'str', 'x264', 'Video codec to use, either §mx264§/, §mtheora§/, §mcopy§/ or §mdrop§/.', short_name='v')
|
||||
main.add_option('video-quality', 'float', 22, 'Video encoding quality. Use 0-10 for Theora (0 being the lowest, 5-7 is generally watchable) and 0-51 for x264 (0 being lossless, 18-28 is reasonable).', short_name='Q')
|
||||
main.add_option('normalize', 'bool', True, 'Normalize the audio track.', short_name='n')
|
||||
main.add_option('normalize-target', 'float', -20.0, 'Target mean volume to target.', short_name='N')
|
||||
main.add_option('normalize-target', 'float', -20.0, 'Target mean volume to target.')
|
||||
main.add_option('normalize-override', 'float', 0.0, 'Volume correction to use instead of computing the required value in a (lengthy) pre-pass.', short_name='N')
|
||||
main.add_option('ffmpeg-vfilter', 'str', '', 'Raw ffmpeg -filter:v options, e.g. "scale=720:trunc(ow/a/2)*2"', short_name='f')
|
||||
main.add_option('move-source', 'str', '', 'Move source file to this directory after conversion.', short_name='m')
|
||||
main.add_option('dump-commands', 'bool', False, 'Print ffmpeg commands that would be executed. If §B--§gnormalize§/ is in effect, the normalization pre-pass will still be performed so that the proper volume correction can be computed.', short_name='D')
|
||||
|
@ -68,7 +69,9 @@ if __name__ == '__main__':
|
|||
if main.cfg.audio == 'vorbis':
|
||||
audio_words.append('§gquality§/=§m%.1f§/' %(main.cfg.audio_quality))
|
||||
|
||||
if main.cfg.normalize:
|
||||
if main.cfg.normalize_override != 0:
|
||||
audio_words.append('§gadjust_volume§/=§m%.1f dB§/' %(main.cfg.normalize_override))
|
||||
elif main.cfg.normalize:
|
||||
audio_words.append('§gnormalize§/=§m%.1f dB§/' %(main.cfg.normalize_target))
|
||||
|
||||
if main.cfg.video in ('copy', 'drop'):
|
||||
|
@ -177,43 +180,48 @@ if __name__ == '__main__':
|
|||
# normalization pre-pass
|
||||
|
||||
if (main.cfg.armed or main.cfg.dump_commands) and main.cfg.normalize:
|
||||
_print('running normalization pre-pass')
|
||||
|
||||
command.normalize_prepass.reset()
|
||||
command.normalize_prepass.INFILE = 'file:' + str(files.infile)
|
||||
command.normalize_prepass.run(stderr=True)
|
||||
|
||||
pb = over.core.textui.ProgressBar(60, int(info.video_fps.value * info.duration), 'frames')
|
||||
|
||||
output_buffer = []
|
||||
|
||||
while True:
|
||||
time.sleep(.25)
|
||||
if main.cfg.normalize_override == 0.0:
|
||||
_print('running normalization pre-pass')
|
||||
|
||||
out = command.normalize_prepass.get_output()
|
||||
command.normalize_prepass.reset()
|
||||
command.normalize_prepass.INFILE = 'file:' + str(files.infile)
|
||||
command.normalize_prepass.run(stderr=True)
|
||||
|
||||
if out:
|
||||
output_buffer.append(out)
|
||||
pb = over.core.textui.ProgressBar(60, int(info.video_fps.value * info.duration), 'frames')
|
||||
|
||||
output_buffer = []
|
||||
|
||||
while True:
|
||||
time.sleep(.25)
|
||||
|
||||
if b'frame=' in out:
|
||||
frame_id = re.findall(b'frame= *(\d+) ', out)[0]
|
||||
pb.update(int(frame_id))
|
||||
out = command.normalize_prepass.get_output()
|
||||
|
||||
if out:
|
||||
output_buffer.append(out)
|
||||
|
||||
if b'frame=' in out:
|
||||
frame_id = re.findall(b'frame= *(\d+) ', out)[0]
|
||||
pb.update(int(frame_id))
|
||||
|
||||
elif out is None:
|
||||
break
|
||||
|
||||
elif out is None:
|
||||
break
|
||||
output = b''.join(output_buffer)
|
||||
|
||||
if b'mean_volume: ' in output:
|
||||
info.mean_volume = float(re.findall(b'mean_volume: (-\d+\.\d+) dB', output)[0])
|
||||
info.volume_correction = main.cfg.normalize_target - info.mean_volume
|
||||
else:
|
||||
_print('§runexpected ffmpeg output§/, dump follows', prefix.fail, suffix=':\n')
|
||||
print(output)
|
||||
raise RuntimeError
|
||||
|
||||
pb.blank()
|
||||
_print('detected volume %.1f dB, correction %.1f dB' %(info.mean_volume, info.volume_correction))
|
||||
|
||||
output = b''.join(output_buffer)
|
||||
|
||||
if b'mean_volume: ' in output:
|
||||
info.mean_volume = float(re.findall(b'mean_volume: (-\d+\.\d+) dB', output)[0])
|
||||
info.volume_correction = main.cfg.normalize_target - info.mean_volume
|
||||
else:
|
||||
_print('§runexpected ffmpeg output§/, dump follows', prefix.fail, suffix=':\n')
|
||||
print(output)
|
||||
raise RuntimeError
|
||||
|
||||
pb.blank()
|
||||
_print('detected volume %.1f dB, correction %.1f dB' %(info.mean_volume, info.volume_correction))
|
||||
info.volume_correction = main.cfg.normalize_override
|
||||
_print('using user-supplied volume correction %.1f dB' %(info.volume_correction))
|
||||
|
||||
info.normalize_command = command.sub_normalize
|
||||
info.normalize_command.reset()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue