1

I have MKV files which contain multiple subtitle options, multiple audio options, and multiple chapters.

I'm wanting to convert to MP4. The MKV's are x265 with DD 5.1. I just want x264 MP4's with plain stereo, no subs and the default audio.

All I can find is solutions for converting with hardcoded subs or specific audio tracks. I need all of that stripped away, and more importantly, x265 to x264.

1 Answer 1

2

There are multiple questions; I'll try to answer them separately for simplicity.

First of all, converting from mkv to mp4: The easiest way would be something like this ffmpeg -i input.mkv output.mp4 This will cause ffmpeg to infer the format based on the filename and isn't always possible.

If you need to specify the type explicitly, you can add the parameter -f <format>. In your case, something like this: ffmpeg -f matroska -i input.mkv -f mp4 output.mp4

Note: The format before the input (-i) corresponds to the input format, while the format after the input corresponds to the output format.

Next, let's look at the codec:

FFmpeg uses a predefined codec by default; you can disable this by specifying the copy codec using -codec copy.

There are multiple options to specify a codec, depending on the scenario:

  • -codec copy Use the original codec for all mapped streams
  • -codec libx264 Convert all video streams to h264 (type of stream is deduced by the codec)
  • -vcodec libx264 Convert video streams to h264 (-acodec and -scodec for audio and subtitles, respectively)
  • -c copy Short for -codec copy
  • -c:v copy Short for -vcodec copy

In your case, something like ffmpeg -i input.mkv -c libx264 output.mp4 should produce the desired result.

Next, audio channels:

FFmpeg already integrates a downmixer; therefore, the standard solution is to use -ac 2 (Set the number of audio channels to 2). As Dolby digital is probably not supported within mp4, you should change the audio codec as well: ffmpeg -i input.mkv -c aac -ac 2 output.mp4

A much more detailed answer is provided here.

Next, chapters: Removing chapters is relatively easy; adding the following option -map_chapters -1 will remove the Chapter-TOC from the output.

Last but not least, stream selection:

The simplest way of selecting a stream is by number, but there are multiple other options:

  • -map 0:0 use the first stream from the first input file
  • -map 0:v:0 select the first video stream from the first input file
  • -map -0:s everything except subtitles from the first input file
  • -map 0:m:language:eng select by language
  • -map 0:v:0? use the first video stream of the first input if exists

To conclude this answer, your final command should look something like this:

ffmpeg -i input.mkv \
  -map 0:v:0 \
  -map 0:m:language:eng? \
  -c:v libx264 \
  -c:a aac \
  -map_chapters -1 \
  -ac 2 \
  output.mp4

Output contains:

  • First video stream
  • English audio (if exists)
  • No chapters
  • Only two audio channels
  • video codec: h264
  • Audio codec: aac
  • Output format: mp4

Hope this helps, and I didn't miss any requirements

1
  • Thank you for your very detailed response. The solution was actually quite simple, just ffmpeg -i "C:\video.mkv" -c:v libx264 -c:a libfdk_aac -c:a copy "C:\video.mp4", but I've saved your reply for future use.
    – Adam
    Sep 9, 2022 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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