13

I have a logitech C920 webcam. It has the ability to directly encode the video in H264.

I want to reproduce what was done with a Beaglebone, but using a Raspberry Pi: send a H264 stream to the network. The Raspberry Pi is then only here to packetize the stream in RTP, the video compression is done by the webcam itself. The H264 mode is enforced using video4linux.

So far, and if I use a common computer with the latest version of Ubuntu, it works using VLC as a server or GStreamer. For instance, if I launch on Raspberry Pi a VLC server using the command:

cvlc --sout=#rtp{sdp=rtsp://:8554/test} 'v4l2:///dev/video0:chroma=H264:width=800:height=600:fps=30'

... and then if I read the stream with VLC on another computer, all is right.

However, if I use the raspberry Pi to send the video stream, the result is quite poor. Lots of garbage in the image as soon as something moves. Image keys are well received every 10 seconds, but in the meanwhile, it is not good enough as compared with the stream from a common computer.

I also tried the method described for the beaglebone with the provided "capture" utility: ok if I stream from a real computer, same garbage problem if I stream from a Raspberry Pi.

It is not a network problem: I did some network checks with Wireshark and the statistics of VLC, I have no packet loss. I tried with Raspbian, and Arch Linux for Raspi (gstreamer 0.10 in raspbian, gstreamer 1.0 in Arch Linux).

I do not know if it is relevant or not, but I also tested with the soft float support version of Raspbian. An update must be done first to use a 3.2 kernel ; but same problem, the video has some garbage.

Any idea on what I could do to enhance the video quality?

5
  • Try reducing the frame rate. The CPU of the rPi is very poor, so I guess transmitting a 800x600 image at 30FPS is too much. Only the new rPI camera board which is connected via the MIPI/CIS connector (instead of USB) streams 1080p at 15-30 FPS.
    – Matthias
    Jun 19, 2013 at 9:32
  • Its not FPS. The Pi can handle HD at 60FPS with no problem using the Pi Camera module. If the Logitech camera send H264 video its already encoded and the Pi needs to re boradcast the packets.. which it is entirely capable of. In fact it can rebroadcast up 6 HD@25FPS streams before it maxes out. It must be the V4L driver corrupting packets
    – Piotr Kula
    Sep 19, 2013 at 20:55
  • I know it is an old thread, but did you finally find something which works? Im trying to do something similar and stuck
    – Ajith
    Oct 6, 2014 at 11:03
  • I used a Beaglebone and it worked better. The problem was because of a bad USB driver for the RaspberryPi in Raspbian. As far as I remember, I did later tested the same system with a later version of Raspbian and I had less garbage. I may did an rpi-update (as said in one of the answer), but I do not remember well. But what is sure is the performance was better after using an updated firmware/operation system. Oct 11, 2014 at 14:11
  • Vincent, I'm getting a 'cannot open v4l2 url' error. Is this command now out of date? Mar 26, 2019 at 0:25

6 Answers 6

6

I had the same problem, found this thread when searching for a hardware encoder, not for c920 issues.

Nevertheless, execute a firmware update for the raspberry pi and the garbage should be gone

$> sudo rpi-update

I myself found the solution here: http://wiki.matthiasbock.net/index.php/Logitech_C920,_streaming_H.264#Raspberry_Pi

1
  • In order to close this question, I accept that answer. The problem was because of a broken USB driver, there was some packet loss in the USB communication. An updated system/firmware should do the trick. Oct 11, 2014 at 14:13
3

You can try and use FFMPEG. But the problem is not to use the repositories version because it is outdatted. There is a forked version that works really well.

You will have to compile it which takes 5 or so hours or download a precompiled binary.

You can then pipe the data from the V4L driver to FFMPEG with these settings. Where the -i "fifo" should just be -i to caputre the piped stream and the -f you will need to double check how to output it H264. the FLV repackages it into FLV that can be played with HTML players.

ffmpeg -y \  
  -f h264 \  
  -i "$fifo" \  
  -c:v copy \  
  -map 0:0 \  
  -f flv "$urllocal"   

or an exmaple I found that targets V4L directly but oyu have to have the camera present in /dev/video* where * is 1 or more...

ffmpeg -f video4linux2 -r 25 -s 640x480 -i /dev/video0 out.avi

the -f denotes the format to output in. It does not mean it will transcode it like H264 to FLV just gets wrapped in the FLV format. then change the address to your clients VLC player. for example -f mpegts udp:192.168.1.19:1234

VLC does not seem to work too well on the Pi. I had very little success pushing the Pi cmaera module to my PC using UDP. It worked but it was not stable.

You may also look at install nginx with rtmp module that works a treat. Look at this guide but you will need to tweak the settings a bit. You then connect your VLC player to the nginx-rtmp stream and it will work like a charm.

1
  • 1
    Which forked version is the one that works well?
    – notbrain
    Feb 22, 2014 at 20:42
1

This seems to work for me @ least... cvlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=640 :v4l2-height=480 --sout="#transcode{vcodec=h264,vb=800,scale=1,acodec=mp4a,ab=128,channels=2,samplerate=44100}:rtp{sdp=rtsp://:8554/live.ts}" -I dummy

1

I posted a possible solution in raspberry forum using a lightweight RTSP server based on live555 that capture H264 from a V4L2 driver. It is available from github v4l2rtspserver

This was done for the raspicamera, but it should works with any V4L2 device that provide H264.

0

Try with larger buffer on the client displaying the video. For me there is dramatic difference between 1000ms buffer and 200ms buffer. 5000ms buffer looks better than 1000ms buffer.

:network-caching=2000

1
  • It should work with 0 caching with the odd jittering on LAN.I got the Pi camera module to work like that with no problem.
    – Piotr Kula
    Sep 19, 2013 at 20:57
-1

If I understood your situation well, you want Raspberry to transcode video to H264? I think that is why you get bad performance, because VLC is using software encoding and Raspberryis not powerful for that task.

I would suggest to to try with Gstreamer and gst-omx plugins. There is element for hardware video encoding that would make good server from your Raspberry.

2
  • 1
    As he said, the Logitech camera provides H.264 already. So the rPi is only transporting frames but not doing any encoding.
    – Matthias
    Jun 19, 2013 at 9:25
  • He is not transcoding. Just rebroadcasting the data. As in it uses stream directly.
    – Piotr Kula
    Sep 19, 2013 at 20:56

Your Answer

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

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