Hi,
     I think it is not related with V4L2.
     I read your code just now, I am not clear your code:     picture2 =
avcodec_alloc_frame();

I have a program, which use V4L2 get camera data YUYV, and then  sws_scale
it to YUV420P.
But the input & output data buffer are both allocated myself, not ffmpeg.
I grab them here, there are some self-defined type by typedef, but not hard
to understand, FYI.


   // init something and buffer
    rb_uint32 oyuv_size =ow*oh*2;
    rb_uint32 conv_size = ow * oh * 1.5;

    int srclines[4];
    srclines[0] = ow * 2;
    srclines[1] = 0;
    srclines[2] = 0;
    srclines[3] = 0;

    rb_uint8 *mid_buf,  *conv_buf[3];

    mid_buf = (rb_uint8*) osdep_malloc(oyuv_size);  // yuyv buffer

    conv_buf[0] = (rb_uint8*) osdep_malloc(ow * oh);   // yuv420p buffer
    conv_buf[1] = (rb_uint8*) osdep_malloc(ow * oh / 2);
    conv_buf[2] = (rb_uint8*) osdep_malloc(ow * oh / 2);

    // ***** THEN******, SOME CODES to read v4l2 buffer data into mid_buf.

    // last , sws_scale

    int destlines[4];
    destlines[0] = mDstW;
    destlines[1] = mDstW / 2;
    destlines[2] = mDstW / 2;
    destlines[3] = 0;
    img_convert_ctx2 = sws_getCachedContext((struct SwsContext*)
img_convert_ctx2, ow, oh,
           PIX_FMT_YUYV422, mDstW, mDstH, PIX_FMT_YUV420P, 1, NULL, NULL,
NULL);
    if (img_convert_ctx2 == NULL)
    {
        fprintf(stderr, "Cannot initialize the conversion context\n");
    }
    sws_scale((struct SwsContext*) img_convert_ctx2, mid_buf, srclines, 0,
mSrcH, conv_buf, destlines);


On Fri, Nov 12, 2010 at 11:35 AM, George Smart <[email protected]>wrote:

> Dear libav-user
>
> I wonder if anybody would be able to help me with encoding video from a
> webcam with ffmpeg libraries.  I have taken the video encoder example, and
> modified it slightly to allow me to encode frames as they arrive from the
> webcam.  My source code for the ffmpeg part can be found here:
> http://www.ee.ucl.ac.uk/~zceed42/ffmpeg.html<http://www.ee.ucl.ac.uk/%7Ezceed42/ffmpeg.html><
> http://www.ee.ucl.ac.uk/%7Ezceed42/ffmpeg.html> .
>
> Frames are read from the webcam by V4L2.  init_video_encode is called with
> a filename, and sets up the codec, etc.  close_video_encode is called to
> close the video encoder, finish files, free memory, etc.  video_encode is
> called with a pointer to a frame of video from V4L2.  It is set as below,
> inside V4L2.  These are the only options which work with the webcams I have.
>
>        fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
>        fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;
>
> Inside my code, 
> http://www.ee.ucl.ac.uk/~zceed42/ffmpeg.html<http://www.ee.ucl.ac.uk/%7Ezceed42/ffmpeg.html><
> http://www.ee.ucl.ac.uk/%7Ezceed42/ffmpeg.html>, I take data from the V4L2
> pointer, *p, with the av_fill command, and fill picture (AVFrame):
>
>    avpicture_fill( (AVPicture *) picture, p, PIX_FMT_YUYV422, c->width,
> c->height);
>
> The input video from V4L2 is YUYV422 (I believe - VLC tells me it's YUY2,
> which Google tells me is the same thing).  I am trying to use:
>
>    eSC = sws_getContext(c->width, c->height, PIX_FMT_YUYV422, c->width,
> c->height, PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL);
>    sws_scale(eSC, (const uint8_t* const*) picture->data, picture->linesize,
> 0, c->height, picture2->data, picture2->linesize);
>
> To convert from YUYV422 to YUV420P for
>
>    avcodec_encode_video(c, outbuf, outbuf_size, picture2);
>
> Picture and Picture2 are AVFrames before and after the conversion,
> respectively.
>
> The problem is, the sws_scale() call SIGSEGV's (Segmentation Faults).  I
> have had a hunt about with gdb and can't find out the reason.  I was hoping
> someone with experience could point me in the right direction.  I've Googled
> a fair bit, and can't seem to get my head around this one...
>
> I am also open to suggestions of replacing my V4L2 interface with something
> more ffmpeg friendly - I read that ffmeg can get frames from webcam
> directly??
>
> Thanks in advance for your time.
>
> George Smart, M1GEO
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to