raymanfx / libv4l-rs

Video4Linux2 bindings for Rust
MIT License
155 stars 65 forks source link

Consistently getting 7.5fps using examples #26

Closed mijoharas closed 3 years ago

mijoharas commented 3 years ago

Hey, sorry for the issue.

I seem to be consistently getting about 7.5FPS running any capture examples (stream_forward_mmap, stream_capture_mmap). This happens even when varying the format that I'm using for the device.

I'm wondering if there could be something I'm doing wrong? the format I'm using doesn't even seem to support 7.5 FPS for any of it's formats... which is strange.

Let me know if there's any advice you can give me.

raymanfx commented 3 years ago

What kind of camera are you using? Please add the active format and parameters you are using. Also, are you running a release or debug mode build?

mijoharas commented 3 years ago

Hey, I'm using a pretty standard laptop webcam (goes up to 720p, and with MJPEG it'll do 30FPS, slightly lower on YUYV). I've tried both release and debug. I messed around with a few different formats (and shrinking it right down to eliminate a slow processor or something as an issue).

Here is some output from a couple of frames of stream_capture_mmap:

Using device: /dev/video0

Active format:
width          : 320
height         : 180
fourcc         : YUYV
field          : progressive
stride         : 640
size           : 115200
colorspace     : sRGB
quantization   : default
transfer       : default transfer function

Active parameters:
capabilities : TIME_PER_FRAME
modes        : (empty)
interval     : 1/30 [s]

Buffer
  sequence  : 2
  timestamp : 1665.073533 [s]
  flags     : MAPPED | TIMESTAMP_MONOTONIC | TSTAMP_SRC_SOE
  length    : 115200
Buffer
  sequence  : 3
  timestamp : 1665.205535 [s]
  flags     : MAPPED | TIMESTAMP_MONOTONIC | TSTAMP_SRC_SOE
  length    : 115200

FPS: 7.462410290914528
MB/s: 0.8201908832008339

Also, for info here is the formats supported from v4l2-ctl:

v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
    Type: Video Capture

    [0]: 'YUYV' (YUYV 4:2:2)
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 960x540
            Interval: Discrete 0.067s (15.000 fps)
        Size: Discrete 848x480
            Interval: Discrete 0.050s (20.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 424x240
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 352x288
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 320x180
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.100s (10.000 fps)
    [1]: 'MJPG' (Motion-JPEG, compressed)
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 960x540
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 848x480
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 424x240
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 352x288
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 320x180
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.033s (30.000 fps)
mijoharas commented 3 years ago

Also, one thing to note, it seems to be consistently very close to 7.5 FPS. it's not a rough number, and it's never been anything else during my testing. (I can't fully remember what it was when I was testing the other day, but wouldn't be surprised if it was the same).

raymanfx commented 3 years ago

I'm afraid I can't reproduce this using my Logitech C922 Pro Stream - I'm getting consistent 30 FPS in MJPG or 20-30 in YUYV. What kind of frame times are you getting when using v4l2-ctl for mmap streaming?

mijoharas commented 3 years ago

Oh wow... this is strange...:

time v4l2-ctl --device /dev/video0 --stream-mmap --stream-to=frame.raw --stream-count=100                                                                                                                                                         
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 30.15 fps, dropped buffers: 1
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 30.14 fps
<<<<<<<<<<<<<<<<<< 26.12 fps
<<<<<<<<<<< 22.37 fps
<<<<<<<< 19.25 fps

I then Ctrl+C-ed it, and did it again afterwards:

 time v4l2-ctl --device /dev/video0 --stream-mmap --stream-to=frame.raw --stream-count=1000
 <<<<<<<< 7.52 fps, dropped buffers: 1
<<<<<<<< 7.50 fps
<<<<<<< 7.51 fps
<<<<<<< 7.50 fps
<<<<<<<< 7.50 fps
<<<<<<< 7.50 fps

I wonder what could be causing this...

Thanks for your help. I guess I'll close this issue, as it doesn't seem to be to do with this library.

If you have any ideas for places I could look do let me know, but I'll dig into this by myself.

(and thanks for the tip, didn't realise you could stream directly from v4l2-ctl).

mijoharas commented 3 years ago

oh wow... I figured it out, that was quick https://stackoverflow.com/questions/46228379/v4l2-framerate-drops

moving to a brighter room sorts it out. Sorry for the distraction!

time v4l2-ctl --device /dev/video0 --stream-mmap --stream-to=frame.raw --stream-count=1000                                                                                                                                             INT ↵  5s    default 🐍  2.6.3   
<<<<<<<< 7.52 fps, dropped buffers: 1
<<<<<<<<<<<<<< 10.83 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 17.17 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 20.36 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 22.29 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 23.59 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 24.50 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 25.20 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 25.73 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 30.08 fps
mijoharas commented 3 years ago

that explains why the framerate seems to drop when I code at night :smile:

raymanfx commented 3 years ago

Oh sorry, I could have saved you some time there :D Most, if not all, laptop cameras are really garbage products and way too sensitive to changing light conditions.