7

I've read multiple threads about streaming a Logitech C920 Webcam via raspberry pi with cvlc using basically this command:

cvlc v4l2:///dev/video1:chroma=h264:width=800:height=600 --sout '#standard{access=http,mux=ts,dst=localhost:8080,name=stream,mime=video/ts}' -vvv

Taken the info from this site: https://wiki.matthiasbock.net/index.php/Logitech_C920,_streaming_H.264

When I use this command, I don't get any output with the Logitech C922. VLC fails to get the h264 stream and says that it only gets the YUYV Stream, which is not compliant to the resulting ts stream. (The h264 stream seems to be transported inside the mjpeg stream)

The Problem is also covered in this recent Blog Post: http://w2017.pl/logitech-vlc-ffmpeg-c922-streaming/

Is there some way around that? I already have audio working with

:input-slave="alsa://hw:1,0" --sout '#transcode{acodec=a52,ab=32}'

Thanks for any hints on how and when this will be resolved.

Output of v4l2-ctl --list-formats:

ioctl: VIDIOC_ENUM_FMT
Index       : 0
Type        : Video Capture
Pixel Format: 'YUYV'
Name        : YUYV 4:2:2

Index       : 1
Type        : Video Capture
Pixel Format: 'MJPG' (compressed)
Name        : Motion-JPEG

Output of v4l2-ctl --all:

Driver Info (not using libv4l2):
Driver name   : uvcvideo
Card type     : C922 Pro Stream Webcam
Bus info      : usb-3f980000.usb-1.4
Driver version: 4.4.50
Capabilities  : 0x84200001
    Video Capture
    Streaming
    Extended Pix Format
    Device Capabilities
Device Caps   : 0x04200001
    Video Capture
    Streaming
    Extended Pix Format
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
    Width/Height  : 800/600
    Pixel Format  : 'YUYV'
    Field         : None
    Bytes per Line: 1600
    Size Image    : 960000
    Colorspace    : SRGB
    Flags         :
Crop Capability Video Capture:
    Bounds      : Left 0, Top 0, Width 800, Height 600
    Default     : Left 0, Top 0, Width 800, Height 600
    Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 800, Height 600
Selection: crop_bounds, Left 0, Top 0, Width 800, Height 600
Streaming Parameters Video Capture:
    Capabilities     : timeperframe
    Frames per second: 24.000 (24/1)
    Read buffers     : 0
                     brightness (int)    : min=0 max=255 step=1 default=-8193 value=128
                       contrast (int)    : min=0 max=255 step=1 default=57343 value=128
                     saturation (int)    : min=0 max=255 step=1 default=57343 value=128
 white_balance_temperature_auto (bool)   : default=1 value=1
                           gain (int)    : min=0 max=255 step=1 default=57343 value=0
           power_line_frequency (menu)   : min=0 max=2 default=2 value=2
      white_balance_temperature (int)    : min=2000 max=6500 step=1 default=57343 value=4000 flags=inactive
                      sharpness (int)    : min=0 max=255 step=1 default=57343 value=128
         backlight_compensation (int)    : min=0 max=1 step=1 default=57343 value=0
                  exposure_auto (menu)   : min=0 max=3 default=0 value=3
              exposure_absolute (int)    : min=3 max=2047 step=1 default=250 value=250 flags=inactive
         exposure_auto_priority (bool)   : default=0 value=1
                   pan_absolute (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                  tilt_absolute (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                 focus_absolute (int)    : min=0 max=250 step=5 default=8189 value=0 flags=inactive
                     focus_auto (bool)   : default=1 value=1
                  zoom_absolute (int)    : min=100 max=500 step=1 default=57343 value=100
                      led1_mode (menu)   : min=0 max=3 default=3 value=0
                 led1_frequency (int)    : min=0 max=255 step=1 default=0 value=24
                     brightness (int)    : min=0 max=255 step=1 default=-8193 value=128
                       contrast (int)    : min=0 max=255 step=1 default=57343 value=128
                     saturation (int)    : min=0 max=255 step=1 default=57343 value=128
 white_balance_temperature_auto (bool)   : default=1 value=1
                           gain (int)    : min=0 max=255 step=1 default=57343 value=0
           power_line_frequency (menu)   : min=0 max=2 default=2 value=2
      white_balance_temperature (int)    : min=2000 max=6500 step=1 default=57343 value=4000 flags=inactive
                      sharpness (int)    : min=0 max=255 step=1 default=57343 value=128
         backlight_compensation (int)    : min=0 max=1 step=1 default=57343 value=0
2
  • And you have updated the firmware ? sudo apt-get install rpi-update raspi-config, sudo rpi-update
    – MatsK
    Commented Sep 7, 2017 at 22:35
  • yes - newest firmware & up to date system
    – Gotschi
    Commented Sep 7, 2017 at 22:51

3 Answers 3

7

The problem is that the C922 does not advertise its H264 stream over UVC whereas the C920 does. This is because Logitech did not want to enable general use of the H264 for the C922, but instead wanted you to buy the camera with something like Skype which knows internally how to get hold of the data. The reason for this peculiar setup was to enable the camera to display high-resolution image previews on the local machine during video-conferencing; compatible applications send the H264 over the network but display the local camera preview using the MJPEG stream.

Technically speaking, the H264 data does come out of the C922, but you have to stream it as MJPEG. It appears that, parsing each MJPEG frame, the H264 is attached to each still image as an JFIF extension packet (e.g. APP1). Check the JFIF specification for details.

If you can parse the MJPEG frame by frame and access the JFIF packets individually (an open source library like libjpeg enables this) then you can get hold of the data.

Given it's a non-standard solution to a non-standard way of streaming H264 from a web camera, for application robustness and future-compatibility with other cameras, I would stick to coding against the C920.

1
  • 1
    Thank you Fred for the explanation. It seems that Logitech applied the same change for their refresh model of the C920. Bad news of the week-end for me... See stackoverflow.com/a/58676573 for other user having the same issue. Regards.
    – Kyrille
    Commented Nov 3, 2019 at 1:02
2

You may have to force the stream mode for your camera. First chek if MPEG or H264 is really available : v4l2-ctl --list-formats

Using v4l2-ctl --all you will see the current resolution and pixel Format for your camera.

To define another resolution and/or pixelFormat, use this command :

v4l2-ctl --device /dev/video0 --set-fmt-video=width=1280,height=960,pixelformat=MJPG

Once this command executed, v4l2-ctl --all should show you :

Format Video Capture:

Width/Height : 1280/960

Pixel Format : 'MJPG'

Wich demonstrate that our previous command as correctly worked, and that the camera will output MJPG instead of YUYV. If you see that your camera is back in YUYV format, it may be because you ask for an unsupported format (see v4l2-ctl --list-formats-ext).

Launch your video client, and then run v4l2-ctl --all again.

If you see that your camera is back in YUYV format, it's because VLC rewrite camera parameters, and then it's command-line options should be tweaked to ask for MJPG format.

If your camera is still in MPEG, that means that VLC should have correctly received MJPG stream, and struggle with the h264 decoding part.

Edit : As pointed in your link, "H264 is still there, but is muxed into MJPEG stream (meaning MJPEG is a container with both still frames and H264 encoded video)". So having your camera in MJPG mode seems to be a prerequite.

Now, following w2017's advice, let's try to create a named pipe (is this really different from command-line pipe ? I don't know !):

mkfifo /tmp/video.mpg

Stream the camera in : v4l2-ctl --stream-mmap=3 --stream-to=/tmp/video.avi

And read from this named pipe as it was a video file, with cvlc or omxplayer :

omxplayer /tmp/video.mpg

7
  • thanks for your suggestion, but it's the driver which keeps me from using h264 - because as i described above the stream is encapsulated in the mjpeg stream. thanks anyway
    – Gotschi
    Commented May 31, 2017 at 8:33
  • Can you post the result of v4l2-ctl --list-formats and the pixel Format part of the v4l2-ctl --all, for further investigation ? Commented May 31, 2017 at 8:44
  • The results don't mean anything as long as V4L cannot access the H264 stream from the cam via the driver. posted them in the original post
    – Gotschi
    Commented May 31, 2017 at 9:06
  • Added some informations in the answer Commented May 31, 2017 at 9:47
  • 1
    Added some notes, your problem is interesting :) Commented Jun 1, 2017 at 19:29
1

There is a H264 UVC extension, where you can enable muxing the H264 stream into the MJPG stream. After that, you can read the H264 frames from the APP4 JPEG markers.

You can read about it from USB_Video_Payload_H 264_1 0.pdf (https://www.usb.org/document-library/video-class-v11-document-set)

Linux supports the extension units: https://www.kernel.org/doc/html/v4.9/media/v4l-drivers/uvcvideo.html

But Logitech says Goodbye to In-Camera Hardware Encoding, so it doesn't work with newer Logitech cameras, except the business class ones (c925e, c930e).

I use this extension unit in my app called fmp4streamer. It provides MP4 (H264) stream over http.

There is a uvch264src source in the gstreamer too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.