Good day! I'm looking for MKVToolNix equivalent software for .MP4's. I will use it in a video file without subtitles, I'll find it's subtitle and merge it with the video file just like what I did in MKVToolNix. Thanks!
-
I needed the same thing. I couldnt find, and contacted them, and asked to add ability to "bake" the result in "mp4" too, not only in mkv..– T.ToduaCommented Aug 2, 2017 at 10:27
-
waiting their answer.. till that, i've found nice topic here - forum.videohelp.com/threads/…– T.ToduaCommented Aug 2, 2017 at 10:41
3 Answers
Muxing a file simply means to extract individual streams out of existing container files or mix existing streams together into a new container file. For MP4, this can be done with ffmpeg and the -c copy
switch. If you don't want to write command line inputs, XMedia Recode is a good, free GUI for ffmpeg (only available for Windows). There's a documentation on the website, simply select Direct Stream Copy to avoid reencoding the individual streams.
-
Can you point me to where is Direct Stream Copy? Can't find that function you're mentioning. Thanks! Commented Mar 16, 2017 at 4:13
-
@JuliusAlfeche That exact phrase was taken from the website (see link). To copy a stream instead of converting it, load a file in the program, open the respective tab (video/audio) and set the Mode dropdown to Copy Commented Mar 16, 2017 at 12:46
-
XMedia Recode is NOT available for Linux. That link is dead.– cipricusCommented Dec 7, 2020 at 8:58
-
@cipricus Thanks for the note, I've updated the link and added a note that it's only available for Windows. Commented Dec 7, 2020 at 9:31
I just went through a very similar use-case working with TS files. MoritzLost has the key point but as ffmpeg
options can be quite difficult to sort out when you are first getting started, here is a more detailed answer.
Short Answer
For a single input mp4 file and single input SRT file, we can keep all streams from both files and merge them into a new mp4 container (only transcoding the subtitle stream...ie lossless on the audio/video) like this:
ffmpeg
-i input.mp4 \
-i subtitle.srt \
-map 0 \
-map 1 \
-codec copy \
-scodec mov_text \
output.mp4
If you have unknown stream types, multiple subtitle streams, or other things going on then this may not work and you might need to revise the options.
MP4 vs MKV container - limitations of mp4
You should know that the MP4 container does not support embedded srt
(subrip) streams. It only supports mov_text
for soft-subs. So we have to transcode the SRT to mov_text
or use hard-coded subs (where the subtitle text is encoded into the video stream directly and cannot be turned off).
This is one of the reasons that I prefer the mkv
container format over mp4
. It allows me to easily maintain multiple audio and subtitle streams with many different formats all within a single file (keep everything together). Yes overall file size is larger for people that don't care about those extra audio/subs... but I don't share over the network and hard-disk space is cheap.
Plex and VLC and most other modern media players have no trouble with MKV right out of the box...so something to think about whether you really want to use mp4 if you are someone that cares about soft-subtitles and keeping everything together (single file).
ffmpeg
ffmpeg
is a very powerful free/opensource tool. The command line options can be confusing but once you understand how to use the -map
and -codec
options, you can already do a lot. If you are semi-technical and do lots of video work it is worth learning how to use the command line on your OS and how to use tools like this. Windows Services for Linux makes this easier than ever for windows users on Windows 10. For Mac/Linux it has always been easy to install and run these tools.
How to mux multiple inputs into a single mp4 container
The following would take an input mp4
(or other) file and a second srt
input file, take all streams from both files and mux them into a new output.mp4 file. We tell ffmpeg
to copy the audio/video streams (no transcoding or quality loss) and to convert any subtitle streams into mov_text
since that is the only type that mp4
container supports.
ffmpeg
-i input.mp4 \
-i subtitle.srt \
-map 0 \
-map 1 \
-codec copy \
-scodec mov_text \
output.mp4
Depending on how you run this on windows, the \
to continue the command on the next line may not work and you may need to remove the backslashes and condense the command into one without newlines.
Again but with comments explaining the options.
ffmpeg \
-i input.mp4 \ # first input file (index 0)
-i subtitle.srt \ # second input file (index 1)
-map 0 \ # select all streams from first input file
-map 1 \ # select all streams from second input file
-codec copy \ # copy audio/video streams (no transcode)
-scodec mov_text \ # transcode all subtitle streams to type mov_text
output.mp4 # name of output file
Running this command will show you output something like the following for a simple input mp4
with a single audio and video stream.
...
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Stream #1:0 -> #0:2 (subrip (srt) -> mov_text (native))
...
You can see it copies the first two streams (audio/video) from input 0
(the first input) and does a conversion on the third stream from input 1
(the second input...the srt file).
Alternatively, go from MP4+SRT to MKV with mkvtoolnix
If you aren't opposed to MKV containers, then there is no reason you can't just take the input mp4 and separate subtitle file and mux all the streams into a new MKV file instead. This would also keep the SRT as an SRT and not transcode it into mov_text
.
Remember MP4 and MKV are just "containers" and so you can copy around the video/audio/subtitle streams from inside these containers without any transcoding (loss of data/quality)...as long as the destination container type supports that stream's codec.
mkvmerge \
--output output.mkv \
input.mp4 \
subtitle.srt
In this case, because we are taking all streams from the input files and mkvmerge
doesn't do any transcoding, the command is much simpler.
If it was me with your use-case I would just go to mkv
unless you are trying to build a file for a player that only supports mp4 and don't have any other option (ie get a different player).
References
https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/subtitle_options#Set_Subtitle_Codec
dmMediaConverter is very similar to MKVToolnix.
It is just a ffmpeg
gui, so it can save in any format.
To replicate the described MKVToolnix use, select "Convert", then "Add files", selecting both video and subtitles.
Check "Enabled" to keep the stream, uncheck to remove it.
Check "Copy" to keep the stream as it is, uncheck to trasnscode it.