26

When I try converting mkv to mp4 using ffmpeg, the following error occurs:

version 0.8.3-4:0.8.3-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers   built on Jun 12 2012 16:52:09 with gcc 4.6.3  
 *** THIS PROGRAM IS DEPRECATED ***   This program is only provided for compatibility and will be removed in a future release. Please use
 avconv instead.   [matroska,webm @ 0x1e939c0] max_analyze_duration
 reached   [matroska,webm @ 0x1e939c0] Estimating duration from
 bitrate, this may be inaccurate   Input #0, matroska,webm, from
 'input.mkv':     Duration: 00:01:00.76, start: 0.000000, bitrate: 384
 kb/s  
     Stream #0.0(eng): Video: h264 (High), yuv420p, 1280x544, PAR 1:1 DAR 40:17, 25 fps, 25 tbr, 1k tbn, 50 tbc (default)  
     Stream #0.1(eng): Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s (default)  
     Stream #0.2(eng): Subtitle: [0][0][0][0] / 0x0000   Output #0, ipod, to 'output.m4v':     Metadata:  
     encoder         : Lavf53.21.0  
     Stream #0.0(eng): Video: libx264, yuv420p, 1280x544 [PAR 1:1 DAR 40:17], q=2-31, 25 tbn, 25 tbc (default)  
     Stream #0.1(eng): Audio: ac3, 48000 Hz, 5.1, 384 kb/s (default)   Stream mapping:     Stream #0.0 -> #0.0     Stream #0.1 -> #0.1  
 Press ctrl-c to stop encoding   [ipod @ 0x1e9b740] Application
 provided invalid, non monotonically increasing dts to muxer in stream
 0: -2 >= -2 av_interleaved_write_frame(): Invalid argument

I used this command to convert the file:

ffmpeg -i input.mkv -vcodec copy -acodec copy -absf aac_adtstoasc output.m4v

The input file has the following characteristics:

mediainfo input.mkv 


>General
>
>Unique ID                                : 200459305952356554213392832683163418790 (0x96CF0ED8DB5914CBB9E18163689280A6)  
>Complete name                            : input.mkv  
>Format                                   : Matroska  
>Format version                           : Version 2  
>File size                                : 1.46 GiB  
>Duration                                 : 1h 5mn  
>Overall bit rate                         : 3 168 Kbps  
>Encoded date                             : UTC 2010-09-26 21:44:02  
>Writing application                      : mkvmerge v2.9.5 ('Tu es le seul') built on >Jun 17 2009 16:28:30  
>Writing library                          : libebml v0.7.8 + libmatroska v0.8.1  
>
>Video
>ID                                       : 1  
>Format                                   : AVC  
>Format/Info                              : Advanced Video Codec  
>Format profile                           : [email protected]  
>Format settings, CABAC                   : Yes  
>Format settings, ReFrames                : 4 frames  
>Codec ID                                 : V_MPEG4/ISO/AVC  
>Duration                                 : 1h 5mn  
>Bit rate                                 : 2 910 Kbps  
>Width                                    : 1 280 pixels  
>Height                                   : 720 pixels  
>Display aspect ratio                     : 16:9  
>Frame rate                               : 25.000 fps  
>Color space                              : YUV  
>Chroma subsampling                       : 4:2:0  
>Bit depth                                : 8 bits  
>Scan type                                : Progressive  
>Bits/(Pixel*Frame)                       : 0.126  
>Stream size                              : 1.31 GiB (90%)  
>Writing library                          : x264 core 105 r1724 b02df7b  
>Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=6 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=0 / chroma_qp_offset=-2 / threads=18 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=0 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc=2pass / mbtree=0 / bitrate=2910 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / pb_ratio=1.30 / aq=1:1.00  
>
>Default                                  : Yes  
>Forced                                   : No  
>
>Audio
>ID                                       : 2  
>Format                                   : AC-3  
>Format/Info                              : Audio Coding 3  
>Mode extension                           : CM (complete main)  
>Codec ID                                 : A_AC3  
>Duration                                 : 1h 5mn  
>Bit rate mode                            : Constant  
>Bit rate                                 : 256 Kbps  
>Channel(s)                               : 2 channels  
>Channel positions                        : Front: L R  
>Sampling rate                            : 48.0 KHz  
>Bit depth                                : 16 bits  
>Compression mode                         : Lossy  
Stream size                              : 121 MiB (8%)  
Language                                 : English  
Default                                  : Yes  
Forced                                   : No  

Being new to ffmpeg, I'm not sure what the error means or how to correct it.

Thanks!

5
  • there is already an answer about this askubuntu.com/questions/50433/… the basic concept is that both the MKV and the MP4 are containers, they are just containers, you basically have to unpack and re-pack the audio and video tracks if you want to switch between the two.
    – user827992
    Jul 4, 2012 at 21:06
  • I read that but I'm trying to learn how to do it with ffmpeg instead of those other tools. I use handbrake all the time but that doesn't help me understand how to do it in ffmpeg. Just trying to learn something new.
    – JohnS
    Jul 4, 2012 at 21:48
  • ffmpeg is probably not the best choice, because it always try to re-encode everything and you waste time and resources doing this, anyway forum.doom9.org/showthread.php?t=164683 this can probably become a good starting point for you.
    – user827992
    Jul 4, 2012 at 21:51
  • @user827992 This is incorrect. ffmpeg does not always try to re-encode everything. Did you even read the details in the question? The example in the question is clearly attempting to copy the streams, not re-encode.
    – llogan
    Jul 7, 2012 at 19:45
  • @user827992: both ffmpeg and avconv are able to losslessly re-pack from container to another without re-enconding content.
    – MestreLion
    Oct 2, 2012 at 0:32

6 Answers 6

40

As I've already written here, I suggest you change a few details in your command line:

  • If you're using an Ubuntu release older than 15.04, replace ffmpeg for avconv, as it was the fork used by Ubuntu for a few years (see the comments)
  • Do you really need -absf aac_adtstoasc? It had some issues that may not have been corrected in current Ubuntu's ffmpeg. I suggest you to try without it first.
  • -vcodec copy -acodec copy can be simplified to -codec copy or -c copy. It would also prevent tampering other streams besides video and audio, like subtitles.

So the winner is...

ffmpeg -i input.mkv -c copy output.m4v

If that does not work, please post all terminal output.

7
7

To automatically convert all files in a folder from MKV to MP4 you can create an alias:

alias mkv2mp4="for f in ./**/*.mkv; do ffmpeg -n -i \"\$f\" -c copy \"\${f%.mkv}.mp4\" && rm \"\$f\"; done"

This command performs the following steps:

  • Recursively loops through the current directory looking for .mkv files
  • Converts each file & all its sources to .mp4, not overwriting (-n) existing files
  • Removes the source file when the conversion was successful
0
4

I know its a very old thread, but I've found a solution to successfully run ffmpeg. Don't use -vcodec copy -acodec copy, use just ffmpeg -i input.mkv output.m4v instead. It will start running.

But in my case, I convert a .mkv to .mp4, the result output is just trash. It losses frame accuracy.

1
  • 5
    If you don't use the copy codec, it will reencode and lose quality. Jul 13, 2015 at 11:53
1

Try This one:: Libav in Linux

Installation: run command

sudo apt-get install libav-tools

Video conversion command::Go to folder contains the video and run in terminal

avconv -i oldvideo.mkv -ar 22050 convertedvideo.mp4
0

Got this on Xubuntu 14.04 when trying to burn a DVD of MP4s using DVDStyler; Bombono produces the same error. ffmpeg #1154 suggests this might have been fixed in ffmpeg, though perhaps not in avconv? libav #478 is still marked open.

Also see: https://unix.stackexchange.com/questions/127522/avconv-error-av-interleaved-write-frame

I filed Launchpad #1339980; in summary, use a current release of ffmpeg, and not avconv.

0

Using -codec copy didn't work for me (Ubuntu 22.04). Instead, this command did the trick:

  • Video-only mkv file:

    ffmpeg -i input.mkv -codec mpeg4 output.mp4
    
  • Video+audio mkv file:

    ffmpeg -i input.mkv -vcodec mpeg4 -acodec aac output.mp4
    

Notice that for an mkv file with audio track I had to explicitly specify that mpeg4 is the video codec (vcodec) and that aac is the audio codec (acodec).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .