help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: record stream using time limit, reconnecting as needed


From: Koichi Murase
Subject: Re: record stream using time limit, reconnecting as needed
Date: Wed, 22 Feb 2023 16:21:14 +0900

2023年2月22日(水) 12:52 Roger <rogerx.oss@gmail.com>:
> However, I'm still stumped for how to background an endless loop with the
> included ffmpeg stream recording, so the stream is easily reconnected if
> dropped, while falling through to get the PID of the backgrounded endless loop
> or ffmpeg, for killing after so many (eg 30) minutes?

If you specify a negative integer (e.g. -<PGID> where <PGID> is an
integer) to `kill', `kill' will kill all the processes that belong to
the process group PGID. You can give a distinct process group ID to
the background while loop by specifying `set -m' before starting the
background job. Then you can pass the PGID (i.e., the PID of the
`while' loop) to `kill' to kill all the processes including ffmpeg. In
this way, you do not need to directly specify the PID of ffmpeg. This
is an example.

#!/usr/bin/env bash

record() {
  local -
  set -m
  while true; do
    ffmpeg http://some.url.m3u8
  done & pgid_task="${!}"
}

sleep_while_recording() { sleep 30m; }

record
sleep_while_recording
kill -INT -"$pgid_task"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]