Thanks Matthew.<div><br></div><div>That all helped, but I am still finding that if I do not set the pts before my call to avcodec_encode_video I keep getting "non-strictly-monotonic PTS" warning messages.</div><div>
<br></div><div>Do you not set the pts value on your AVFrame* before encoding?</div><div><br></div><div>Regards,</div><div>Zac Shenker<br><div><br><div class="gmail_quote">On Sat, Nov 5, 2011 at 3:16 AM, Matthew Einhorn <span dir="ltr"><<a href="mailto:moiein2000@gmail.com">moiein2000@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Fri, Nov 4, 2011 at 2:40 AM, Zac Shenker <<a href="mailto:zac@zacshenker.com">zac@zacshenker.com</a>> wrote:<br>
> Hi,<br>
> I have started working on some code based on the decoding_encoding.c sample<br>
> file to encode the test pattern as h.264 video.<br>
> The settings I am using on my AVCodecContext is as follows:<br>
> c->width = 352;<br>
> c->height = 288;<br>
> c->time_base.num = 1;<br>
> c->time_base.den = 25;<br>
> c->pix_fmt = PIX_FMT_YUV420P;<br>
> c->gop_size = 1;<br>
> if(codec_id == CODEC_ID_H264)<br>
><br>
> av_opt_set(c->priv_data, "preset", "slow", 0);<br>
><br>
> I am having a number of issues:<br>
> 1) Even when I set the AVFrame->pts to AVS_NOPTS_VALUE, I still get<br>
> "non-strictly-monotonic PTS" warning messages. How should I be setting the<br>
> PTS value?<br>
<br>
</div>See my code below. I don't set the pts or anything else in the frame<br>
other than copying the image data to the picture.<br>
<div class="im"><br>
> 2) For the first 13 frames my call to avcodec_encode_video returns a size of<br>
> 0, should this be happening?<br>
</div>Yes, because it needs to buffer a couple of frames so it can calculate<br>
best compression.<br>
<div class="im"><br>
> 3) The output file that gets written does not seem to have a duration(using<br>
> ffprobe or VLC to check)<br>
<br>
</div>Maybe you have to write the header and trailer before and after the<br>
video is written. I.e. avformat_write_header(m_pFormatCtx, NULL) and<br>
av_write_trailer(m_pFormatCtx);<br>
<div class="im"><br>
> So far to figure out how things work I have been searching through the<br>
> ffmpeg & x264 source, is there any up-to-date examples of doing h264 video<br>
> encoding (no audio) anywhere?<br>
<br>
</div>Look in ffmpeg.c and ffplay.c<br>
<br>
<br>
<br>
Here's how my code looks:<br>
if (m_pFormatCtx->oformat->flags & AVFMT_RAWPICTURE)<br>
{<br>
/* raw video case. The API will change slightly in the near<br>
future for that. Latency won't happen here. */<br>
AVPacket sPkt;<br>
av_init_packet(&sPkt);<br>
<br>
sPkt.flags |= AV_PKT_FLAG_KEY;<br>
sPkt.stream_index= m_pAVStream->index;<br>
sPkt.data= (unsigned char *)m_pAVFrame;<br>
sPkt.size= sizeof(AVPicture);<br>
<br>
nRes = av_interleaved_write_frame(m_pFormatCtx, &sPkt);<br>
} else<br>
{<br>
/* Encode the image, if flushing pass null frame. */<br>
nTemp = avcodec_encode_video(pCodecCtx, m_auchVideoOutBuf, m_nBuffer,<br>
auchBuffer?m_pAVFrame:NULL);<br>
/* If zero size, it means the image was buffered and will need to be<br>
flushed later. */<br>
if (nTemp > 0)<br>
{<br>
AVPacket sPkt;<br>
av_init_packet(&sPkt);<br>
<br>
// Save pts of frame<br>
if (pCodecCtx->coded_frame && pCodecCtx->coded_frame->pts != AV_NOPTS_VALUE)<br>
sPkt.pts= av_rescale_q(pCodecCtx->coded_frame->pts,<br>
pCodecCtx->time_base, m_pAVStream->time_base);<br>
if(sPkt.pts == AV_NOPTS_VALUE && sPkt.dts == AV_NOPTS_VALUE &&<br>
!(m_pFormatCtx->oformat->flags & AVFMT_NOTIMESTAMPS))<br>
sPkt.dts= 0;<br>
<br>
// Is it a key frame?<br>
if(pCodecCtx->coded_frame && pCodecCtx->coded_frame->key_frame)<br>
sPkt.flags |= AV_PKT_FLAG_KEY;<br>
sPkt.stream_index= m_pAVStream->index;<br>
sPkt.data= m_auchVideoOutBuf;<br>
sPkt.size= nTemp;<br>
/* Write the compressed frame in the media file */<br>
nRes = av_interleaved_write_frame(m_pFormatCtx, &sPkt);<br>
} else<br>
{<br>
nRes = nTemp; // If zero it's ok, if none zero it means error.<br>
if (!auchBuffer) // Either way, no more frames to flush, if flushing<br>
m_bDone= true;<br>
}<br>
}<br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
</blockquote></div><br></div></div>