[FFmpeg-user] How to check if a youtube URL is valid before starting download?

Bo Berglund bo.berglund at gmail.com
Fri Jul 9 20:12:02 EEST 2021

On Fri, 09 Jul 2021 13:00:39 +0200, Bo Berglund <bo.berglund at gmail.com> wrote:

>Final problem is how to run ffmpeg with an input that is a live stream currently
>playing on Youtube?
>I need to detect (in a script) if the stream has frozen before I start the
>download, so my plan is to run the detection and then start the download only if
>it reports that the stream is not frozen.

To simplify things I decided to use youtube-dl inside the script to download
15-20 s of the stream to a video file:

timeout --signal=2 20s youtube-dl -f 94 -o $TESTFILE $VIDEOURL

Then if this succeeds it would apply the ffmpeg command shown earlier to the
testfile to determine if it contains a frozen video:

FFREPORT=file=ffreport.log:level=32 ffmpeg -hide_banner -t 15  -i $TESTFILE -vf
"freezedetect=n=0.01:d=5" -map 0:v:0 -f null -

And finally the grep to check if it had a positive:

grep "lavfi.freezedetect.freeze_start: " ffreport.log
if [ $? -eq "0" ]
  echo "Video frozen"
  exit 1
  echo "Video streaming OK"
  exit 0

This way I don't have to mess with making ffmpeg read the live stream directly.

Bo Berglund
Developer in Sweden

More information about the ffmpeg-user mailing list