1

We have a text-based subtitle stream, and we need to convert each distinct subtitle in that subtitle stream to an individual .bmp file, with 24 Bits per pixel.

How can we do that with ffmpeg?

karel
  • 13,706
Advika
  • 111

1 Answers1

1

A little hacky, but this is the best I came up with, also given the rather ambiguous task, where it isn't clear what the output frame size should be, or how the timing should be guaranteed.

ffmpeg -f lavfi -i "color=color=black:d=10:s=1280x720:r=24" \
-filter:v "subtitles=sample.srt,mpdecimate,setpts=N/FRAME_RATE/TB" \
images/out-%04d.bmp

Here's what this does:

  • Create black background color with a size of 1280×720px, 10 seconds duration, and 24 frames per second. You can change the pixel size, obviously, and you have to change the duration based on the overall duration of the subtitle stream. The framerate can be lowered, but this affects the precision of the rendered output.
  • Render the subtitles using the subtitles filter (see its options for defining the subtitle style).
  • Drop duplicate frames with mpdecimate, and reset the time base. This can be left out if you do not want only distinct images to be output.
  • Output each remaining frame to a BMP image, sequentially ordered.

Now, in case there are parts without subtitles, this will output an empty black frame—these will have to be removed later on, e.g. based on a file checksum.

slhck
  • 235,242