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.
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) .
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
ffmpeg -i yourFile -map X:Y srt sub.srt
extract only needed track
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With