ffmpeg recording h264 live stream got error <p>I am trying to record a h.264 live stream using the following code:</p> <pre><code> AVOutputFormat* fmt = av_guess_format(NULL, "test.mpeg", NULL); AVFormatContext* oc = avformat_alloc_context(); oc-&gt;oformat = fmt; avio_open2(&amp;oc-&gt;pb, "test.mpeg", AVIO_FLAG_WRITE, NULL, NULL); AVStream* stream = NULL; ... while(!done) { // Read a frame if(av_read_frame(inputStreamFormatCtx, &amp;packet)&lt;0) return false; if(packet.stream_index==correct_index) { //////////////////////////////////////////////////////////////////////// // Is this a packet from the video stream -&gt; decode video frame if (stream == NULL){//create stream in file stream = avformat_new_stream(oc, pFormatCtx-&gt;streams[videoStream]-&gt;codec-&gt;codec); avcodec_copy_context(stream-&gt;codec, pFormatCtx-&gt;streams[videoStream]-&gt;codec); stream-&gt;sample_aspect_ratio = pFormatCtx-&gt;streams[videoStream]-&gt;codec-&gt;sample_aspect_ratio; stream-&gt;sample_aspect_ratio.num = pFormatCtx-&gt;streams[videoStream]-&gt;codec-&gt;sample_aspect_ratio.num; stream-&gt;sample_aspect_ratio.den = pFormatCtx-&gt;streams[videoStream]-&gt;codec-&gt;sample_aspect_ratio.den; // Assume r_frame_rate is accurate stream-&gt;r_frame_rate = pFormatCtx-&gt;streams[videoStream]-&gt;r_frame_rate; stream-&gt;avg_frame_rate = stream-&gt;r_frame_rate; stream-&gt;time_base = av_inv_q(stream-&gt;r_frame_rate); stream-&gt;codec-&gt;time_base = stream-&gt;time_base; avformat_write_header(oc, NULL); } av_write_frame(oc, &amp;packet); ... } } </code></pre> <p>However, the ffmpeg says </p> <pre><code>encoder did not produce proper pts making some up </code></pre> <p>when the code runs to av_write_frame(); what's the problem here?</p>