I have a bash script that is called by a phone system that gets some audio from a URL and (using ffmpeg, mplayer etc.) then pipes it back to the application. The file can have several URL's that are called so if the first one say goes off line or gives a 404 it will go to the next line.
I have an issue where some times the server will produce content however there is no audio. In such a case I want to kill the current PID of ffmpeg, mplayer etc. so that the script should move on.
I can't foreground it and get the last PID since once it's ran in the foreground the media is no longer being piped to the application calling it. I can't use exec in the beginning since if I then issue a kill to the PID the script dies which I don't want.
The script looks something like this:
#!/bin/bash
/usr/bin/ffmpeg -i 'http://1.1.1.1/soft_music' -vn -ar 8000 -ac 1 -f s16le -
/usr/bin/ffmpeg -i 'http://2.2.2.2/soft_music' -vn -ar 8000 -ac 1 -f s16le -
I assume I need to add something that will allow me to log the pid of the current ffmpeg command running so my external script can get it and kill it. Once that's done it will go to the next line and try the next stream from 2.2.2.2