Reputation: 503
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.
Upvotes: 11
Views: 25584
Reputation: 1
updated the code to v5 ver.
work pretty good.
usage:
ffmpegSubExtract mp4 srt
ffmpegSubExtract mp4 srt 1
@echo off
cls
if "%1"=="" (
echo.
echo Usage:
echo ffmpegSubExtract mp4 srt
echo ffmpegSubExtract mp4 srt 1
goto :eof )
if "%2"=="" (
echo.
echo Usage:
echo ffmpegSubExtract mp4 srt
echo ffmpegSubExtract mp4 srt 1
goto :eof )
set fle=%1
set ext=%2
set str=%3
for %%i in ("*.%fle%") do (set fname=%%i) & call :rename
goto :eof
:rename
if exist "%fname:~0,-4%.%ext%" (
del "%fname:~0,-4%.%ext%" )
if "%str%"=="" (
set str=0 )
if "%ext%" == "srt" (
ffmpeg -i "%fname%" -map 0:s:%str% "%fname:~0,-4%.%ext%"
) else (
ffmpeg -i "%fname%" -c copy -map 0:s:%str% "%fname:~0,-4%.%ext%"
)
goto :eof
rem come code from here
rem https://stackoverflow.com/questions/17388253/extracting-subtitles-from-mp4
rem https://superuser.com/questions/583393/how-to-extract-subtitle-from-video-using-ffmpeg
Upvotes: 0
Reputation: 1762
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
Upvotes: 12
Reputation: 8469
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) .
Upvotes: 14