fixed progressbar crashing on non-video media
This commit is contained in:
parent
2929725416
commit
e94c3d166f
3 changed files with 29 additions and 11 deletions
18
aux.py
18
aux.py
|
@ -4,6 +4,7 @@
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import over
|
import over
|
||||||
|
import re
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
||||||
|
@ -17,6 +18,23 @@ def parse_fps(raw):
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
||||||
|
def parse_time(raw):
|
||||||
|
"""
|
||||||
|
Parses ffmpeg's state sentence containing the time= token.
|
||||||
|
|
||||||
|
E.g. b"... time=00:01:11.85 ..."
|
||||||
|
|
||||||
|
Returns the time in seconds, e.g. 71.85.
|
||||||
|
"""
|
||||||
|
|
||||||
|
s = re.findall(b"time=([^ ]+) ", raw)[0]
|
||||||
|
|
||||||
|
hh, mm, ss = (float(t) for t in s.split(b":"))
|
||||||
|
|
||||||
|
return hh * 3600 + mm * 60 + ss
|
||||||
|
|
||||||
|
# --------------------------------------------------
|
||||||
|
|
||||||
def to_Path(raw_path):
|
def to_Path(raw_path):
|
||||||
"""
|
"""
|
||||||
Returns pathlib.Path pointing to raw_path, handling "~/" correctly.
|
Returns pathlib.Path pointing to raw_path, handling "~/" correctly.
|
||||||
|
|
|
@ -262,9 +262,9 @@ if __name__ == "__main__":
|
||||||
if out:
|
if out:
|
||||||
output_buffer.append(out)
|
output_buffer.append(out)
|
||||||
|
|
||||||
if b"frame=" in out:
|
if b"time=" in out:
|
||||||
frame_id = re.findall(b"frame= *(\d+) ", out)[0]
|
t = aux.parse_time(out)
|
||||||
pb.set("a", int(frame_id) / info.video_fps.value)
|
pb.set("a", t)
|
||||||
pb.render()
|
pb.render()
|
||||||
|
|
||||||
elif out is None:
|
elif out is None:
|
||||||
|
@ -398,11 +398,11 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
if main.cfg.armed:
|
if main.cfg.armed:
|
||||||
pb = over.text.ProgressBar(
|
pb = over.text.ProgressBar(
|
||||||
"§%f §rs [§=f>§ F] §sf (§ss) (Sest=§zs, Trem=§TF)",
|
"§%a §rs [§=a>§ A] §sa (§ss) (Sest=§zs, Trem=§TA)",
|
||||||
{
|
{
|
||||||
"f": {
|
"a": {
|
||||||
"unit": "f",
|
"unit": "s",
|
||||||
"top": int(info.video_fps.value * info.duration),
|
"top": int(info.duration),
|
||||||
"precision": 1,
|
"precision": 1,
|
||||||
"min_width_rate": 9
|
"min_width_rate": 9
|
||||||
},
|
},
|
||||||
|
@ -424,9 +424,9 @@ if __name__ == "__main__":
|
||||||
out = encode_cmd.get_output()
|
out = encode_cmd.get_output()
|
||||||
|
|
||||||
if out:
|
if out:
|
||||||
if b"frame=" in out:
|
if b"time=" in out:
|
||||||
frame_id = re.findall(b"frame= *(\d+) ", out)[0]
|
t = aux.parse_time(out)
|
||||||
pb.set("f", int(frame_id))
|
pb.set("a", int(t))
|
||||||
|
|
||||||
elif out is None:
|
elif out is None:
|
||||||
break
|
break
|
||||||
|
|
|
@ -4,5 +4,5 @@
|
||||||
major = 1 # VERSION_MAJOR_IDENTIFIER
|
major = 1 # VERSION_MAJOR_IDENTIFIER
|
||||||
minor = 112 # VERSION_MINOR_IDENTIFIER
|
minor = 112 # VERSION_MINOR_IDENTIFIER
|
||||||
# VERSION_LAST_MM 1.112
|
# VERSION_LAST_MM 1.112
|
||||||
patch = 1 # VERSION_PATCH_IDENTIFIER
|
patch = 2 # VERSION_PATCH_IDENTIFIER
|
||||||
str = ".".join(str(v) for v in (major, minor, patch))
|
str = ".".join(str(v) for v in (major, minor, patch))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue