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,390
  • 26
  • 45
  • 52
Advika
  • 111
  • 2
  • Thanks for reply. The link which you shared here talks about burning subtitle into video. But in our scenario , subtitles needs to be render as separate stream not embedded with video. Any input on this would be helpful. – Advika Jul 14 '17 at 10:23
  • That is correct. DASH uses text based subtitle. But our current project environment has support for bitmap format rendering. So we thought will convert the text based to bitmap format and then same pipeline can be used for rendering. – Advika Jul 14 '17 at 11:29
  • As I am totally new to this so sorry for not providing the sufficient information. BMP format with 24 bits per pixel. LIke for example we have text string "XYZ" as input and output should be in the BMP format. – Advika Jul 17 '17 at 05:33
  • we need one bitmap(.bmp) file for each distinct subtitle text string. – Advika Jul 17 '17 at 10:07

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
  • 223,558
  • 70
  • 607
  • 592