mkvtomp4
Looks like mkvtomp4
is what you want?
Uses mpeg4ip or GPAC's MP4Box, mkvtoolnix and ffmpeg to convert troublesome mkv files to mp4. The conversion does not re-encode the video and only re-encodes the audio if it doesn't use AAC codec (one can override this behaviour using --audio-codec).
You can download Windows and Linux versions on the Google Code page. You will need additional software though.
Check the sites for downloads for either Windows or Linux. On OS X, you only need to brew install mkvtoolnix mp4box
if you have Homebrew.
This will not copy your subtitles though. You'll need an additional step.
FFmpeg batch
If mkvtomp4 does not work for you, a simple FFmpeg batch file could also do.
Install ffmpeg (e.g. via Homebrew or options from https://ffmpeg.org/download.html). Then, just call:
ffmpeg -i input.mkv -c:v copy -c:a copy output.mp4
This will create a valid MP4 container without re-encoding. Loop over the files as needed and available by your operating system. This batch won't, however, copy subtitles.
In *nix, you could do the following. Just create a file convert.sh
:
#!/bin/bash
find /path/to/input/folder -iname '*.mkv' -print0 | while read -d '' -r file; do
ffmpeg -i "$file" -c:v copy -c:a copy ${file%%.mkv}.mp4
done
Replace the path to your video folder here. Make it executable with chmod +x convert.sh
, then run it with ./convert.sh
.
In Windows, you probably need two Batch files (shameless plug from here), one being startconvert.bat
:
for %%i IN (*.mkv) DO (convert-to-mp4.bat "%%i")
pause
And one that performs the conversion:
IF EXIST "%1.mp4" GOTO exit
@echo Conversion for %1 started on %DATE% %TIME%
ffmpeg -i %1 -c:v copy -c:a copy %1.mp4
:exit
@echo %1.mp4 already exists
Save both in the video folder. Simply run startconvert.bat
from the folder you want to start the conversion from.
Subtitles
If you want to add the subtitles, you might need a manual procedure if the following doesn't work for you:
ffmpeg -i input.mkv -c:a copy -c:v copy -map 0 output.mp4
To extract subtitles, use:
mkvextract tracks input.mkv 3:subtitles.srt
This is assuming that your file really contains the subtitles at track ID number 3 and they can be exported to the SRT format. To check whether a file really contains subtitles at track 3, use mkvmerge -i input.mkv
.
Then, use MP4Box to re-add the subtitles to the MP4 file.
mp4box -add input.mp4 -add subtitles.srt -new output.mp4
Best Answer
Save the following as something like DelMKVSubs.bat in the same directory mkvmerge.exe is in, edit the rootfolder variable as per your requirements and run the batch file:
The batch file should be easy enough to understand, but here's an overview nevertheless:
It uses
for /r
to recursively search%rootfolder%
for all MKVsIt then runs
mkvmerge -i
on each MKV to check whether a subtitle track existsIf the MKV does contain subtitle tracks, it runs
mkvmerge -S
to remux the file while skipping all such tracksFinally it checks the exit code of mkvmerge and if this (i.e.
errorlevel
) is 0 indicating success with no warnings/errors, it deletes the original fileFor more see the mkvmerge documentation and also
for /?
,if /?
etc. at the command prompt.