On Thu, Nov 11, 2010 at 10:35 PM, 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/~zceed42/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/~zceed42/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
>

I think your problem might be that data pointer that you are passing to
sws_scale.  YUVY data is stored in three seperate arrays.  One for Y data,
one for U data, and one for V data.  sws_scale wants an array of pointers
that point to each array of data.

I can't give you an exact example right now because I not near my linux box,
but if you google YUV color space you should find something.
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to