I have the following setup:
- Tvheadend 4.3-2009, installed from the PPA
- Ubuntu 18.04 (and Ubuntu 20.04)
- Multiple DVB-C tuner makes
I need to burn in subtitles on the video, and do hardware transcoding. Sadly this leaves me with requirement of spawning <code>ffmpeg</code> to handle my transcoding needs.
Due to various issues, sometimes a channel will go offline at the source, because the providers in my area are just crappy.
I have around 3 profiles that I use right now, each one doing it's own thing, setup like this:
https://i.imgur.com/yk402Wx.png
The bash script I use is:
#!/bin/bash
if read -t 2 -n 1; then
/usr/local/bin/v_ffmpeg -threads 1 -v fatal -nostats -vsync 1 -async 1 \
-init_hw_device cuda=cuda -filter_hw_device cuda -extra_hw_frames 3 -reinit_filter 1 -hwaccel nvdec -hwaccel_output_format cuda -filter_threads 2 -filter_complex_threads 2 \
-i - -filter_complex "[0:s] scale=w=1920:h=1080 [sub]; [0:v] hwdownload [video]; [video][sub] overlay,format=nv12,hwupload=derive_device=cuda [v]" \
-map "[v]" -map 0:a \
-c:v h264_nvenc -preset medium -b:v 5M -bufsize 10M -profile:v main -temporal-aq 1 \
-acodec copy -copy_unknown \
-f mpegts -
else
exit 1
fi
The issue I'm facing is that sometimes, when a channel is offline (no signal from dvb-c), the ffmpeg process WILL spawn, but it will hang indefinitely wait because there is no input from the stdin pipe. For some reasons,tvheadend will not kill the ffmpeg child. But because the hardware is initialized, this ends up using around 76MB VRAM. During half a day, this will obviously end up using all my available VRAM, even tough the processes don't really do anything but wait for input.
To try to get around the issue of no input, I have added the <code>read -t 2 -n 1</code> block. In my limited testing this SHOULD timeout if there's no input from stdin, and then obviously exit the script. Sadly, this does not seem to happen, so after around 12 hours, I end up with something like this:
├─tvheadend─┬─1567*[hd-5m.sh]
│ ├─10*[hd-5m.sh───z_ffmpeg───22*[{z_ffmpeg}]]
│ ├─8*[sd-sub-0.sh───z_ffmpeg───21*[{z_ffmpeg}]]
│ ├─5*[sub-burn-0.sh]
│ ├─3*[sub-burn-0.sh───v_ffmpeg───4*[{v_ffmpeg}]]
│ └─231*[{tvheadend}]
So the question I'm asking is:how exactly can I prevent this behaviour and make tvheadend kill the orphaned ffmpeg children ?
I have tried:
- swapping the "Kill Signal" (SIGKILL, SIGTERM), there was no difference
- reducing/increasing the "Kill Timeout", there was no difference
- changing the data timeout, there was no difference
Stracing the script and/or the ffmpeg process reveals it doing nothing but waiting:
root@nxt1:/opt# strace -p 2475
strace: Process 2475 attached
read(0,