jim1961
Posts: 4
Joined: Sun Dec 17, 2017 8:31 pm

Adding Audio to UV4L Video Stream

Sun Jul 08, 2018 10:55 pm

Hi,
I have an ongoing (hobby) project to use RPi's for bird monitoring and research studies. I started this project last fall and was able to get an RPi3 with PiCam camera module to stream video (via wifi) to a security camera client (iSpy). This set-up worked very well as we could use iSpy to monitor the inside of a birdhouse and also automatically capture video (motion detection) to the PC hard drive. We were able to monitor (record) a chickadee mated pair produce eggs and fledge 5 young birds. COOL!

I spent a lot of time trying to figure out the best video streamer to use. I was a total "noob" then, and only slightly over that level now. Lol. I was proud though that I got where I am today without posting a question here - but now I am stumped trying to figure out how to add audio (using a USB mic).

I settled on setting up a UV4L Server and this works very well for the wifi video stream:

Code: Select all

sudo uv4l -nopreview --auto-video_nr --driver raspicam --encoding mjpeg --width 640 --height 480 --framerate 3 --bitrate 100000 --server-option '--port=9090' --server-option '--max-queued-connections=30' --server-option $
I recently purchased a VA Links USB Microphone and the RPi recognizes it (hw:1,0) .

Now my major confusion is how to get the RP1 to stream the audio from the mike. The iSpy software has settings for an external networked mike, and FFMPEG is one of the options and I think likely the best choice (i can set a url in the microphone settings).

When I set up UV4l for video it was straightforward about the settings for video server (and I believe it uses FFMPEG underneath), but I don't see any options for an Audio Server. I have read posts suggesting WebRTC but my impression is that it is used for streaming to browsers. I want to use iSpy for listening and recording the audio from inside the birdhouse. So I THINK I need to configure FFMPEG for audio.

I have been testing FFMPEG commands and admit the "output" section confuses me. This is one I tried:

Code: Select all

sudo ffmpeg -ar 44100 -ac 1 -acodec pcm_s16le -f alsa -thread_queue_size 2048 -i hw:1,0 -thread_qu                                                                                                        eue_size 2048 -r 10 -i http://192.168.1.58:9090/stream/
Note that 192.168.1.58 is the IP of the RPi3.

This is the result from command line:
sudo ffmpeg -ar 44100 -ac 1 -acodec pcm_s16le -f alsa -thread_queue_size 2048 -i hw:1,0 -thread_qu eue_size 2048 -r 10 -i http://192.168.1.58:9090/stream/
ffmpeg version 3.2.10-1~deb9u1+rpt1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1) 20170516
configuration: --prefix=/usr --extra-version='1~deb9u1+rpt1' --toolchain=hardened --libdir=/usr/lib/arm-linux-gnuea bihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdi o --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libg me --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse -- enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable -libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx2 65 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx-rpi --enable-mmal --enable-openal --enable-opengl - -enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable -libx264 --enable-shared
libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, alsa, from 'hw:1,0':
Duration: N/A, start: 1531085010.899271, bitrate: 705 kb/s
Stream #0:0: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s
[http @ 0x231a440] HTTP error 404 Not Found
http://192.168.1.58:9090/stream/: Server returned 404 Not Found
It seemed to like everything except the output to the IP and file. My understanding is that the second "-i" is identifying the Output.

So my questions:
1. Am I thinking correctly that FFMPEG is the best choice for adding an audio stream?

a. If FFMPEG can work, what am I missing in setting the Output?

b. Is there a better way than FFMPEG? I really don't want to scrap the UV4l Server as it works very well.

Thanks,
Jim

jim1961
Posts: 4
Joined: Sun Dec 17, 2017 8:31 pm

Re: Adding Audio to UV4L Video Stream

Tue Jul 10, 2018 11:39 am

Did I post this in the wrong forum? Any advice appreciated.
Jim

rabiach786
Posts: 3
Joined: Thu Sep 06, 2018 8:53 am

Re: Adding Audio to UV4L Video Stream

Sat Sep 29, 2018 5:38 am

Dear Jim,
I am also working with Raspberry Pi 3 and my project has a similarity with your project. I also have to stream live audio and video from Raspberry Pi 3 to Windows 10 PC and from PC to Raspberry Pi too.It is a bidirectional communication. Using UV4L WebRTC, video is streaming very well from one side but I am not able to get audio from USB Mic to PC. I have done all the recommended settings except to buy a secured (HTTPS) licence. Only Chrome can stream video, Mozilla Firefox is not showing any video.
second problem is when I check the option to 'Cast local Audio/Video sources to remote peer', I got an error 'Check media device, permissions on media and origin'.

Jim, have you find any solution for audio transmit or not?
Can anyone help us in this regard?

Rabia

jahau
Posts: 12
Joined: Thu Dec 20, 2018 11:32 am

Re: Adding Audio to UV4L Video Stream

Sun Jan 20, 2019 5:08 pm

Me too, as stated in https://www.raspberrypi.org/forums/view ... 6#p1419086 I get the similar error. Settings are pretty much out of the box. I've just followed the tutorial here: https://www.linux-projects.org/uv4l/installation/

If you succeed with the mentioned tutorial, please let me know. Thanks!

RpiName
Posts: 712
Joined: Sat Jul 06, 2013 3:14 am

Re: Adding Audio to UV4L Video Stream

Tue Jan 22, 2019 8:57 am

rabiach786 wrote:
Sat Sep 29, 2018 5:38 am
I have done all the recommended settings except to buy a secured (HTTPS) licence.
there is no such thing as "HTTPS license to buy". Just enable HTTPS according to the doc, if you want/need it.
Last edited by RpiName on Tue Jan 22, 2019 8:59 am, edited 1 time in total.

RpiName
Posts: 712
Joined: Sat Jul 06, 2013 3:14 am

Re: Adding Audio to UV4L Video Stream

Tue Jan 22, 2019 8:58 am

jahau wrote:
Sun Jan 20, 2019 5:08 pm
If you succeed with the mentioned tutorial, please let me know. Thanks!
what's the output of arecord -L ?

jahau
Posts: 12
Joined: Thu Dec 20, 2018 11:32 am

Re: Adding Audio to UV4L Video Stream

Fri Feb 01, 2019 6:09 pm

null
Discard all samples (playback) or generate zero samples (capture)
default
sysdefault:CARD=Loopback
Loopback, Loopback PCM
Default Audio Device
front:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Front speakers
surround21:CARD=Loopback,DEV=0
Loopback, Loopback PCM
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Loopback,DEV=0
Loopback, Loopback PCM
4.0 Surround output to Front and Rear speakers
surround41:CARD=Loopback,DEV=0
Loopback, Loopback PCM
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Loopback,DEV=0
Loopback, Loopback PCM
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Loopback,DEV=0
Loopback, Loopback PCM
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Loopback,DEV=0
Loopback, Loopback PCM
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
dmix:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Direct sample mixing device
dmix:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Direct sample mixing device
dsnoop:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Direct sample snooping device
dsnoop:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Direct sample snooping device
hw:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Direct hardware device without any conversions
hw:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Direct hardware device without any conversions
plughw:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Hardware device with all software conversions
plughw:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Hardware device with all software conversions

RpiName
Posts: 712
Joined: Sat Jul 06, 2013 3:14 am

Re: Adding Audio to UV4L Video Stream

Fri Feb 01, 2019 7:32 pm

jahau wrote:
Fri Feb 01, 2019 6:09 pm
null
Discard all samples (playback) or generate zero samples (capture)
default
sysdefault:CARD=Loopback
Loopback, Loopback PCM
Default Audio Device
front:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Front speakers
surround21:CARD=Loopback,DEV=0
Loopback, Loopback PCM
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Loopback,DEV=0
Loopback, Loopback PCM
4.0 Surround output to Front and Rear speakers
surround41:CARD=Loopback,DEV=0
Loopback, Loopback PCM
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Loopback,DEV=0
Loopback, Loopback PCM
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Loopback,DEV=0
Loopback, Loopback PCM
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Loopback,DEV=0
Loopback, Loopback PCM
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
dmix:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Direct sample mixing device
dmix:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Direct sample mixing device
dsnoop:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Direct sample snooping device
dsnoop:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Direct sample snooping device
hw:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Direct hardware device without any conversions
hw:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Direct hardware device without any conversions
plughw:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Hardware device with all software conversions
plughw:CARD=Loopback,DEV=1
Loopback, Loopback PCM
Hardware device with all software conversions
so you want to record from the loopback device? follow the instructions for the audio settings in this example:

https://www.linux-projects.org/uv4l/tut ... d-sharing/

jahau
Posts: 12
Joined: Thu Dec 20, 2018 11:32 am

Re: Adding Audio to UV4L Video Stream

Sat Feb 02, 2019 6:46 am

I did as the tutorial suggested, https://www.linux-projects.org/home/wp- ... sound.conf. I can hear the audio on the Raspberry (I have speakers for testing purposes attached to it) but cannot hear any audio from the Chrome (Raspberry/WebRTC is accessible in the address http://192.168.1.4:9080/stream/webrtc).

Additionally it's said here https://www.linux-projects.org/uv4l/installation/ to install uv4l-uvc. Is this really needed? It seems to create separate configuration file /etc/uv4l/uv4l-uvc.conf and includes same parameters as /etc/uv4l/uv4l-raspidisp.conf. This is very confusing.

RpiName
Posts: 712
Joined: Sat Jul 06, 2013 3:14 am

Re: Adding Audio to UV4L Video Stream

Sat Feb 02, 2019 12:02 pm

jahau wrote:
Sat Feb 02, 2019 6:46 am
I did as the tutorial suggested, https://www.linux-projects.org/home/wp- ... sound.conf. I can hear the audio on the Raspberry (I have speakers for testing purposes attached to it) but cannot hear any audio from the Chrome (Raspberry/WebRTC is accessible in the address http://192.168.1.4:9080/stream/webrtc).

Additionally it's said here https://www.linux-projects.org/uv4l/installation/ to install uv4l-uvc. Is this really needed? It seems to create separate configuration file /etc/uv4l/uv4l-uvc.conf and includes same parameters as /etc/uv4l/uv4l-raspidisp.conf. This is very confusing.
uv4l-uvc and uv4l-raspidisp are two separate modules for different purposes as their names imply. it's hard to understand what you are trying to do as you have both installed apparently. secondly, from the output of arecord -L you only have a loopback device you can capture the audio from and no e.g. external usb input audio card with mic. I asked if this is what you want but got no answer yet (just a broken link to the doc you are trying to follow).

jahau
Posts: 12
Joined: Thu Dec 20, 2018 11:32 am

Re: Adding Audio to UV4L Video Stream

Sat Feb 02, 2019 12:41 pm

I'm playing the audio in the raspberry (not from usb) and trying to listen to that audio from different machine using browser. Right?

Why do I have both installed? I just followed the instructions here: https://www.linux-projects.org/uv4l/installation/

The broken link was supposed to be this: https://www.linux-projects.org/home/wp- ... sound.conf. This was from the other article linked in https://www.linux-projects.org/uv4l/tut ... d-sharing/

RpiName
Posts: 712
Joined: Sat Jul 06, 2013 3:14 am

Re: Adding Audio to UV4L Video Stream

Sat Feb 02, 2019 6:12 pm

jahau wrote:
Sat Feb 02, 2019 12:41 pm
I'm playing the audio in the raspberry (not from usb) and trying to listen to that audio from different machine using browser. Right?

Why do I have both installed? I just followed the instructions here: https://www.linux-projects.org/uv4l/installation/
my best advice is that you restart from scratch (from a fresh Stretch image) by exactly following the steps in:

https://www.linux-projects.org/uv4l/tut ... d-sharing/

by "exactly" I exactly mean EXACTLY (e.g. there is no mention of uv4l-uvc and apparently you do not need it for your purposes). Make it work. Once you are at that point I can help you to eventually customize UV4L further.

jahau
Posts: 12
Joined: Thu Dec 20, 2018 11:32 am

Re: Adding Audio to UV4L Video Stream

Mon Mar 04, 2019 7:04 pm

I've done now everything exactly as in the instructions. Still not working BUT should I use something else for the webrtc-recdevice-index=14 since now this is pointing to plughw since I want to hear just the stuff played on the pi itself (not plugged from usb)? Belows is the arecord configuration currently available in the pi. Thanks!

pi@system:~ $ arecord -L | grep CARD
sysdefault:CARD=Loopback
front:CARD=Loopback,DEV=0
surround21:CARD=Loopback,DEV=0
surround40:CARD=Loopback,DEV=0
surround41:CARD=Loopback,DEV=0
surround50:CARD=Loopback,DEV=0
surround51:CARD=Loopback,DEV=0
surround71:CARD=Loopback,DEV=0
dmix:CARD=Loopback,DEV=0
dmix:CARD=Loopback,DEV=1
dsnoop:CARD=Loopback,DEV=0
dsnoop:CARD=Loopback,DEV=1
hw:CARD=Loopback,DEV=0
hw:CARD=Loopback,DEV=1
plughw:CARD=Loopback,DEV=0
plughw:CARD=Loopback,DEV=1

jim1961
Posts: 4
Joined: Sun Dec 17, 2017 8:31 pm

Re: Adding Audio to UV4L Video Stream

Sun May 05, 2019 6:25 pm

Thank you to all those who replied. :D

I did successfully add an audio stream using ffmpeg. So now we are able to view the live video feed (PiCam) and listen to the live audio (USB mic) using our security system PC client (iSpy). iSPy will also record both the video stream and audio upon an alarm (motion in this case).

Code: Select all

ffmpeg -ar 8000 -ac 1 -f alsa -i hw:1,0 -acodec mp2 -b:a 128k -f rtp rtp://192.168.1.78:4444 &
What I failed to realize is that the IP address above needed to be where I wanted to send the audio (PC client IP in this case). Then in the iSpy microphone settings I had to enter the Pi IP as the source. Simple, but darn took a long time for me to "get" that. Much different than the UV4L settings.

Let me know if anyone is interested in viewing a birdhouse video. This year it looks like we will have a house wren nesting. Last year it was chickadees.

Jim

lackdaz
Posts: 2
Joined: Fri Sep 14, 2018 3:24 am

Re: Adding Audio to UV4L Video Stream

Fri Jun 07, 2019 9:31 am

Hey Jim! Can I contact you over some of the specifics of what you've done with your setup? I'm trying to monitor my parrot (with an infra-red camera and audio) and I'm starting to think that we might be heading down parallels here.

Regards,
Seth

Return to “Camera board”