const char *video_device;
int j;
- if (!ap || ap->width <= 0 || ap->height <= 0 || ap->frame_rate <= 0)
+ if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0)
return -1;
width = ap->width;
height = ap->height;
- frame_rate = ap->frame_rate;
- frame_rate_base = ap->frame_rate_base;
+ frame_rate = ap->time_base.den;
+ frame_rate_base = ap->time_base.num;
+ if((unsigned)width > 32767 || (unsigned)height > 32767)
+ return -1;
+
st = av_new_stream(s1, 0);
if (!st)
return -ENOMEM;
+ av_set_pts_info(st, 48, 1, 1000000); /* 48 bits pts in us */
s->width = width;
s->height = height;
}
desired_palette = -1;
- if (st->codec.pix_fmt == PIX_FMT_YUV420P) {
+ if (st->codec->pix_fmt == PIX_FMT_YUV420P) {
desired_palette = VIDEO_PALETTE_YUV420P;
- } else if (st->codec.pix_fmt == PIX_FMT_YUV422) {
+ } else if (st->codec->pix_fmt == PIX_FMT_YUV422) {
desired_palette = VIDEO_PALETTE_YUV422;
- } else if (st->codec.pix_fmt == PIX_FMT_BGR24) {
+ } else if (st->codec->pix_fmt == PIX_FMT_BGR24) {
desired_palette = VIDEO_PALETTE_RGB24;
}
val = 1;
ioctl(video_fd, VIDIOCCAPTURE, &val);
- s->time_frame = av_gettime();
+ s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
s->use_mmap = 0;
/* ATI All In Wonder automatic activation */
goto fail;
}
s->gb_frame = 0;
- s->time_frame = av_gettime();
+ s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
/* start to grab the first frame */
s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
switch(s->frame_format) {
case VIDEO_PALETTE_YUV420P:
frame_size = (width * height * 3) / 2;
- st->codec.pix_fmt = PIX_FMT_YUV420P;
+ st->codec->pix_fmt = PIX_FMT_YUV420P;
break;
case VIDEO_PALETTE_YUV422:
frame_size = width * height * 2;
- st->codec.pix_fmt = PIX_FMT_YUV422;
+ st->codec->pix_fmt = PIX_FMT_YUV422;
break;
case VIDEO_PALETTE_RGB24:
frame_size = width * height * 3;
- st->codec.pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
+ st->codec->pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
break;
default:
goto fail;
s->fd = video_fd;
s->frame_size = frame_size;
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_RAWVIDEO;
- st->codec.width = width;
- st->codec.height = height;
- st->codec.frame_rate = frame_rate;
- st->codec.frame_rate_base = frame_rate_base;
-
- av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_RAWVIDEO;
+ st->codec->width = width;
+ st->codec->height = height;
+ st->codec->time_base.den = frame_rate;
+ st->codec->time_base.num = frame_rate_base;
+ st->codec->bit_rate = frame_size * 1/av_q2d(st->codec->time_base) * 8;
return 0;
fail:
if (video_fd >= 0)
close(video_fd);
av_free(st);
- return -EIO;
+ return AVERROR_IO;
}
static int v4l_mm_read_picture(VideoData *s, uint8_t *buf)
av_log(NULL, AV_LOG_ERROR, "Cannot Sync\n");
else
perror("VIDIOCMCAPTURE");
- return -EIO;
+ return AVERROR_IO;
}
/* This is now the grabbing frame */
VideoData *s = s1->priv_data;
int64_t curtime, delay;
struct timespec ts;
- int64_t per_frame = (int64_t_C(1000000) * s->frame_rate_base) / s->frame_rate;
/* Calculate the time of the next frame */
- s->time_frame += per_frame;
+ s->time_frame += int64_t_C(1000000);
/* wait based on the frame rate */
for(;;) {
curtime = av_gettime();
- delay = s->time_frame - curtime;
+ delay = s->time_frame * s->frame_rate_base / s->frame_rate - curtime;
if (delay <= 0) {
- if (delay < -per_frame) {
+ if (delay < int64_t_C(-1000000) * s->frame_rate_base / s->frame_rate) {
/* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */
- s->time_frame += per_frame;
+ s->time_frame += int64_t_C(1000000);
}
break;
}
}
if (av_new_packet(pkt, s->frame_size) < 0)
- return -EIO;
+ return AVERROR_IO;
pkt->pts = curtime & ((1LL << 48) - 1);
return v4l_mm_read_picture(s, pkt->data);
} else {
if (read(s->fd, pkt->data, pkt->size) != pkt->size)
- return -EIO;
+ return AVERROR_IO;
return s->frame_size;
}
}