[Libav-user] Header missing in mpg, in spite of using avformat_write_header

Drabner drabner at zoobe.com
Thu Nov 22 17:27:56 CET 2012

I am encoding a live rendered video to mpg and/or mp4 (depends on the later
usage of the video) using the ffmpeg C API. When encoding to mp4, everything
is well. But when encoding to mpg, the resulting video cannot be played by
any player. A quick call to ffprobe on it reveals that the header is
missing. But this seems pretty much impossible, as I am explicitly writing

This is how I write the header, before any frame is encoded:

// ptr->oc is the AVFormatContext
int error = avformat_write_header(ptr->oc, NULL);
if (error < 0)
    s_logFile << "Could not write header. Error: " << error << endl;
    fprintf(stderr, "Could not write header. Error: '%i'\n", error);
    return 1;

There never is any error when writing the header.

The result mpg does work when I "encode" it in an additional step with an
external ffmpeg executable like this: "ffmpeg -i ownEncoded.mpg -sameq -y
So it seems all the data is there, only the header is missing for some

I wonder what could be wrong here as I encode mp4 with the exact same
functions, except setting some special values like qmin, qmax, me_method,
etc. when encoding to mp4. Do I probably have to set any special values so
that ffmpeg really does write the header correctly?

View this message in context: http://libav-users.943685.n4.nabble.com/Header-missing-in-mpg-in-spite-of-using-avformat-write-header-tp4656101.html
Sent from the libav-users mailing list archive at Nabble.com.

More information about the Libav-user mailing list