[Libav-user] How to use FFMpeg to encode in x264.

Denis info at denisgottardello.it
Tue Sep 6 21:19:55 CEST 2011


Hello everybody. I'm writing a custom application for encode a sequence of 
IplImage in a mpg file.
Using CODEC_ID_MPEG4 all works well. The file that my program has produced work 
well with mplayer. Now I want to use CODEC_ID_H264 but I have some trouble.
How you can see in this code:



        AVCodec *pAVCodec= avcodec_find_encoder(CODEC_ID_H264);
        if (!pAVCodec) qDebug() << "avcodec_find_encoder Error!!!";
        else {
            AVCodecContext *pAVCodecContext= avcodec_alloc_context(); {
                pAVCodecContext->pix_fmt= PIX_FMT_YUV420P;
                pAVCodecContext->width= Width;
                pAVCodecContext->height= Height;
                pAVCodecContext->time_base.den= 25;
                pAVCodecContext->time_base.num= 1;




on begin I set the framerate to 25 fps. During job x264 causes this error:
"non-strictly-monotonic PTS".
In order to solve it, before "avcodec_encode_video" function I have inserted 
this row:
"pAVFrame->pts= currentTimeStamp".
See the code:


		pAVFrame->pts= currentTimeStamp;
                int out_size= avcodec_encode_video(pAVCodecContext, pOutBuffer, 
BYTEPIC, pAVFrame);
                fwrite(pOutBuffer, 1, out_size, FileOut);



The error does not appears again but mplayer does not uses this value, it uses 
the initial fps value.
My problem is that I'm not sure to can respect the initial fps, how can I do 
in order to explain the timestamp for each frame?


-- 
www.denisgottardello.it
Skype: mrdebug
Videosurveillance and home automation! 
http://www.denisgottardello.it/DomusBoss/DomusBossIndice.php


More information about the Libav-user mailing list