Stream video/audio from a Raspberry PI

5,003 views
Skip to first unread message

Andy Hayward

unread,
Dec 4, 2014, 12:41:00 AM12/4/14
to reading-...@googlegroups.com
Got a couple of Raspberry PI that (amongst other duties) I'd like to stream video and audio from.

Turns out the video streaming is super easy. With a clean Raspbian installation:

$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo apt-get install vlc
$ sudo rpi-update
$ sudo reboot
$ sudo modprobe bcm2835-v4l2
$ cvlc v4l2:///dev/video0 --v4l2-width 1280 --v4l2-height 720 --v4l2-chroma h264 --sout '#rtp{sdp=rtsp://:8554/}'

(note: cvlc == /usr/bin/vlc -I "dummy" "$@")

Optionally use v4ls-ctl to control various camera settings (rotation, exposure, ...

This will create a RTSP server listening on port 8554, for any number of clients to connect to (i.e. via rtsp://10.1.10.29:8554/). CPU usage is low, ~5% with one client, ~10% with two clients.

Audio, on the other hand, I've been bashing my head against for far too long. I've got a cheap USB audio dongle (C-Media, http://www.amazon.com/dp/B001MSS6CS):

$ lsusb
...
Bus 001 Device 004: ID 0d8c:0008 C-Media Electronics, Inc.

Basic audio record/play works:

$ alsamixer  // set recording volume
$ arecord -D plughw:1,0 -f S16_LE test.wav
$ aplay -D plughw:1,0 test.wav

Note the options to select the ALSA device and format (S16_LE seems to be the only format this dongle supports).

I can also use cvlc to stream the audio only:

$ cvlc alsa://hw:1,0 --sout '#rtp{sdp=rtsp://:8555}'

Ideally I'd like to add the audio to the video stream that gets served by vlc. (using :input-slave):

$ cvlc v4l2:///dev/video0 --v4l2-width 320 --v4l2-height 256 --v4l2-chroma :h264 :input-slave=alsa://hw:1,0 --sout '#rtp{sdp=rtsp://:8554/}'

However that complains:

[0x17c7118] stream_out_rtp stream out error: cannot add this stream (unsupported codec: I420)
[0x17cd778] main decoder error: cannot create packetizer output (I420)

So I suspect I need some transcoding options here. Questions:

* does the PI have enough CPU to combine these two streams into a single container?
* anyone familiar enough with VLC to know the magic incantation to do this?

Worse case is that I have to stream the video and audio separately, and combine them at the destination. But I'd like to avoid that if possible.

Thanks!

Barnaby

unread,
Dec 4, 2014, 4:40:10 AM12/4/14
to reading-...@googlegroups.com
It is certainly possible to MUX the audio and video on the Pi, however it is a bit borderline. Don't think that is the causing your error though. Not familiar enough with VLC to be sure. Did notice "v4l2-chroma :h264" gained the colon on your second example.

This may help https://github.com/iizukanao/picam

Andy Hayward

unread,
Dec 4, 2014, 10:58:25 AM12/4/14
to reading-...@googlegroups.com
> Did notice "v4l2-chroma :h264" gained the colon on your second example.

Good catch; I'll check that tonight.


On 4 December 2014 at 02:40, Barnaby <b...@zi.is> wrote:
It is certainly possible to MUX the audio and video on the Pi, however it is a bit borderline. Don't think that is the causing your error though. Not familiar enough with VLC to be sure. Did notice "v4l2-chroma :h264" gained the colon on your second example.

This may help https://github.com/iizukanao/picam

--
You received this message because you are subscribed to the Google Groups "Reading Hackspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reading-hacksp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

DB3

unread,
Dec 5, 2014, 4:46:48 AM12/5/14
to reading-...@googlegroups.com, a...@buteo.org
You can couple the RPi with an Arduino or another like device to assist with audio. Wish the B+ had a fix for this already... 

Have you looked into the Raspivid material? 

Also, check this out:

Daniel Heinrich

unread,
Aug 1, 2016, 9:37:36 PM8/1/16
to Reading Hackspace, a...@buteo.org
I know this is old but since I spent a lot of time finding a solution, I'd like to post it here as reference for others.

It appears that VLC has problems combining both video and audio stream, but there is the possibility to stream both separately. The same can also be done with GStreamer or you can use FFmpeg to combine both streams if you're willing to compile it yourself.
The easiest solution however appeares to be the program picam that directly combines video and audio. It offers good support for a lot of streaming possibilities.

I've put all the ressources I've found on video and audio recording and streaming on a raspberry pi into a beginner-friendly post. Feedback is appreciated.

Greetings, Daniel

Jeremy Poulter

unread,
Aug 2, 2016, 2:13:42 AM8/2/16
to rLab List

Hi,

It surprises me that VLC could not do it but good work on finding an alternative solution.

Jeremy


Reply all
Reply to author
Forward
0 new messages