[Libav-user] Trying to mux h264 to mp4.

Charlie Lye karl.lye at gmail.com
Sat Feb 7 00:22:56 CET 2015


Hello,

I’m attempting to use libavformat to generate an MP4 file from a sequence of compressed frames provided to me by an encoder.
I am successfully generating an MP4 file, however I missing something. When sanity checking it with ffmpeg -i file.mp4, I get:

ffmpeg version git-2014-11-10-5dcb990 Copyright (c) 2000-2014 the FFmpeg developers
  built on Nov 10 2014 23:50:45 with Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      54. 11.100 / 54. 11.100
  libavcodec     56. 12.100 / 56. 12.100
  libavformat    56. 12.103 / 56. 12.103
  libavdevice    56.  2.100 / 56.  2.100
  libavfilter     5.  2.103 /  5.  2.103
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
[h264 @ 0x7fd02300f000] no frame!
    Last message repeated 149 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd02300da00] decoding for stream 0 failed
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd02300da00] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1280x720, 4941 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
/Users/charlie/hd.mp4: could not find codec parameters
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/charlie/hd.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1iso6mp41
    encoder         : Lavf56.15.102
  Duration: 00:00:05.23, start: 0.066667, bitrate: 4944 kb/s
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 1280x720, 4941 kb/s, 30 fps, 30 tbr, 19200 tbn, 38400 tbc (default)
    Metadata:
      handler_name    : VideoHandler
At least one output file must be specified

The (possibly) relevant bit of code looks like this:

/* Add an output stream. */
static void addStream(OutputStream *ost, AVFormatContext *oc, enum AVCodecID codec_id)
{
    AVCodecContext *c;

    ost->st = avformat_new_stream(oc, 0);
    if (!ost->st) {
        fprintf(stderr, "Could not allocate stream\n");
        return;
    }
    
    ost->st->id = oc->nb_streams-1;
    c = ost->st->codec;
    c->codec_id = codec_id;

    switch (codec_id) {
        case AV_CODEC_ID_H264:
            c->codec_type = AVMEDIA_TYPE_VIDEO;
            c->profile = FF_PROFILE_H264_HIGH;
            c->pix_fmt = AV_PIX_FMT_YUV420P;
            c->framerate = (AVRational){ 640, 19200 };
            c->bit_rate = 5000000;
            c->width    = 1280;
            c->height   = 720;
            c->time_base = (AVRational){ 1, 60 };
            ost->st->time_base = (AVRational){ 1, 19200 };
            c->time_base       = ost->st->time_base;
            
            //c->gop_size      = 12; /* emit one intra frame every twelve frames at most */
            //c->pix_fmt       = STREAM_PIX_FMT;
            break;
        default:
            break;
    }
    
    /* Some formats want stream headers to be separate. */
    if (oc->oformat->flags & AVFMT_GLOBALHEADER)
        ost->st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
}

As you can see I am setting the pix_fmt field, but this isn’t being reflected in the final MP4. I am unsure as the whether this information is trying to be determined from the H264 stream, or the MP4, and so am unsure of where the problem lies. Could it be an issue with the SPS and PPS of the H264 stream? Could it be that the pixel format I am specifying is wrong? Presumably it needs to match whatever the encoder is outputting, but the error doesn’t suggest that. It looks more like it tried to scan the entire stream and found nothing…


Any thoughts appreciated!

Kind regards,
Charlie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20150206/bc4353df/attachment.html>


More information about the Libav-user mailing list