Skip to content

Commit

Permalink
Prolong timeout for ffmpeg termination.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tage Johansson committed Mar 28, 2024
1 parent 6b196ba commit 9f9fe20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions chess_cli/record.py
Expand Up @@ -45,7 +45,7 @@

FRAMES_PER_BUFFER: int = 8192
ERROR_REGEX: re.Pattern = re.compile("error", flags=re.IGNORECASE)
PROCESS_TERMINATE_TIMEOUT: float = 3.0 # Timeout for a process to terminate before killing it.
PROCESS_TERMINATE_TIMEOUT: float = 20.0 # Timeout for a process to terminate before killing it.


def _find_ffmpeg_exe() -> list[bytes] | None:
Expand Down Expand Up @@ -214,7 +214,7 @@ def set_mark(self, comment: str | None = None) -> None:
assert len(self.boards) > 0
self.marks.append((len(self.boards) - 1, comment))

async def stop(self) -> float:
async def stop(self, timeout: float | None = None) -> float:
"""Stop the recording.
No pause/resumes can take place after this. Returns the length of the recording
Expand All @@ -235,7 +235,7 @@ async def stop(self) -> float:
print("Terminating FFMpeg.")
self.ffmpeg_process.terminate()
try:
await asyncio.wait_for(self.ffmpeg_process.wait(), PROCESS_TERMINATE_TIMEOUT)
await asyncio.wait_for(self.ffmpeg_process.wait(), timeout)
except TimeoutError:
print("Warning: ffmpeg did not listen to SIGTERM so we have to kill it.")
self.ffmpeg_process.kill()
Expand Down Expand Up @@ -497,13 +497,14 @@ async def save_recording(
marks_file: PurePath | None = None,
override_output_file: bool = False,
no_cleanup: bool = False,
timeout: float | None = None,
) -> float:
"""Stop and save the recording.
Returns the length of the recording in seconds.
"""
assert self.recording is not None
duration = await self.recording.stop()
duration = await self.recording.stop(timeout=timeout)
await self.recording.save(
output_file=output_file.with_suffix(".mp4"),
marks_file=m.with_suffix(".txt") if (m := marks_file) is not None else None,
Expand Down
2 changes: 2 additions & 0 deletions chess_cli/record_cmds.py
Expand Up @@ -40,6 +40,7 @@ class RecordCmds(Record):
action="store_true",
help="Don't remove any created temporary files. Mostly useful for debugging.",
)
record_save_argparser.add_argument("--timeout", type=float, help="A timeout for stopping ffmpeg.")
record_subcmds.add_parser("delete", help="Delete the ongoing recording.")
record_mark_argparser = record_subcmds.add_parser(
"mark", help="Mark the current position so that its timestamp can be remembered."
Expand Down Expand Up @@ -92,6 +93,7 @@ async def do_record(self, args) -> None:
marks_file=args.marks_file,
override_output_file=args.override,
no_cleanup=args.no_cleanup,
timeout=args.timeout,
)
print(f"Recording successfully saved to {args.output_file}")
print(f"It was {show_time(duration)} long.")
Expand Down

0 comments on commit 9f9fe20

Please sign in to comment.