How to use a Logitech C920 webcam with 1080p resolution at 30fps?

I’m trying to fetch frames from a Logitech C920 webcam at 1080p and 30fps it doesn’t work with the default ofVideoGrabber.

I’ve googled a bit and this post seems to explain what’s going on:

The Logitech C920 only provides 30fps at 1080p with applications that supports H.264 directly, and can pull in the H.264 stream directly from the camera. The C920 does on-board H.264 compression, but most applications don’t support pulling the compressed stream straight from the camera; instead, they have to decompress then re-compress the stream, dropping the framerate.

I’m using Windows 8 and I’ve noticed the logitech software can record 1080p at 30fps with no delay.
Is it possible to talk to the logitech driver and fetch the h264 frames directly from openframeworks ?
If so, how ?

you could try ofxGStreamer https://github.com/arturoc/ofxGStreamer

gstreamer should be able to decompress h264

actually scratch that, gstreamer won’t be able to grab video from a camera in windows yet

I’ve used that webcam on Linux to directly stream the 1080p h264 stream muxed in FLV to Twitch. I did this on a raspberry pi and works great! I used V4L2 for this. At the time there were some issues with the UVC (usb) module but haven’t checked that in a couple of months. The problems was that sometimes when I closed and restarted the application my keyboard didn’t work anymore (?). Someone told me this may be caused because the C920 didn’t follow the USB UVC specs correctly.

But it indeed depends on what you want to do; but my I think for now you maybe better implement the webcam API of the OS directly.

roxlu

Thanks @arturo @roxlu.

I’ve done more snooping around and a few more tests.

I’ve been tinkering with VLC using DirectShow as source:
MRL: dshow://
options: :dshow-vdev=Logitech HD Pro Webcam C920 :dshow-adev=none :dshow-size=1920x1080 :live-caching=10

but it’s super slow and does not display at 1080p

When I use GraphEdit (from the Windows 8 DirectShow SDK) the preview is very responsive, but I can’t change the capture pin to use MJPG 1080p @30FPS
and I’m sttill missing a second Capture pin which is probably H264.

I’ve also tried the cam on a mac like so:

  • using OpenCV’s VideoCapture class in c++ (I think it uses ffmpeg behind the scenes) > I get about 12/15fps with 1080p even though I’ve tried setting H264 or MJPG codecs
  • using VLC/open capture > I get smooth/fluid video 1080p (might actually be close to 30fps, way better than what I get with opencv) but it’s a few frames behind

For reference here’s my OpenCV test:

#include<opencv2/opencv.hpp>
#include<iostream>

using namespace std;
using namespace cv;
 
int main(int argc, char *argv[])
{
    Mat frame;
 
    VideoCapture cap(0);
    cap >> frame;
    cap.set(CV_CAP_PROP_FOURCC,CV_FOURCC('H','2','6','4'));
//    cap.set(CV_CAP_PROP_FOURCC,CV_FOURCC('M','J','P','G'));
    cap.set(CV_CAP_PROP_FRAME_WIDTH,1920);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT,1080);
    cap.set(CV_CAP_PROP_FPS, 30);
 
    namedWindow("Frame");
 
    int f = 0;
    bool rec = false;
 
    time_t start,end;
    time(&start);
    int counter=0;
 
    for(;;)
    {
        cap >> frame;
 
        if(rec) {
            ostringstream filename;
            filename << "frame" << f << ".png";
            imwrite(filename.str().c_str(),frame);
            f++;
            ellipse( frame, Point( 100, 100 ),Size( 50,50),0, 0,360,Scalar( 0, 0, 255 ),20,8 );
        }
        imshow("Frame",frame);
 
        time(&end);
        ++counter;
        double sec=difftime(end,start);
        double fps=counter/sec;
        printf("\n%lf fps",fps);
 
        if(waitKey(30) == 27) break;
        if(waitKey(30) == 'r') rec = !rec;
    }
    return 0;
}

Also had a look at how ofVideoGrabber works and the DirectShow grabber is actually using @theo’s videoInput library (https://github.com/ofTheo/videoInput). My hunch is I’ll need to use DirectShow to access the camera but use the correct H264 filter (which I assume is the one used by Skype and the Logitech Webcam Software). At the moment I have no clue how do to that, so even a minimal example would help a lot.

I’ll also test V4L2 on osx, hopefully that would be another solution.

Thanks again,
George

Got an update, I’ve managed to get a 1080p stream in oF at 30fps but using Windows 7.

I’m not sure how/why it works. Guessing something related to the driver.
Same code what was barely fetching ~15fps in windows 8 is running smoothly on windows 7
without any change in code.

If there are any suggestions on how get 30fps on other operating systems, that would be nice.

Thanks again for the suggestions.

Hello,
I have been working with this camera for some time on a university project. Last year mostly on Linux (beagleboard) I managed to get some results but nothing major and due to deadlines ended up grabbing the mpej stream.

I have now re tackled this and am trying to grab the H264 stream but this time on windows 8. So far mixed results from VLC and Graphedit. I believe I managed to get the correct pin chosen in graph edit and was getting a stream but am not 100% sure as I am totally new to graph edit. In VLC no luck. I tried using windows MMF (Microsoft Media Foundation, replaces DirectShow, ) and had mixed results. I could see the pin (i think) but could not use it. Please let me know if you find a way to access the H264 stream as I desperately require it.

Hi,

Thanks for sharing this. I’m guessing you were using V4L on the beagle board.

I’ve tried VLC and Graph Edit too. VLC looked just as slow(~12-15fps). I’ve tried to replicate this GraphEdit from the logitech forums:
http://forums.logitech.com/t5/image/serverpage/image-id/5383i6EC6F790CF88787C/image-size/original/is-moderation-mode/false?v=mpbl-1&px=-1

but I could only see a single pin on the logitech camera node. I’m guessing for some reason I was missing the H264 node. Did you get 2 pins in GraphEdit ? Did you get that by default( if not, how did you enable the 2nd one) ?

If you need need to get a better frame rate right now, I recommend using a machine with Windows 7 and the C920 Windows 7 driver installed.

If anyone is still looking for how to do it in VLC, I got it to work for Logitech C930e which in theory should be very similar to C920.

Here are the steps:

  1. Make sure webcam is connected to computer and functioning.
  2. Launch VLC and click on Media and then on Open Capture Device.
  3. In the dialog box that opens, set Capture mode to DirectShow.
  4. Choose your webcam’s name from the Video device name and do the same for Audio device name drop down lists.
  5. In Video size, put in the desired display resolution. I put in 1920x1080 as that was the max supported for C930e.
  6. Now click on Advanced options and set the following values:
  7. Set aspect ratio to 4:3 or 16:9 as desired.
  8. Set Video input frame rate to 30.00 as that is the max C930e supports.(I think)
  9. Click on Ok.
  10. Now click on Play and you should have a live video feed displayed in VLC.
  11. You can click on Tools and then click on Codec Information to get detailed codec and resolution data.

Do note that Directshow is SLOW at showing you the video feed. I monitored that it got data from my webcam only at 4 MB/sec over USB whereas Skype’s built in video preview in the settings was able to do that much faster at 14 MB/s.

Hope this helps someone who was looking for a quick way to analyse the output of their webcams without installing extra bloatware.

1 Like