27

To convert an MKV to AVI, I do two things. The first thing I do is this:

ffmpeg -i filename.mkv -vcodec copy -acodec copy output.avi

or this:

ffmpeg -i filename.mkv -sameq -acodec copy output.avi

Either of these will convert the MKV to an AVI, but the problem is that the video does not play smoothly for some reason. That's fine though, because if I do one more thing it gets fixed:

ffmpeg -i output.avi -vcodec mpeg4 -b 4000k -acodec mp2 -ab 320k converted.avi

After I do this then the file plays without problem. I had success doing it this way for one file, but then I tried it on another file, and there is a slight, but noticeable loss in video quality. This is the output I get when doing the second step:

FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
  built on Dec 29 2010 18:02:10 with gcc 4.2.1 (Apple Inc. build 5664)
  configuration: 
  libavutil     50.15. 1 / 50.15. 1
  libavcodec    52.72. 2 / 52.72. 2
  libavformat   52.64. 2 / 52.64. 2
  libavdevice   52. 2. 0 / 52. 2. 0
  libswscale     0.11. 0 /  0.11. 0

Seems stream 0 codec frame rate differs from container frame rate: 359.00 (359/1) -> 29.92 (359/12)
Input #0, avi, from 'output.avi':
  Metadata:
    ISFT            : Lavf52.64.2
  Duration: 00:04:17.21, start: 0.000000, bitrate: 3074 kb/s
    Stream #0.0: Video: mpeg4, yuv420p, 704x480 [PAR 229:189 DAR 5038:2835], 29.92 fps, 29.92 tbr, 29.92 tbn, 359 tbc
    Stream #0.1: Audio: vorbis, 48000 Hz, stereo, s16
Output #0, avi, to 'converted.avi':
  Metadata:
    ISFT            : Lavf52.64.2
    Stream #0.0: Video: mpeg4, yuv420p, 704x480 [PAR 229:189 DAR 5038:2835], q=2-31, 4000 kb/s, 29.92 tbn, 29.92 tbc
    Stream #0.1: Audio: mp2, 48000 Hz, stereo, s16, 320 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1

I just used arbitrarily large settings on the second step and it worked nicely before but not in this case. What settings should I use?

Arjan
  • 30,974
  • 14
  • 75
  • 112
tony_sid
  • 14,001
  • 51
  • 139
  • 194
  • This is what ffmpeg gave me for sameq: Option 'sameq' was removed. If you are looking for an option to preserve the quality (which is not what -sameq was for), use -qscale 0 or an equivalent quality factor option. – DavidG Nov 24 '15 at 20:16
  • IIRC this was because the AVI container is so outdated that it cannot properly transport modern codecs. The very least of the problems will manifest during seeking. – Daniel B Jan 28 '20 at 09:02

5 Answers5

36

In order to just copy the video and audio bitstream, thus without quality loss:

ffmpeg -i filename.mkv -c:v copy -c:a copy output.avi

If you want FFmpeg to convert video and audio automatically:

ffmpeg -i filename.mkv output.avi
slhck
  • 223,558
  • 70
  • 607
  • 592
RobotHumans
  • 5,904
  • 1
  • 19
  • 25
  • 9
    FFmpeg's default settings tend to be awful. [Here](https://evilsoup.wordpress.com/2013/02/10/general-ffmpeg-encoding-guide-2/) is a general guide to encoding with various codecs; [the FFmpeg wiki](https://ffmpeg.org/trac/ffmpeg/wiki#Encoding) has more in-depth guides. – evilsoup Jun 11 '13 at 08:27
  • first code created file which was corrupted did not play in VLC. – codemirror Oct 29 '18 at 20:26
25
 ffmpeg -i "input.mkv" -f avi -c:v mpeg4 -b:v 4000k -c:a libmp3lame -b:a 320k "converted.avi"

My suggestion: use mpeg4+mp3 in avi container.

slhck
  • 223,558
  • 70
  • 607
  • 592
Ken
  • 251
  • 3
  • 2
1

based on Ken's answer

recursive

find . \( -name '*.mkv' \) -exec sh -c '
  for file do
    target="${file%.*}.avi"
    ffmpeg -i "$file" -f avi -c:v mpeg4 -b:v 4000k -c:a libmp3lame -b:a 320k "$target"
  done' sh {} +

check if everything is right

find . \( -name '*.mkv' \) -exec sh -c '
  for file do
    target="${file%.*}.avi"
    echo ffmpeg -i "$file" -f avi -c:v mpeg4 -b:v 4000k -c:a libmp3lame -b:a 320k "$target"
  done' sh {} +
srghma
  • 180
  • 1
  • 7
  • Thank! This was very useful :) I have a cheap Beamer (Victsing BH486A) which didnt play sound from mkv files. I made avi from it, as in this recursive command, and it works :) – franc May 20 '22 at 04:32
1

Try to use ffmulticonverter. Very useful for me: it is a sort of GUI for ffmpeg and you can set easily all the parameters. Moreover you can find a list of all possible video formats.

LP

user155915
  • 11
  • 1
-4

May I recommend a shortcut I use regularly?

ffmpeg -i filename.mkv -sameq output.avi
CarlF
  • 8,846
  • 3
  • 24
  • 40
  • 5
    sameq does not mean same quality and shouldn't be used. In fact it was removed from ffmpeg altogether. Rather set the quality using whatever the target codec provides. – slhck Aug 29 '12 at 21:15