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
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.
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.
See the susbtitles filter documentation for more info such as how to select a particular subtitle stream if there is more than one.