Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to extract SubRip (SRT) subtitles from an MP4 video with ffmpeg?

I have checked the FFMpeg documentation and many forums and figured out the correct command-line to extract subtitles from an .MP4 video should look like so:

ffmpeg -i video.mp4 -vn -an -codec:s:0 srt out.srt

However, I get the following error, which lends me to question whether this is feasible at all:

Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Using ffmpeg -codecs, I can confirm that ffmpeg should be able to encode subrip subtitles.

Using ffmpeg -i video.mp4, I can see that there is two subtitle tracks embedded in the video :

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
...
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 720x572 [SAR 64:45 DAR 256:143], 1341 kb/s, 25 fps, 25 tbr, 90k tbn, 180k tbc
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 191 kb/s
Stream #0:2(fra): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 191 kb/s
Stream #0:3(eng): Subtitle: dvd_subtitle (mp4s / 0x7334706D)
Stream #0:4(und): Subtitle: mov_text (text / 0x74786574)

EDIT

I have tested with the simplified command-line shown in the comments but I still get the same error. Here is a link to the detailed verbose output from running the command. I have also tried to completely disable metadata and chapters in the resulting output but that still produces the same error.

like image 639
Maxime Labelle Avatar asked Dec 19 '13 08:12

Maxime Labelle


People also ask

Can you extract SRT from MP4?

Click the "Add Video" button to add an MP4 file and then select SRT (SubRip Text) as an output subtitle format. Step 3. Select the output path and click the "Extract Subtitles" button to extract SRT from MP4. After completing those steps above, the subtitle is extracted from the video.

Can we extract subtitles from MP4 using VLC?

The following are the steps to extract subtitles from MP4 VLC. Step 1: Open VLC preferences and hit the All button at the bottom. Select Video > Subtitles/OSD and then uncheck the "Autodetect subtitle files" option. Enable the sub-picture and on-screen display.


2 Answers

I enventually figured out why I did not succeed:

The specified command-line would have been perfectly fine if the subtitles from the source video were encoded in a text-based representation. However, as can be seen in the output to the ffmpeg -i command-line, the subtitles are encoded in the "dvd_subtitle" format.

The dvd_subtitle format stores bitmaps for each subtitle in the video. Therefore, there is no way ffmpeg would be able to translate the bitmaps into text.

For this task, one has to resort to an OCR-based software which assists a user with the task of identifying each subtitle as text from its bitmap représentation.

(There is a secondary text-based subtitle in the source video, but I don't know where it came from and is not seen by most popular players. For all intents and purposes, this "mov_text" subtitle seems to be a stub placeholder, probably an artifact of the conversion from the original DVD)

like image 118
Maxime Labelle Avatar answered Sep 22 '22 23:09

Maxime Labelle


Try using map option... if there are too many streams in input files....

Syntax would be:

ffmpeg -i video.mp4 -map 0:4 out.srt

Since there are two subtitle streams in your video, first on 0:3 which is dvdsubtitle so cannot be converted to srt so we will convert second subtitle on 0:4 stream which is mov_text and is soft copy of subtitle so can be easily converted....

like image 30
Manthaar Janyaro Avatar answered Sep 23 '22 23:09

Manthaar Janyaro