Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to convert an MKV file to MP4 to be compatible with my PS3. I am using: avconv -i file.mkv -c copy file.mp4

It fails and I get the following error:

[mp4 @ 0x8a17c00] pts < dts in stream 0 av_interleaved_write_frame(): Invalid argument

The file is h264 video and ac3 audio.

share|improve this question
This question may give you some pointers. See answer #2 – Kevin Bowen Jan 15 '13 at 21:21
That question is where I originally found how to do the conversion. There is no mention of errors though. Thanks anyway. – boredemt Jan 17 '13 at 14:21
After much trial and error i got it to work using: avconv -i file.mkv -c:v copy -c:a copy file.mp4 – boredemt Jan 17 '13 at 15:20
up vote 4 down vote accepted

Get needed software

sudo apt-get install gpac mkvtoolnix

Extract video and audio from matroska file

First you need to check what tracks the matroska file contains with

mkvmerge --identify video.mkv

File 'video.mkv': container: Matroska
Track ID 1: video (V_MPEG4/ISO/AVC)
Track ID 2: audio (A_AC3)

Then extract video and audio according to their tracks with:

mkvextract tracks video.mkv 1:video.h264 2:audio.ac3

Extracting track 1 with the CodecID 'V_MPEG4/ISO/AVC' to the file 'video.h264'. Container format: AVC/h.264 elementary stream
Extracting track 2 with the CodecID 'A_AC3' to the file 'audio.ac3'. Container format: Dolby Digital (AC3)
Progress: 100%

Mux audio and video into mp4 containter

MP4Box -fps 24 -add video.h264 -add audio.ac3 video.mp4

AVC-H264 import - frame size 1280 x 720 at 24.000 FPS
Import results: 31671 samples - Slices: 5672 I 125048 P 122648 B - 32288 SEI - 4936 IDR
AC3 import - sample rate 48000 - 6 channels
Saving to video.mp4: 0.500 secs Interleaving

I had to add -fps 24 option because MP4Box didn't detect video fps correctly. Depending on usage AC3 audio track should be re-encoded into something else before muxing.

Now you have remuxed streams from matroska container into mp4 container without losing any quality.

EDIT: MP4 doesn't officially support AC3 audio so the audio track should be converted into a supported format (eg. AAC, MP3) if you want the file to be playable with something else than VLC.

share|improve this answer

I believe that

avconv -i file.mkv -c:v copy -c:a copy file.mp4

is the correct command. You need to specify the codec copy property for the streams you want to copy separately.

share|improve this answer
That should be correct. At least that you need to specify video and audio codec. If -c:a is not accepted -codec:a and -acodec should work, same goes for video. – LiveWireBT Dec 11 '13 at 6:02

I was looking for muxing mp4 along with m4a. The usual ffmpeg commands for encoding didn't worked.Tried MP4Box & it worked like a charm. :-)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.