I am trying to convert mythtv recorded mpg (mpeg2) files into streamable mp4 files. Converting to an mp4 is simple, however, the entire file must be converted first before it is usable. Even using conversion tools that put the "mov atom" at the start of the file for quick streaming require that the entire mp4 be encoded before that happens.

I read on avconv docs that "The mov/mp4/ismv muxer supports fragmentation." which can put a "fake" mov atom at the start of the file and then puts a new one at each keyframe throughout the file so the video can be streamed while it is being transcoded or if the conversion is interrupted.

I believe I have followed the avconv instructions (http://libav.org/avconv.html#MOV_002fMP4_002fISMV) on how to convert a file, but continue to get errors that indicate the encoder does not understand the parameters. Below is my command, and the error output it generates. I have exhausted google and myself searching for answers and have come up blank so any help would be greatly appreciated.

System running ubuntu 12.04x64 with avconv version 0.8.1-4:0.8.1-0ubuntu1.


avconv -i 1081_20111227200000.mpg -f mp4 -movflags frag_keyframe+empty_moov -c:v libx264 -c:a copy output.mp4


[mp4 muxer @ 0x36772e0] [Eval @ 0x7fffeddb69b0] Undefined constant or missing '(' in 'frag_keyframe'
[mp4 muxer @ 0x36772e0] Unable to parse option value "frag_keyframe+empty_moov"
[mp4 muxer @ 0x36772e0] Error setting option movflags to value frag_keyframe+empty_moov.
Output #0, mp4, to 'output.mp4':
    Stream #0.0: Video: libx264, yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], q=-1--1, 90k tbn, 29.97 tbc
    Stream #0.1(eng): Audio: ac3, 48000 Hz, 5.1, 384 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video -> libx264)
  Stream #0:1 -> #0:1 (copy)
Could not write header for output file #0 (incorrect codec parameters ?)

I have tried different muxers (-f parameters like h264 etc) and had other errors like the movflag wasn't even supported (logical).

Am I missing a package, dependency, or just the point? Thanks in advance.

  • Should this be done via terminal? Have you tried Non Linear Editing Systems? like kdenlive, openshot, etc. Take a look at this: askubuntu.com/questions/58250/what-is-an-easy-video-editor May 9, 2012 at 18:35
  • Yeah, I am trying to automate this, so command line or bash shell-able (even perl-able) is what I am looking for. So if one of these editors can be scripted to do this, I'm game.
    – Scrubb
    May 9, 2012 at 20:06

2 Answers 2


There is a bug filed with libav about this exact issue. Depressingly, is doesn't seem to be addressed. I think it's best to consider avconv a good encoding tool, but not a good encapsulating tool.

The best way to go about it is to use MP4Box from GPAC. It's a utility which seems to be primarily concerned with encapsulating media streams into mp4 files. It does not do en/de/transcoding, for instance. If you install GPAC on Ubuntu, you can say:

MP4Box -add non-streamable.mp4 new-shiny-streamable.mp4

MP4Box by default makes the mp4 files streamable:

As of version 0.2.4, MP4Box always stores the file with 0.5 second interleaving and meta-data at the begining, making it suitable for HTTP streaming. (source)


See here: it's an ffmpeg guide, but it applies equally well to avconv.

I don't know about creating files for streaming, but the error could be because you are missing out on a preset, and also possibly a quality setting (though I believe that avconv uses -crf 23 as the default, if no other quality setting is provided). Try:

avconv -i 1081_20111227200000.mpg -f mp4 -movflags frag_keyframe+empty_moov -c:v libx264 -preset medium -c:a copy output.mp4

The presets are: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower and veryslow. The faster presets will give you faster encodes, but larger files, while the slower ones have smaller files, but take longer to make. There is no quality difference between the different presets. There is also a 'placebo' preset, but that's a joke by the x264 developers, and should be ignored.

If that doesn't work, you could try using:

avconv -i 1081_20111227200000.mpg -f mp4 -movflags frag_keyframe+empty_moov -c:v libx264 -crf 20 -preset medium -c:a copy output.mp4

20 is completely arbitrary, choose whatever crf setting works best for you. Lower=better picture quality, but larger file size. According to that guide, you should probably use between 18-28.

You must log in to answer this question.

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