'how can i stop ffmpeg when no new frame come to /dev/video0

I am now modifying stream from camera with our program(programA) and output as .ts files like below.

camera => programA => /dev/video0 => ffmpeg => .ts files

When camera stopped, programA stop automatically and no new frame arrive to /dev/video0. I want ffmpeg stop automatically in such situation. What ffmpeg option should I use? Currently I'm using option below, but ffmpeg doesn't stop.

ffmpeg -f video4linux2 -i /dev/video0 -vsync vfr -f hls -c:v h264_nvenc out.m3u8

Edited:
I tried to invalidate /dev/video0 but it failed like below.

# modprobe -r v4l2loopback
modprobe: FATAL: Module v4l2loopback is in use.

After I stopped programA and ffmpeg, the command success.
ProgramA is kicked by systemd service and restart automatically when it stopped.
ffmpeg is kicked by programB, but programB doesn't control programA.
But it sounds like good idea to inform B so B can kill ffmpeg.
I'll try that way. Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source