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

拥有回忆 提交于 2020-01-02 01:07:53

问题


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.


回答1:


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)




回答2:


Just FYI, (Can't comment due to rep yet), but extracting SRT from an MP4 will result in a file formatted as MOV_Text not the regular SRT. It will still get added and work but its like changing mp4 to m4v. While it usually works, things don't work the same in the code. Mov_text is horrible for manually adjusting font/size etc etc. Best bet is to download and test an SRT from the web!

This will work, but will result in mov_text coded srt file:

ffmpeg -i in.mp4 out.srt



回答3:


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....



来源:https://stackoverflow.com/questions/20676906/is-it-possible-to-extract-subrip-srt-subtitles-from-an-mp4-video-with-ffmpeg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!