Question

I have a Logitech webcam, when I list its available formats it shows (amongst others) the following:

Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUV 4:2:2 (YUYV)
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
            Interval: Discrete 0.040s (25.000 fps)
            Interval: Discrete 0.050s (20.000 fps)
            Interval: Discrete 0.067s (15.000 fps)
            Interval: Discrete 0.100s (10.000 fps)
            Interval: Discrete 0.200s (5.000 fps)

So now I want to capture 300 frames with a resolution of 640x480 @30fps, jpeg compress them and mux it to an avi. Capturing 300 frames @30fps should result in a 10 second movie and should take 10 seconds to record, but in my case it takes about 40 seconds to get 300 frames but it results in a 10 second video as expected.

This is my pipeline:

gst-launch-1.0 -v v4l2src device=/dev/video0 num-buffers=300 ! \
"video/x-raw,width=640,framerate=30/1" ! jpegenc ! avimux ! \
filesink location=output.avi

I checked with fpsdisplaysink, and a lot of frames get dropped:

last-message = rendered: 48, dropped: 250, fps: 1.88, drop rate: 5.64

So obviously I do not get 30fps from the cam. It is attached via USB 2.0 so enough bandwidth should be available. Gstreamer is not complain about the PC being to slow or anything else.

Is this a problem of the camera, lying about the fps, or am I missing something? Also why are there so many frames being dropped?

edit 1:

I now tried under better light conditions. With guvcview I set the exposure to a fixed value. When I set the caps to 15fps the results are as expected: Capturing 150 frames results in a 10 second video and takes 10 seconds.

Also the time needed to record 300 frames @30fps dropped to 20 seconds.

OK, so lets find the right settings: I played with the fixed exposure time and found out, that the longer the exposure time is, the closer I come to the 300 frames in 10 seconds mark. So setting the exposure to 300 solved my problem of recording 300 frames at 30fps in 10 seconds.

Now the really interesting thing is, that when I inspect the stream with fpsdisplaysink it shows that nearly all frames get droped:

last-message = rendered: 1, dropped: 298, fps: 0.00, drop rate: 30.07 

edit 2:

All right, when I use videorate to fix it to 30fps fpsdisplay sink shows basicaly no dropped frames and a constant rate of 30fps.

The resulting pipeline is this:

gst-launch-1.0 -v v4l2src device=/dev/video0 num-buffers=300 ! \
"video/x-raw,width=640,framerate=30/1" ! \
videorate ! "video/x-raw,framerate=30/1" ! tee name=a ! \
queue ! jpegenc ! avimux ! filesink location=output.avi a. ! \ 
queue ! fpsdisplaysink
Was it helpful?

Solution

I solved the problem by playing around with the webcam settings. Increasing the exposure to 300 instead of the default 150 did the trick for me.

Also use videorate to fix a specific framerate.

My pipeline for recording 300 frames with a resolution of 640x480 with 30fps in 10 seconds resulting in a 10 second avi looks like this:

gst-launch-1.0 -v v4l2src device=/dev/video0 num-buffers=300 ! \
"video/x-raw,width=640,framerate=30/1" ! \
videorate ! "video/x-raw,framerate=30/1" ! \
jpegenc ! avimux ! filesink location=output.avi
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top