<div dir="ltr">Dear list,<div><br></div><div>I am writing my first libav program and facing problem in muxing h.264 raw frames to mp4.</div><div><br></div><div>I referred to muxing.c sample but that sample encodes frames to h.264 before writing to file however in my case I dont have to encoding, the frames are already compressed.</div>
<div><br></div><div>I need to know the what steps do I need to follow in order to create correct mp4 movie</div><div><br></div><div>currently I am doing the following</div><div><br></div><div>AVOutputFormat* outputFormat<br>
</div><div>AVFormatContext* formatContext<br></div><div>char* filename = "c:\\export.mp4";<br></div><div><br></div><div>outputFormat = av_guess_format(NULL, filename, NULL);<br></div><div>formatContext = avformat_alloc_context();<br>
</div><div>AVCodec* codec = avcodec_find_encoder(outputFormat->video_codec);</div><div><div>AVStream* st = avformat_new_stream(formatContext , codec);</div></div><div><div><br></div><div>c = st->codec;</div><div>c->bit_rate = 400000;<br>
</div><div>c->width    = 720;<br></div><div>c->height   = 480;</div><div>c->time_base.den = 2997;<br></div><div>c->time_base.num = 100;</div><div>c->gop_size      = 12; /* emit one intra frame every twelve frames at most */</div>
<div>c->pix_fmt       = AV_PIX_FMT_YUV420P;</div></div><div><br></div><div><div>av_dump_format(formatContext, 0, filename, 1);</div></div><div><br></div><div><div>if (!(outputFormat->flags & AVFMT_NOFILE)) {</div>
<div>    if (avio_open(&formatContext->pb, filename, AVIO_FLAG_WRITE) < 0) {</div><div>        return 1;<br></div><div>    }</div><div>}</div><div><br></div><div>/* Write the stream header, if any. */</div><div>
avformat_write_header(formatContext, NULL);</div></div><div><br></div><div>The following code writes the data in another callback function having data and dataLen as parameters.. data is the pointer to h.264 frame data and dataLen is the length in bytes</div>
<div><div>AVPacket pkt = { 0 };</div><div>av_init_packet(&pkt);</div><div>pkt.stream_index = 0;</div><div>pkt.flags = 0;           </div><div>pkt.pts = videoFrameNumber;</div><div>pkt.dts = videoFrameNumber;           </div>
</div><div><div>pkt.size = dataLen;</div><div>pkt.data = data;</div><div>av_interleaved_write_frame(formatContext, &pkt);</div></div><div>videoFrameNumber += 100;</div><div><br></div><div>and finally <br></div><div><br>
</div><div><div>av_write_trailer(formatContext);</div><div>int i = 0;</div><div>for (i = 0; i < formatContext->nb_streams; i++)</div><div>    {</div><div>        av_freep(&formatContext->streams[i]->codec);</div>
<div>        av_freep(&formatContext->streams[i]);       </div><div>    }</div><div><br></div><div>if (!(formatContext->oformat->flags & AVFMT_NOFILE))</div><div>{</div><div>        avio_close(formatContext->pb);</div>
<div>}</div><div><br></div><div>av_free(formatContext);</div></div><div><br></div><div><br></div><div>The movie is created but when I run</div><div>ffmpeg -i c:\output.mp4 the following error</div><div><br></div><div>Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), 720x480, 318244 kb/s): unspecified pixel format</div>
<div><br></div><div><br></div><div>Please help!</div></div>