finished aux.Command, working volume detection pre-pass

This commit is contained in:
Overwatch 2014-08-15 16:57:04 +02:00
parent 5c3df8f2fc
commit b165bb628d
2 changed files with 82 additions and 56 deletions

View file

@ -52,7 +52,8 @@ if __name__ == "__main__":
identify_cmd = Command(command.identify)
identify_cmd.INFILE = tgt
identify_raw = identify_cmd.run()
identify_cmd.run()
identify_raw = identify_cmd.get_all_output()
identify_dict = json.loads(identify_raw.decode("utf-8"))
info = over.core.types.ndict()
@ -95,29 +96,38 @@ if __name__ == "__main__":
norm_pre_cmd = Command(command.normalize_prepass)
norm_pre_cmd.INFILE = tgt
norm_pre_cmd.run(async=True, stderr=True)
norm_pre_cmd.run(stderr=True)
pb = over.core.textui.ProgressBar(50, int(info.video_fps.value * info.duration), "frames")
output_buffer = []
while True:
probably_dead = not norm_pre_cmd.running
time.sleep(.25)
o = norm_pre_cmd.poll_output()
out = norm_pre_cmd.get_output()
if o:
if b"frame=" in o:
frame_id = re.findall(b"frame= *(\d+) ", o)[0]
pb.update(int(frame_id))
if out:
output_buffer.append(out)
elif b"mean_volume: " in o:
info.mean_volume = float(re.findall(b"mean_volume: (-\d+\.\d+) dB", o)[0])
info.volume_correction = info.mean_volume - main.cfg.normalize_mean
else:
print(o)
if b"frame=" in out:
frame_id = re.findall(b"frame= *(\d+) ", out)[0]
pb.update(int(frame_id))
elif not norm_pre_cmd.running and probably_dead:
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 = info.mean_volume - main.cfg.normalize_mean
else:
_print("§runexpected ffmpeg output§/, dump follows", prefix.fail, suffix=":\n")
print(output)
raise RuntimeError
pb.blank()
_print("detected volume %.2f dB, correction %.2f dB" %(info.mean_volume, info.volume_correction))