[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: record stream using time limit, reconnecting as needed
From: |
Roger |
Subject: |
Re: record stream using time limit, reconnecting as needed |
Date: |
Thu, 23 Feb 2023 01:06:49 -0500 |
> On Wed, Feb 22, 2023 at 04:21:14PM +0900, Koichi Murase wrote:
>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"
I worked on this for awhile and found the following was required for killing a
PGID/process group:
kill -- -$(ps -o pgid=$pgid_task | grep [0-9] | tr -d ' ')
Cannot remember the reason why "kill -- -$pgid_task" was not working, something
about the variable not reliable passing back a list of PIDs, as such, ps -o was
required, along with ensuring no white space was included.
Frankly, kill prints a really ugly non-zero return upon script exit.
I'm not seeing a signal emulating a safe return 0 exit, likely for good reason.
Although this method is likely far more reliable, as long as a file number
suffix is incremented upon each loop for preventing file over-writing, later
concating the files as needed; thinking of now trying the ffmpeg -reconnect
method.
Think I also had to globally declare (eg. "declare -g pgid_task") pgid_task
also.
signature.asc
Description: PGP signature
- record stream using time limit, reconnecting as needed, Roger, 2023/02/21
- Re: record stream using time limit, reconnecting as needed, Roger, 2023/02/21
- Re: record stream using time limit, reconnecting as needed, Roger, 2023/02/21
- Re: record stream using time limit, reconnecting as needed, alex xmb ratchev, 2023/02/22
- Re: record stream using time limit, reconnecting as needed, Koichi Murase, 2023/02/22
- Re: record stream using time limit, reconnecting as needed, Koichi Murase, 2023/02/22
- Re: record stream using time limit, reconnecting as needed, Roger, 2023/02/22
- Re: record stream using time limit, reconnecting as needed, Koichi Murase, 2023/02/22
- Re: record stream using time limit, reconnecting as needed, Roger, 2023/02/22
- Re: record stream using time limit, reconnecting as needed,
Roger <=
- Re: record stream using time limit, reconnecting as needed, Roger, 2023/02/23
- Re: record stream using time limit, reconnecting as needed, Greg Wooledge, 2023/02/23
- Re: record stream using time limit, reconnecting as needed, Roger, 2023/02/24