45

I am trying to extract subtitle from video as .srt file, I used the following command:

FFMPEG -i mytestmovie.mkv -vn -an -codec:s:0.1 srt sub.srt

But, I got an error as Unrecognized option codec:s:0:1 So, can you tell me the exact command and how to extract a subtitle as .srt file in video?

  • umair:shall u tell me in command prompt – vijay Apr 16 '13 at 8:11
  • I have the same problem. Did you get this to eventually work? – Maxime Labelle Dec 19 '13 at 8:23
77

Simple:

ffmpeg -i Movie.mkv -map 0:s:0 subs.srt
  • -i: Input file URL/path.
  • -map: Designate one or more input streams as a source for the output file.
  • s:0: Select the subtitle stream.
| improve this answer | |
  • 3
    This worked for me with a MP4 file with embedded subtitles. – Rubens Mariuzzo Sep 18 '16 at 17:21
  • 13
    This would download the first subtitle track. If there are several, use 0:s:1 to download the second one, 0:s:2 to download the third one, and so on. – Fabien Snauwaert Nov 10 '16 at 19:06
  • 5
    @jm3 Would you happen to know any way to automatically extract all subtitle streams from a file, naming them after their language identifier (e.g. eng, fre, dut etc.)? – Fr. Dec 1 '17 at 0:30
  • 1
    why is it so slow when extracting from big MKV container (~4 gb)? – user25 Jun 2 '18 at 16:24
  • 2
    To extract more subtitles at once you have to duplicate the -map parameters for each file. Also include -c copy so that it just extracts the file without trying to process it: ffmpeg -i Movie.mkv -c copy -map 0:s:0 subs.01.srt -c copy -map 0:s:1 subs.02.srt. Anyway it will take long time because ffmpeg must read whole video file to find all parts of the subtitle streams. – Radek Pech Apr 20 '19 at 8:39
10

-codec:s:0:1 is incorrect. If you use -codec:s:0 then ffmpeg will use the stated codec for the first subtitle stream being passed to the output, if you use -codec:s:1 then it will use it for the second subtitle stream, etc.

You can also use -codec:s to select all output subtitle streams, or -codec:2 to select the third output stream, regardless of what it is.

You are probably confused because the -map option behaves in a different way - there, you have to select which input the selected stream comes from. (so, -map 0:s:0 would take the first subtitle stream from the first input, and feed it to the output). However, -map is for selecting which streams you want to take from the inputs; whereas most of the other options that use stream mapping are for use on the streams after they have been selected (so there's no need to specify which input file they're from), as they are passed to the output.

| improve this answer | |
  • evilsoup:i would using the following command E:\FFMpeg_Latest>ffmpeg -i E:\Routine\routine.mkv -vn -an -map 0:s:0 srt E:\Routine\sub.srt,it seems an error i got Unable to find a suitable output format for 'srt',can u tell me the command for extracting an subtitle in video... – vijay Apr 16 '13 at 9:38
  • 2
    Try: ffmpeg -i E:\Routine\routine.mkv -map 0:s:0 E:\Routine\sub.srt (ffmpeg should detect that you want srt subtitles from the output file name) – evilsoup Apr 16 '13 at 14:31
  • I used: ffmpeg -i film.mp4 -vn -an -codec:s srt film.srt that should copy all the subtitles to the srt file. – Stuart Apr 5 '16 at 19:05
  • @Stuart it doesn't extract all subtitles – user25 Jun 2 '18 at 17:28
  • 1
    @evilsoup -codec:s is equal to -codec:s:0 so it doesn't select all subtitles... it will extract first text track – user25 Jun 2 '18 at 18:15
2
ffmpeg -i video.mkv subs.srt

Wicked, right?

Worked for me just now, for a bunch of MKVs containing a single SRT stream. Apparently this is the default behavior. My ffmpeg version is 20170516, from ubuntu 16.4

| improve this answer | |
0

Batch file. Copy this code to new .bat file.

Just drop .mkv file on it to get a .srt subtitle file.

Among all other things, I made an asynchronous call of msgBox. Who needs it - copy it to your sources.

For some reason, it can doesn't accept parentheses () in file names. I did not check the rest of the characters.

    @echo off
    :: Your language code
    :: chcp 866 
    if "%~x1"==".mkv" (
        set mkv=%~n1
        set path=%~d1%~p1
    )
    if "%~x2"==".mkv" (
        set mkv=%~n2
        set path=%~d1%~p1
    )
    if not "%mkv%"=="" (
            :: If your original ffmpeg.exe file located in system32 directory then replace "%~dp0ffmpeg.exe" to ffmpeg
            "%~dp0ffmpeg.exe" -i "%path%%mkv%.mkv" -map 0:s:0 "%path%%mkv%.srt"
            call :msgbox "File %path%%mkv%.srt completed."
    ) else call :msgbox "File .mkv missing in the input parameters`r`nJust drop file with extensions:`r`n.mkv to this batch file to get subtitle file .srt"
    goto :eof
    
    :msgBox [msgText]
    C:\Windows\System32\mshta.exe vbscript:Execute("CreateObject(""WScript.Shell"").Run ""powershell -Command """"[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')|Out-Null;"""" """"[System.Windows.Forms.MessageBox]::Show(\""""%~1\"""")"""""",0,false:close")
    exit /B
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.