FFMPEG mkv to mp4 conversion loses subtitles

36,475

Solution 1

MP4 does not support SRT. You can either use softsubs or hardsubs.

softsubs

Subtitles that consist as a separate stream in the file. They can be toggled on/off by the player, and do not require the video stream to be re-encoded.

ffmpeg -i input.mkv -c copy -c:s mov_text output.mp4

Player support for timed text softsubs in MP4 can be rather poor. You'll just have to try it.

hardsubs

Hardsubs are "burned" into the video so the video must be re-encoded.

ffmpeg -i input.mkv -vf subtitles=input.mkv output.mp4

See the susbtitles filter documentation for more info such as how to select a particular subtitle stream if there is more than one.

Solution 2

I had a similar problem going from MP4 to MKV from some mp4 files I ripped with Handbrake. I first consulted https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/subtitle_options, which implied particular subtitle formats for mkv vs mp4. After playing around with ass and mov_text conversions that didn't work, I tested some files and noticed the dvd_subtitle format appearing. After a lot of playing around the following worked.

ffmpeg -i "\\server\directory\Sourcefile.mp4" -c:v copy -c:a copy -c:s dvd_subtitle "\\server\directory\Outputfile.mkv"

Hope it helps.

Share:
36,475

Related videos on Youtube

dpkmon
Author by

dpkmon

Updated on September 18, 2022

Comments

  • dpkmon
    dpkmon almost 2 years

    Currently trying to convert my mkv library to mp4 (Iphone 6 plus)

    I've managed to get to mkv to mp4 conversion correctly, but I'm missing the subtitles part (SRT)

    Here's my code:

    dir/b/s *.mkv >mkvlist.txt   ///////// this gets a list of all the mkv files on the directory
    
    for /F "delims=;" %%F in (mkvlist.txt) do ffmpeg.exe  -i "%%F" -format mp4 -vcodec copy -acodec aac -strict -2 -sn "%%~dF%%~pF%%~nF.mp4"   ///////////// this makes the conversion
    
    del mkvlist.txt     ////// this deletes the txt file
    

    I would like to include subtitles into the scrip, but I´m having trouble inserting the correct name for the subtitles into the script (since this is a multiple conversion batch).

    • Admin
      Admin about 9 years
      .mkv files are a container format. Its very likely that the mkv file contains an .srt file that you can extract. Make sure it has the same name as the .mp4 file and it should work. The mkv file might actually also contain an mp4 file but can also have an .divx, .avi or any other video format.
  • dpkmon
    dpkmon about 9 years
    Could you help me better understand my code? Where and why would you add the re-encoding for the subs? (And if you can think of a solution or way to batch convert all the files in the subfolders with their corresponding subs?) (if there are no subtitles, then it would need to skip the file altogether and move on to the next one.