Home > Blockchain >  ffmpeg: video from images - handling a zero length image file
ffmpeg: video from images - handling a zero length image file

Time:09-30

I have a shell script which uses ffmpeg to crate a time-lapse video from webcam images. Normally, it works just fine:

/usr/bin/ffmpeg -loglevel info  -framerate 4 \
     -pattern_type glob -i $ipath/'*.jpg' \
    -c:v libx264 -crf 30 -y -pix_fmt yuv420p $temp &>>$log

But this chokes if the image is a zero-length file:

-rw-r--r-- 1 pi pi  156636 Sep 29 04:35 image_022.jpg
-rw-r--r-- 1 pi pi  156533 Sep 29 04:35 image_023.jpg
-rw-r--r-- 1 pi pi  159302 Sep 29 04:35 image_024.jpg
-rw-r--r-- 1 pi pi       0 Sep 29 04:35 image_025.jpg
-rw-r--r-- 1 pi pi  157055 Sep 29 04:35 image_026.jpg
-rw-r--r-- 1 pi pi  156851 Sep 29 04:35 image_027.jpg
-rw-r--r-- 1 pi pi  155793 Sep 29 04:35 image_028.jpg
-rw-r--r-- 1 pi pi  160647 Sep 29 04:35 image_029.jpg

In this case the video only included frames up to the zero length JPEG.

I realize I can test the file length of every webcam image, but there must be an easier, more efficient way.

Is there?

CodePudding user response:

FFmpeg will terminate reading an image sequence upon encountering a file with zero size. There's no option to carry on.

Copy over the previous image onto the zero-sized file.

  • Related