[Libav-user] About encode video frame from webcam into H264 using ffmpeg

Scott Zhang macromarship at gmail.com
Fri Aug 19 08:26:57 CEST 2011


Hello.
     I am using ffmpeg 20110816 git version on windows.
     I am trying to do an application get camera frame from directshow then
encode it into h264 stream.
    Here is what I am doing:
1. Get frame from directshow pin
which is in YUYV12 format (YUV422).
2. sws_scale the frame into YUV420P format
3. encode YUV420P into h264 format.
The problem is after the encode start, the avcodec_encode_video always
return 0 until pass frame 42, then each frame generate 1 encoded frame.
here is the code.

pEnCodecCtx = avcodec_alloc_context3(NULL);
pEnCodecCtx->gop_size = 25;
    pEnCodecCtx->time_base.den = 25;
    pEnCodecCtx->time_base.num = 1;
pEnCodecCtx->width = m_iWidth;
    pEnCodecCtx->height = m_iHeight;
    pEnCodecCtx->pix_fmt = PIX_FMT_YUV420P;
pEnCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
ideo_outbuf_size = 200000;

    AVCodec *t_codec;
    t_codec = avcodec_find_encoder(CODEC_ID_H264);

    if(avcodec_open(pEnCodecCtx, t_codec) < 0){
        printf("Error open code\n");
        exit(1);
    }



Then encode
ret =
avcodec_encode_video(pEnCodecCtx,video_outbuf,video_outbuf_size,pictureDst);

the ret is 0 until I call encode_video from 42 times.

Why? Please help.


Thanks.
Regards.
Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20110819/7a66cb83/attachment.html>


More information about the Libav-user mailing list