---
libavdevice/v4l2.c | 26 ++++++++++++++------------
1 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index f829e50..2572912 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -63,6 +63,7 @@ struct video_data {
int width, height;
int frame_size;
int top_field_first;
+ AVRational fps;
int buffers;
void **buf_start;
@@ -457,6 +458,8 @@ static int v4l2_set_parameters(AVFormatContext *s1,
AVFormatParameters *ap)
#if FF_API_FORMAT_PARAMETERS
if (ap->channel > 0)
s->channel = ap->channel;
+ if (ap->time_base.num)
+ s->fps = (AVRational){ap->time_base.den, ap->time_base.num};
#endif
/* set tv video input */
@@ -510,23 +513,23 @@ static int v4l2_set_parameters(AVFormatContext *s1,
AVFormatParameters *ap)
}
av_freep(&s->standard);
- if (ap->time_base.num && ap->time_base.den) {
+ if (s->fps.num) {
av_log(s1, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",
- ap->time_base.num, ap->time_base.den);
- tpf->numerator = ap->time_base.num;
- tpf->denominator = ap->time_base.den;
+ s->fps.den, s->fps.num);
+ tpf->numerator = s->fps.den;
+ tpf->denominator = s->fps.num;
if (ioctl(s->fd, VIDIOC_S_PARM, &streamparm) != 0) {
av_log(s1, AV_LOG_ERROR,
"ioctl set time per frame(%d/%d) failed\n",
- ap->time_base.num, ap->time_base.den);
+ s->fps.den, s->fps.num);
return AVERROR(EIO);
}
- if (ap->time_base.den != tpf->denominator ||
- ap->time_base.num != tpf->numerator) {
+ if (s->fps.num != tpf->denominator ||
+ s->fps.den != tpf->numerator) {
av_log(s1, AV_LOG_INFO,
"The driver changed the time per frame from %d/%d to
%d/%d\n",
- ap->time_base.num, ap->time_base.den,
+ s->fps.den, s->fps.num,
tpf->numerator, tpf->denominator);
}
} else {
@@ -536,8 +539,6 @@ static int v4l2_set_parameters(AVFormatContext *s1,
AVFormatParameters *ap)
return AVERROR(errno);
}
}
- ap->time_base.num = tpf->numerator;
- ap->time_base.den = tpf->denominator;
return 0;
}
@@ -657,8 +658,8 @@ static int v4l2_read_header(AVFormatContext *s1,
AVFormatParameters *ap)
st->codec->codec_id = codec_id;
st->codec->width = s->width;
st->codec->height = s->height;
- st->codec->time_base.den = ap->time_base.den;
- st->codec->time_base.num = ap->time_base.num;
+ st->codec->time_base.den = s->fps.num;
+ st->codec->time_base.num = s->fps.den;
st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8;
return 0;
@@ -711,6 +712,7 @@ static const AVOption options[] = {
{ "channel", "", offsetof(struct video_data, channel), FF_OPT_TYPE_INT,
{.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ "width", "", offsetof(struct video_data, width), FF_OPT_TYPE_INT,
{.dbl = 640}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ "height", "", offsetof(struct video_data, height), FF_OPT_TYPE_INT,
{.dbl = 480}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ { "framerate","", offsetof(struct video_data, fps),
FF_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
{ "pixel_format", "", offsetof(struct video_data, pix_fmt),
FF_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};
--
1.7.5.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel