ffmpeg: extract subtitles from mp4 files, when subtitles are embedded as binary data stream

123 Views Asked by At

What I am trying to do is to extract subtitles which are embedded in a .mp4 file. Goal is to have the .mp4 file and the subtitles uploaded together on HTML5. What I would normally do is looking for the subtitles stream with ffprobe then do something along (assuming stream 2 is the subtitle stream)

ffmpeg -i input.mp4 -map:0:2 out.vtt

Now I have this file where, applying the command above, the following error is generated

Exactly one WebVTT stream is needed.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --

I have tried a similar solution

ffmpeg -i input.mp4 -vn -an -codec:s:0.2 srt sub.srt

without success:

Output file #0 does not contain any stream

It turns out the subtitles stream is some binary data which I would have to decode somehow (I was also able to dump the binary content of it to no further use)

Stream #0:2(eng): Data: bin_data (text / 0x74786574)
    Metadata:
      handler_name    : SubtitleHandler

Any idea about a solution, or at least a way around it?

1

There are 1 best solutions below

1
Ricardo Bohner On

Use the copy codec:

ffmpeg -i input.mkv -map 0:s:2 -c copy subtitle.srt