title: Precise framerate in gstreamer while grabbing YUY2 frames from usb camera
body: <p>I have a ELP USB 3.0 camera. The output of C:\msys64\mingw64\bin\gst-device-monitor-1.0 is:</p>
  <pre><code>    name  : 3.0 USB Camera
      class : Video/Source
      caps  : image/jpeg, width=1920, height=1080, framerate=60/1, pixel-aspect-ratio=1/1
              image/jpeg, width=1280, height=720, framerate=60/1, pixel-aspect-ratio=1/1
              image/jpeg, width=640, height=480, framerate=60/1, pixel-aspect-ratio=1/1
              video/x-raw, format=YUY2, width=1920, height=1080, framerate=60/1, pixel-aspect-ratio=1/1
              video/x-raw, format=YUY2, width=1280, height=720, framerate=60/1, pixel-aspect-ratio=1/1
              video/x-raw, format=YUY2, width=640, height=480, framerate=60/1, pixel-aspect-ratio=1/1
      gst-launch-1.0 ksvideosrc device-path=&quot;\\\\\?\\usb\#vid_15aa\&amp;pid_1555\&amp;mi_00\#6\&amp;35c2c7be\&amp;0\&amp;0000\#\{6994ad05-93ef-11d0-a3cc-00a0c9223196\}\\global&quot; ! ...
  </code></pre>
  <p>What I want is to grab YUY2 frames with gstreamer in an avi file for later processing. Now I need to make recordings of 20 min and I need a frame rate of only 5 fps. What it is important in my setup is the need to insure somehow that the frames are equally spaced because I need to do a frequency analysis on the timeseries from certain pixels/ROIs. Because my camera only delivers 60 fps I presume my only option would be videorate. The captured frames should be real frames not duplicates. So I have adapted for Windows a script found <a href="https://gist.github.com/NamWoo/84bbaa17247bd372ad3224870f4f3df1" rel="nofollow noreferrer">here</a> and I'm using PyGst and PyGObject to create a window displaying images from camera at 5fps and buttons to start and stop recording.</p>
  <p>The pipeline for display is this one:</p>
  <p>self.pipeline = Gst.parse_launch(&quot;ksvideosrc device-index=0 do-timestamp=true ! timeoverlay halignment=right valignment=bottom ! clockoverlay halignment=left valignment=bottom time-format='%Y/%m/%d %H:%M:%S' ! videorate drop-only=true silent=false ! video/x-raw, framerate=5/1, width=1280, height=720, format=(string)YUY2 ! tee name=tee ! queue name=videoqueue ! videoconvert ! autovideosink&quot;)</p>
  <p>and the one for recording that gets attached to the first one when pressing record button is this one:</p>
  <p>self.recordpipe = Gst.parse_bin_from_description(&quot;queue name=filequeue ! video/x-raw, framerate=5/1, width=1280, height=720, format=(string)YUY2 ! avimux ! filesink location=&quot; + filename, True)</p>
  <p>My questions:</p>
  <ol>
  <li>are the above pipelines good enough? Could I make any optimisations? I mean are there any bottlenecks to be removed cause I just need to grab frames wihout any processing (all is done on a mini pc Bmax B3) and recording on a sata6 SSD.</li>
  <li>How could I somehow see a log of dumped frames and recorded ones just to insure that the framerate is as close to real as it could be.</li>
  <li>Do you have any ideas on some other solutions maybe with OpenCv? Would it make a difference in regard to framerate precision?</li>
  </ol>
  <p>Thank you for your time.</p>