[Ffmpeg-devel] compressed v4l2 images
Michael Niedermayer
michaelni
Sat Feb 10 17:23:53 CET 2007
Hi
On Wed, Feb 07, 2007 at 11:18:33PM -0200, Ramiro Polla wrote:
> Luca Abeni wrote:
> >Hi,
> >
> >On Tue, 2007-02-06 at 08:57 +0100, Luca Abeni wrote:
> >[...]
> >
> >>I have a dirty and half-working patch (at least, I had report of some
> >>kind of "half-success" with it) at home. I think it can be a good
> >>starting point... I'll post it this evening.
> >>
> >Here it is...
> >
> >
> Had to make some modifications for it to work.
>
> - Change int64_t_C to INT64_C
> - Move setting pkt->pts to after av_new_packet
> - Set st->codec->{width,height,time_base} after compressed_device_init works
> - Make device_init return an error when the device changes the pixelformat
>
> I think that's it... (altough the code could use some cleanup =)
>
> Attached new patch. Just ignore the change of video_device to
> s1->filename. It's part of the new grabbing interface.
[...]
> +static int compressed_device_init(int fd, int *width, int *height)
> +{
> + struct v4l2_format fmt;
> + int res;
> +
> + memset(&fmt, 0, sizeof(struct v4l2_format));
> + fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> + fmt.fmt.pix.width = *width;
> + fmt.fmt.pix.height = *height;
> + fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
> + res = ioctl(fd, VIDIOC_S_FMT, &fmt);
> + if ((*width != fmt.fmt.pix.width) || (*height != fmt.fmt.pix.height)) {
> + av_log(NULL, AV_LOG_INFO, "The V4L2 driver changed the video from %dx%d to %dx%d\n", *width, *height, fmt.fmt.pix.width, fmt.fmt.pix.height);
please provide a context to av_log (AVFormatContxt will do), i dont want to
see to many new av_log(NULL, ...) they cause problems in multithreded
apps
[...]
> +static int compressed_read_frame(struct video_data *s, AVPacket *pkt)
> +{
> + struct v4l2_buffer buf;
> + int res;
> +
> + memset(&buf, 0, sizeof(struct v4l2_buffer));
> + buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> + buf.memory = V4L2_MEMORY_MMAP;
> +
> + /* FIXME: Some special treatment might be needed in case of loss of signal... */
> + while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 &&
> + ((errno == EAGAIN) || (errno == EINTR)));
> + if (res < 0) {
> + av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno));
> +
> + return -1;
> + }
> + assert (buf.index < s->buffers);
> + if (av_new_packet(pkt, buf.bytesused) < 0) {
> + return -1;
> + }
> + pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec;
> +
> + /* Image is at s->buff_start[buf.index] */
> + memcpy(pkt->data, s->buf_start[buf.index], buf.bytesused);
can that memcpy be avoided? (directly grabing into AVPacket.data)?
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070210/2354df0a/attachment.pgp>
More information about the ffmpeg-devel
mailing list