1

I would like to know how to convert an mkv file with several subtitle and audio tracks into an mp4 with one of the subtitle tracks hardcoded and a single audio track selected using ffmpeg? It should be a single command without resorting to extract the tracks from the original mkv (if possible).

What I tried so far: ffmpeg -i File.mkv -map 0:s:1 -map 0:v -map 0:a:1 -c:a aac -c:v copy output.mp4 but the subtitle is not being hardcoded into the file, just muxed into the mp4 container, if that is possible (maybe the file is just ending up with the mp4 extension but it's still an mkv).

ffmpeg -i File.mkv
Input #0, matroska,webm, from 'File.mkv':
  Metadata:
    encoder         : libebml v1.2.1 + libmatroska v1.1.1
    creation_time   : 2018-08-11T22:02:55.000000Z
  Duration: 00:24:57.22, start: 0.000000, bitrate: 2271 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 640x480 [SAR 1:1 DAR 4:3], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Metadata:
      title           : A Day in Ichinoseki
    Stream #0:1(eng): Audio: aac (LC), 48000 Hz, 5.1, fltp (default)
    Metadata:
      title           : English
    Stream #0:2(jpn): Audio: aac (LC), 48000 Hz, stereo, fltp
    Metadata:
      title           : Japanese
    Stream #0:3(eng): Subtitle: ass (default)
    Metadata:
      title           : English (Translation Only)
    Stream #0:4(eng): Subtitle: ass
    Metadata:
      title           : English
    Stream #0:5: Attachment: ttf
    Metadata:
      filename        : OpenSans-Semibold_0.ttf
      mimetype        : application/x-truetype-font
At least one output file must be specified

PS: I used to know of a command that used to get me a simple summary of an mkv streams that could be used verbatim with ffmpeg commands but forgot it.

4
  • 1
    ffmpeg -i video.mkv -vf subtitles=video.mkv:si=1 out.mp4 where si is subtilte stream id?
    – konradmb
    Commented May 22, 2020 at 16:13
  • @konradmb nope, nada. Commented May 22, 2020 at 17:22
  • 1
    You'll have to do this with the subtitles filter as suggested by konradmb. Please explain what was wrong with the command. Did you get an error? Did it not map the correct streams? Did it not burn the subtitles?
    – llogan
    Commented May 22, 2020 at 17:40
  • 1
    I renamed the file (removed spaces) and now the same command worked. Apparently the -vf option had problems with the spaces in the filename even though I had escaped them. The final command was ffmpeg -i video.mkv -map 0:v -map 0:a:1 -c:a copy -vf subtitles=video.mkv:si=1 -preset veryslow -crf 18 out.mp4 because I wanted a specific audio track, can this be improved somehow? Is it redundant? @konradmb post your comment as an answer so I can mark it as the answer. Commented May 22, 2020 at 19:21

1 Answer 1

2

To embed subtitles using mkv as a source use:

ffmpeg -i video.mkv -vf subtitles=video.mkv:si=1 out.mp4

Replace id in si=1 with subtitle stream number that you want to hardcode. You can check it with ffprobe.

1
  • which additional code is necessary to also make sure to pick the correct audio stream? Commented Nov 18, 2020 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .