24
votes

I am using ffmpeg to switch container from mkv to mp4 via this command:

ffmpeg -i filename.mkv -vcodec copy 1.mp4

this is the simplest command that I found when converting from mkv container to mp4 without re-encoding. The output stated otherwise (if I am not mistaken)

This is a small screen shot of the the output:

FFmpeg Screenshot

Where it said Stream Mapping, #0:0 (264 (native)) -> 264 (libx264)). Does this mean that it's re-encoding from x264 to libx264? What Did I do wrong?

Any help is appreciated...

3
In the future, note that FFmpeg questions belong on SuperUser.com.Brad
The console output is text. It can be copied and pasted. No need for an image of some of the text. It would be like writing an email to someone, then taking a screenshot of just half of it, and then sending that.llogan

3 Answers

44
votes

problem solved, specify the audio codec solve my problem...

ffmpeg -i filename.mkv -vcodec copy -acodec copy 1.mp4
4
votes

Remuxing containers, e.g. MKV or AVI to MP4, with FFmpeg will only keep a single – it tries to choose the best one available – audio and video stream from the input file in the output file. This can be avoided by providing -map 0.

Matroska files frequently contain subtitles in a format not supported in MOV/MPEG containers by FFmpeg, esp. SRT/Subrip or ASS/SSA. They can either simply be dropped with -sn or be converted to a native format like mov_text. (You could also burn hard subtitles into a video stream with filters.)

Sometimes, adding missing information by using heuristics might help. This is activated with -find_stream_info, but I am not sure whether this should be used by default.

I shall assume that built configuration is not important to know (-hide_banner) and only serious problems should be logged to the console (-loglevel warning, alternatively: quiet | panic | fatal | error | warning | info (default) | verbose | debug | trace).

Therefore, a rather universal conversion command looks like this:

$ ffmpeg -find_stream_info -i input.mkv \
         -map 0 -codec copy -codec:s mov_text output.mp4 \
         -hide_banner -loglevel warning; \
  rm input.mkv

For batch processing multiple files on a Windows box within cmd and overwriting existing files (-y), use for:

FOR /r %F IN (*.mkv) DO (@ffmpeg \
  -find_stream_info -i "%F" \
  -map 0 -codec copy -codec:s mov_text "%~pnF.mp4" \
  -hide_banner -loglevel warning -y)
-1
votes

Throwing this batch file in the same directory and execute it. This should do the trick:

@ECHO OFF

FOR %%F IN (*.mkv) DO (
    ffmpeg -i %%~nF.mkv -acodec copy -vcodec copy %%~nF.mp4
)

Some context in case anyone else is facing the same:

I'd previously recorded my desktop using OBS; the mkv file wasn't accepted by Sony Vegas. I ran the above batch which called ffmpeg on each of the captures and the resultant MP4s were accepted by Sony Vegas.