Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting subtitles from mp4

I got an assignment of retrieving subtitles from a mp4 file

I want to know how to do this, by java or c++, does it depends on mp4 encoding format and

I want to know the basic concepts of different video formats and basic concepts of video processing.

like image 228
vector Avatar asked Jun 30 '13 07:06

vector


3 Answers

there is several subtitle format, SRT, STL(mainly use by Apple), etc.... and ffmpeg support a lot of them http://ffmpeg.org/general.html#Subtitle-Formats

and ffmpeg can extract them with cmd line the following sequence of command:

1) perform track identification

ffmpeg -i yourFile

2) extract the subtitle track with

ffmpeg -i yourFile -vn -an -codec:s:X.Y srt 
sub.srt

with X.Y the track number indicator you found from the cmd (1) .

like image 75
alexbuisson Avatar answered Oct 09 '22 03:10

alexbuisson


Neither of the other answers here worked for me with an m.m4v containing multiple subtitles. But the following did work (with both .m4v and .mp4 files):

ffmpeg -i m.m4v -map 0:s:0 eng.srt
ffmpeg -i m.m4v -map 0:s:1 ita.srt
ffmpeg -i m.m4v -map 0:s:2 fre.srt

In my m.m4v are 3 subtitle streams with English being the first, Italian the second, French the third. It appears to be the order that's used for the ffmpeg command rather than the X.Y (input.stream) values one obtains with ffmpeg -i m.m4v

which for my m.m4v gave:

Stream #0:2(eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
Metadata:
  handler_name    : SubtitleHandler
Stream #0:3(ita): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s
Metadata:
  handler_name    : SubtitleHandler
Stream #0:4(fre): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s
Metadata:
  handler_name    : SubtitleHandler

I'm using Mac OS 10.4.5 on a Macbook Pro 2015

By the way, if there's only one subtitle track then you would use:

ffmpeg -i m.m4v -map 0:s:0 sub.srt
like image 41
Tony M Avatar answered Oct 09 '22 02:10

Tony M


ffmpeg -i yourFile -map X:Y srt sub.srt

extract only needed track

like image 34
zulkris Avatar answered Oct 09 '22 02:10

zulkris