---
libavdevice/v4l.c | 21 +++++++++------------
1 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/libavdevice/v4l.c b/libavdevice/v4l.c
index bd011e1..94b670a 100644
--- a/libavdevice/v4l.c
+++ b/libavdevice/v4l.c
@@ -42,7 +42,7 @@ typedef struct {
int fd;
int frame_format; /* see VIDEO_PALETTE_xxx */
int use_mmap;
- AVRational time_base;
+ AVRational fps;
int64_t time_frame;
int frame_size;
struct video_capability video_cap;
@@ -85,12 +85,6 @@ static int grab_read_header(AVFormatContext *s1,
AVFormatParameters *ap)
int vformat_num = FF_ARRAY_ELEMS(video_formats);
enum PixelFormat pix_fmt = av_get_pix_fmt(s->pix_fmt);
- if (ap->time_base.den <= 0) {
- av_log(s1, AV_LOG_ERROR, "Wrong time base (%d)\n", ap->time_base.den);
- return -1;
- }
- s->time_base = ap->time_base;
-
#if FF_API_FORMAT_PARAMETERS
if (ap->width > 0)
s->video_win.width = ap->width;
@@ -98,6 +92,8 @@ static int grab_read_header(AVFormatContext *s1,
AVFormatParameters *ap)
s->video_win.height = ap->height;
if (ap->pix_fmt)
pix_fmt = ap->pix_fmt;
+ if (ap->time_base.num)
+ s->fps = (AVRational){ap->time_base.den, ap->time_base.num};
#endif
st = av_new_stream(s1, 0);
@@ -204,7 +200,7 @@ static int grab_read_header(AVFormatContext *s1,
AVFormatParameters *ap)
goto fail;
}
- s->time_frame = av_gettime() * s->time_base.den / s->time_base.num;
+ s->time_frame = av_gettime() * s->fps.num / s->fps.den;
s->use_mmap = 0;
} else {
s->video_buf = mmap(0, s->gb_buffers.size, PROT_READ|PROT_WRITE,
MAP_SHARED, video_fd, 0);
@@ -216,7 +212,7 @@ static int grab_read_header(AVFormatContext *s1,
AVFormatParameters *ap)
}
}
s->gb_frame = 0;
- s->time_frame = av_gettime() * s->time_base.den / s->time_base.num;
+ s->time_frame = av_gettime() * s->fps.num / s->fps.den;
/* start to grab the first frame */
s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
@@ -258,7 +254,7 @@ static int grab_read_header(AVFormatContext *s1,
AVFormatParameters *ap)
st->codec->codec_id = CODEC_ID_RAWVIDEO;
st->codec->width = s->video_win.width;
st->codec->height = s->video_win.height;
- st->codec->time_base = s->time_base;
+ st->codec->time_base = (AVRational){s->fps.den, s->fps.num};
st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8;
return 0;
@@ -306,9 +302,9 @@ static int grab_read_packet(AVFormatContext *s1, AVPacket
*pkt)
/* wait based on the frame rate */
for(;;) {
curtime = av_gettime();
- delay = s->time_frame * s->time_base.num / s->time_base.den - curtime;
+ delay = s->time_frame * s->fps.den / s->fps.num - curtime;
if (delay <= 0) {
- if (delay < INT64_C(-1000000) * s->time_base.num /
s->time_base.den) {
+ if (delay < INT64_C(-1000000) * s->fps.den / s->fps.num) {
/* printf("grabbing is %d frames late (dropping)\n", (int)
-(delay / 16666)); */
s->time_frame += INT64_C(1000000);
}
@@ -360,6 +356,7 @@ static const AVOption options[] = {
{ "width", "", offsetof(VideoData, video_win.width), FF_OPT_TYPE_INT,
{.dbl = 640}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ "height", "", offsetof(VideoData, video_win.height), FF_OPT_TYPE_INT,
{.dbl = 480}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ "pixel_format", "", offsetof(VideoData, pix_fmt), FF_OPT_TYPE_STRING,
{.str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
+ { "framerate", "", offsetof(VideoData, fps), FF_OPT_TYPE_RATIONAL,
{.dbl = 25}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};
--
1.7.5.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel