How to convert an mpeg2 to a streamable or fragmented mp4?

9,708

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)

Share:
9,708

Related videos on Youtube

Lars Kecker
Author by

Lars Kecker

Updated on September 18, 2022

Comments

  • Lars Kecker
    Lars Kecker almost 2 years

    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.

    Command:

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

    Error:

    [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.

    • Admin
      Admin about 12 years
      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
    • Admin
      Admin about 12 years
      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.