[PATCH] In video4linux2, in the case the timebase value in ap is 0/0, read the timebase value already set in the driver, and set it back in the codec stream, rather than leaving the invalid value of 0/0.

Stefano Sabatini stefano.sabatini-lala
Tue Jan 4 21:49:34 CET 2011


In particular, fix ffmpeg grabbing timestamps when the timebase value
is not set through the CLI.
---
 doc/indevs.texi    |    9 +++++++--
 libavdevice/v4l2.c |   13 +++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index d345833..2e67500 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -146,6 +146,8 @@ devices and the command @file{v4l-info} for Video4Linux2 devices.
 
 If the size for the device is set to 0x0, the input device will
 try to autodetect the size to use.
+Only for the video4linux2 device, if the frame rate is set to 0/0 the
+input device will use frame rate value already set in the driver.
 
 Video4Linux support is deprecated since Linux 2.6.30, and will be
 dropped in later versions.
@@ -153,13 +155,16 @@ dropped in later versions.
 Follow some usage examples of the video4linux devices with the ff*
 tools.
 @example
-# Grab and show the input of a video4linux device.
+# Grab and show the input of a video4linux device, frame rate is set
+# to the default of 25/1.
 ffplay -s 320x240 -f video4linux /dev/video0
 
 # Grab and show the input of a video4linux2 device, autoadjust size.
 ffplay -f video4linux2 /dev/video0
 
-# Grab and record the input of a video4linux2 device, autoadjust size.
+# Grab and record the input of a video4linux2 device, autoadjust size,
+# frame rate value defaults to 0/0 so it is read from the video4linux2
+# driver.
 ffmpeg -f video4linux2 -i /dev/video0 out.mpeg
 @end example
 
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index 5425928..26f879a 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -514,6 +514,19 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
             ap->time_base.num = tpf->numerator;
             ap->time_base.den = tpf->denominator;
         }
+    } else {
+        /* if timebase value is not set in ap, read the timebase value
+         * from the driver and set it in ap */
+        struct v4l2_streamparm streamparm = { 0 };
+        struct v4l2_fract *tpf = &streamparm.parm.capture.timeperframe;
+
+        streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+        if (ioctl(s->fd, VIDIOC_G_PARM, &streamparm) != 0) {
+            av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %s\n", strerror(errno));
+            return AVERROR(errno);
+        }
+        ap->time_base.num = tpf->numerator;
+        ap->time_base.den = tpf->denominator;
     }
 
     return 0;
-- 
1.7.2.3


--envbJBWh7q8WU6mo
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0004-Factorize-common-code-in-v4l2_set_parameters.patch"




More information about the ffmpeg-devel mailing list