ffmpeg: Infinite length output when overlaying subtitles onto black image

Viewed 338

I'm trying to do some analysis of image-based subtitles by outputting them as a sequence of PNGs to a pipe. My command line looks like this:

ffmpeg -y -i $INPUTFILE -f lavfi -i color=c=black:s=1920x1080 -filter_complex "[1:v][0:s:5]overlay[v]" -shortest -map "[v]" -c:v png -f image2pipe - | pike subspng.pike

In theory, -shortest should mean that the stream stops at the shortest input, which would be roughly seven minutes of input file. Instead, my script receives an infinite sequence of black frames after the last frame of subtitles, until I send FFMPEG a SIGINT. Placing -shortest before -filter_complex has the same effect.

Is there a different way to force the filtering to stop at the end of the input file?

EDIT: Using the shortest=1 flag on the overlay filter also doesn't help, even in combination with -shortest.

2 Answers

Use the shortest option in the overlay filter:

shortest
If set to 1, force the output to terminate when the shortest input terminates. Default value is 0.

ffmpeg -y -i $INPUTFILE -f lavfi -i color=c=black:s=1920x1080 -filter_complex "[1:v][0:s:5]overlay=shortest=1[v]" -map "[v]" -c:v png -f image2pipe - | pike subspng.pike

Building on the suggestions from both llogan and Gyan, here's what I came up with:

ffmpeg -y -i $INPUTFILE -filter_complex "[0:v]drawbox=c=black:t=fill[black]; [black][0:s:5]overlay=shortest=1[v]" -map "[v]" -c:v png -f image2pipe - | pike subspng.pike

Instead of creating an infinite-length source of black frames, this instead takes the original video stream, then covers the entire thing with a black box. NOTE: May require a newish version of FFMPEG for the drawbox filter.

Related