Ask Your Question

Anders Musikka's profile - activity

2018-08-29 01:56:59 -0600 received badge  Famous Question (source)
2016-09-14 00:10:47 -0600 received badge  Student (source)
2015-07-29 09:32:25 -0600 received badge  Notable Question (source)
2014-11-11 10:48:18 -0600 received badge  Popular Question (source)
2013-02-13 01:51:21 -0600 received badge  Editor (source)
2013-02-13 01:49:59 -0600 asked a question How do I adjust FPS for a v4l2 camera

How can I adjust the FPS that my v4l2 camera captures at?

The following patch seems to solve it, but is there any other way?

From 0ad873a3682a1d7354b8c233e71fc76c7bb319b1 Mon Sep 17 00:00:00 2001 From: Anders Musikka [email protected] Date: Wed, 13 Feb 2013 08:45:04 +0100 Subject: [PATCH] Add FPS adjust possibility

---
 modules/highgui/src/cap_libv4l.cpp |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/modules/highgui/src/cap_libv4l.cpp b/modules/highgui/src/cap_libv4l.cpp
index 63a2ff9..179c90f 100644
--- a/modules/highgui/src/cap_libv4l.cpp
+++ b/modules/highgui/src/cap_libv4l.cpp
@@ -1665,6 +1665,22 @@ static int icvSetPropertyCAM_V4L(CvCaptureCAM_V4L* capture, int property_id, dou
             width = height = 0;
         }
         break;
+    case CV_CAP_PROP_FPS:
+    {
+        struct v4l2_streamparm streamparm;
+        struct v4l2_fract *tpf;
+        memset (&streamparm, 0, sizeof (streamparm));
+        streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+        tpf = &streamparm.parm.capture.timeperframe;
+        tpf->numerator = 1;
+        tpf->denominator = cvRound(value);
+        retval=1;
+        if (ioctl(capture->deviceHandle, VIDIOC_S_PARM, &streamparm) < 0) {
+            fprintf(stderr,"Failed to set camera FPS: %s\n",strerror(errno));
+            retval=0;
+        }
+        break;
+    }
     default:
         retval = icvSetControl(capture, property_id, value);
     }
-- 
1.7.9.5