[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix some av type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Nov 29, 2023
1 parent 2b97ec3 commit 057fbb2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
18 changes: 15 additions & 3 deletions auto_editor/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ def media_length(self) -> int:
self.log.error("Could not get media duration")

video = cn.streams.video[0]
dur = int(video.duration * video.time_base * self.tb)

if video.duration is None or video.time_base is None:
dur = 0
else:
dur = int(video.duration * video.time_base * self.tb)
self.log.debug(f"Video duration: {dur}")

return dur
Expand Down Expand Up @@ -371,7 +375,11 @@ def motion(self, s: int, blur: int, width: int) -> NDArray[np.float_]:
stream = container.streams.video[s]
stream.thread_type = "AUTO"

if stream.duration is None:
if (
stream.duration is None
or stream.time_base is None
or stream.average_rate is None
):
inaccurate_dur = 1
else:
inaccurate_dur = int(
Expand Down Expand Up @@ -445,7 +453,11 @@ def pixeldiff(self, s: int) -> NDArray[np.uint64]:
stream = container.streams.video[s]
stream.thread_type = "AUTO"

if stream.duration is None:
if (
stream.duration is None
or stream.time_base is None
or stream.average_rate is None
):
inaccurate_dur = 1
else:
inaccurate_dur = int(
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def edit_media(
if os.path.isdir(output):
log.error("Output path already has an existing directory!")

if os.path.isfile(output) and src is not None and src.path != output:
if os.path.isfile(output) and src is not None and src.path != output: # type: ignore
log.debug(f"Removing already existing file: {output}")
os.remove(output)

Expand Down
6 changes: 3 additions & 3 deletions auto_editor/ffwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class VideoStream:
fps: Fraction
duration: float
sar: Fraction
time_base: Fraction
time_base: Fraction | None
pix_fmt: str | None
color_range: str | None
color_space: str | None
Expand Down Expand Up @@ -266,13 +266,13 @@ def initFileInfo(path: str, ffmpeg: FFmpeg, log: Log, label: str = "") -> FileIn

for a in cont.streams.audio:
adur = 0.0
if hasattr(a, "duration") and a.duration is not None:
if a.duration is not None and a.time_base is not None:
adur = float(a.duration * a.time_base)

audios += (
AudioStream(
a.codec_context.name,
a.sample_rate,
0 if a.sample_rate is None else a.sample_rate,
a.channels,
adur,
0 if a.bit_rate is None else a.bit_rate,
Expand Down

0 comments on commit 057fbb2

Please sign in to comment.