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

Turn HDMI-out into a V4L2-compliant capture device with UV4L

Tue Oct 25, 2016 9:09 am

As promised by http://linux-projects some time ago, here is the announcement of a new driver and a link to a DEMO:
The raspidisp driver turns a given HDMI output source into a Video4Linux-compliant device (such as a camera) that can capture the images coming from that source. The UV4L Streaming Server itself makes use of this driver to give the user full control of the Raspberry Pi by allowing to see the what’s on the screen and send keyboard or mouse inputs to from within a web page in a PC browser. [...]
DEMO:
https://youtu.be/wthS8TPk2DE

sorbonne
Posts: 49
Joined: Thu Jan 14, 2016 10:25 am

Re: Turn HDMI-out into a V4L2-compliant capture device with

Tue Nov 01, 2016 5:48 pm

This is impressive. Do you know if it is possible to capture and redirect audio-out too from the Raspberry Pi to the browser?

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

Re: Turn HDMI-out into a V4L2-compliant capture device with

Tue Nov 01, 2016 7:54 pm

sorbonne wrote:This is impressive. Do you know if it is possible to capture and redirect audio-out too from the Raspberry Pi to the browser?
UV4L can capture audio from any input source. You can create an ALSA "loopback device" from audio-out and use it with UV4L as input. And yes, audio can be streamed in real-time along with the video track to any browser.

jgreen71
Posts: 92
Joined: Wed May 01, 2013 12:29 pm
Location: Clarksville, IN

Re: Turn HDMI-out into a V4L2-compliant capture device with

Wed Nov 02, 2016 12:25 pm

So I've watched the YouTube clip, and skimmed through the http://www.linux-projects.org/uv4l site, and the one thing I've not been able to find...

What's the hardware set up for this project?

I get that there is a RPi, and another computer, but what is the connectivity? The RPi's HDMI-out to the PC's... what? Is there a list of the bits and bobs I would need to connect to try this out on my own?

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

Re: Turn HDMI-out into a V4L2-compliant capture device with

Wed Nov 02, 2016 2:24 pm

jgreen71 wrote:What's the hardware set up for this project?

I get that there is a RPi, and another computer, but what is the connectivity? The RPi's HDMI-out to the PC's... what? Is there a list of the bits and bobs I would need to connect to try this out on my own?
There's no special hardware involved. As you said, on the left side you have a PC with a browser, while on the right side you have a standard Raspberry Pi 3 connected to a standard Touchscreen and WITHOUT keyboard attached (see below). They are in the same LAN. In this scenario the PC is a client and the Raspberry Pi is a server.

The Raspberry Pi runs the UV4L Streaming Server which captures whatever goes through HDMI-out and streams it to the browser PC on request. No browser plugin's are necessary.

(Internally the Streaming Server makes use of the UV4L raspidisp driver which creates a virtual input Video4Linux-compliant device from HDMI-out.)

In the clip you can also see another interesting thing, that is the possibility of sending PC keyboard inputs towards the Raspberry Pi in order to control it from with in the browser. In the clip this possibility is used to login in the Raspberry Pi and run omxplayer which plays a video clip.

To test the above, just install UV4L according the installation instructions, reboot and connect to your Rpi with the browser: http://yourrpi:9080/stream/webrtc
http://www.linux-projects.org/uv4l/installation/

No configuration is required.

mattmiller
Posts: 2112
Joined: Thu Feb 05, 2015 11:25 pm

Re: Turn HDMI-out into a V4L2-compliant capture device with

Wed Nov 02, 2016 10:07 pm

Just tried this on a PiZero but no luck - documentation talks about Pi2 onwards for WebRTC so that may be the issue (Or I might not have followed the instructions properly of course)

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

Re: Turn HDMI-out into a V4L2-compliant capture device with

Wed Nov 02, 2016 11:05 pm

mattmiller wrote:Just tried this on a PiZero but no luck - documentation talks about Pi2 onwards for WebRTC so that may be the issue
exactly, Pi Zero is not supported.

mattmiller
Posts: 2112
Joined: Thu Feb 05, 2015 11:25 pm

Re: Turn HDMI-out into a V4L2-compliant capture device with

Thu Nov 03, 2016 6:06 pm

Shame - I was really hoping to be able to use this as to remotely view/use Minecraft

Can't win em all

jgreen71
Posts: 92
Joined: Wed May 01, 2013 12:29 pm
Location: Clarksville, IN

Re: Turn HDMI-out into a V4L2-compliant capture device with

Fri Nov 04, 2016 1:42 pm

RpiName wrote:They are in the same LAN.
Ah, this was the piece I was missing.

Thanks.

sorbonne
Posts: 49
Joined: Thu Jan 14, 2016 10:25 am

Re: Turn HDMI-out into a V4L2-compliant capture device with

Sun Nov 06, 2016 3:30 pm

RpiName wrote:UV4L can capture audio from any input source. You can create an ALSA "loopback device" from audio-out and use it with UV4L as input. And yes, audio can be streamed in real-time along with the video track to any browser.
Awsome, I confirm it works! I could get real-time audio - video to my smartphone and could even control the Raspberry Pi with the Android virtual keyboard, with both Chrome and Firefox (although it is not really clear that you have to touch the "send" input text item in the page to make the virtual keyboard appear).

For those who are interested in creating an alsa loopback device, here is what I have put in /etc/modules /etc/asound.conf in my Raspbian Jessie:

/etc/modules

Code: Select all

snd-aloop
/etc/asound.conf

Code: Select all

pcm.!default {
  type asym
  playback.pcm "LoopAndReal"
  capture.pcm "looprec"
}

pcm.looprec {
    type hw
    card "Loopback"
    device 1
    subdevice 0
}

pcm.LoopAndReal {
  type plug
  slave.pcm mdev
  route_policy "duplicate"
}

pcm.mdev {
  type multi
  slaves.a.pcm pcm.MixReale
  slaves.a.channels 2
  slaves.b.pcm pcm.MixLoopback
  slaves.b.channels 2
  bindings.0.slave a
  bindings.0.channel 0
  bindings.1.slave a
  bindings.1.channel 1
  bindings.2.slave b
  bindings.2.channel 0
  bindings.3.slave b
  bindings.3.channel 1
}

pcm.MixReale {
  type dmix
  ipc_key 1024
  slave {
    pcm "hw:0,0"
    rate 48000
    #rate 44100
    periods 128
    period_time 0
    period_size 1024 # must be power of 2
    buffer_size 8192
  }
}

pcm.MixLoopback {
  type dmix
  ipc_key 1025
  slave {
    pcm "hw:Loopback,0,0"
    rate 48000
    #rate 44100
    periods 128
    period_time 0
    period_size 1024 # must be power of 2
    buffer_size 8192
  }
}
To test:

Code: Select all

$ mpg123-alsa -a hw:Loopback,0,0 audio.mp3 
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
        version 1.20.1; written and copyright by Michael Hipp and others
        free software (LGPL) without any warranty but with best wishes

Playing MPEG stream 1 of 1: audio.mp3 ...

MPEG 1.0 layer III, 128 kbit/s, 44100 Hz joint-stereo
^C

matrixhero259
Posts: 1
Joined: Sun Jan 06, 2019 5:29 am

Re: Turn HDMI-out into a V4L2-compliant capture device with UV4L

Sun Jan 06, 2019 5:39 am

Hi,

I was following sorbone instructions but failed to stream audio from my Pi. It was runnning retropie and when using the ALSA loopback device, it reports with

Code: Select all

1v10: VolumeControl::init() - Failed to find mixer elements!
ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to create IPC
1v10: AudioManager Error - Unable to open SDL audio: ALSA: Couldn't open audio device: Permission denied
So I guess I need to config the asound.conf to work with retropie audio output. But I have no idea how to. Hope someone can help me with this.
Thanks!

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

Re: Turn HDMI-out into a V4L2-compliant capture device with UV4L

Mon Jan 07, 2019 8:34 am

matrixhero259 wrote:
Sun Jan 06, 2019 5:39 am
Hi,

I was following sorbone instructions but failed to stream audio from my Pi. It was runnning retropie and when using the ALSA loopback device, it reports with

Code: Select all

1v10: VolumeControl::init() - Failed to find mixer elements!
ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to create IPC
1v10: AudioManager Error - Unable to open SDL audio: ALSA: Couldn't open audio device: Permission denied
So I guess I need to config the asound.conf to work with retropie audio output. But I have no idea how to. Hope someone can help me with this.
Thanks!
I do not exactly know what retropie is, but here is a way to stream audio "what you hear" to the browser which makes use of a loopback device:
https://www.linux-projects.org/uv4l/tut ... d-sharing/

User avatar
HermannSW
Posts: 1571
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Turn HDMI-out into a V4L2-compliant capture device with

Mon Jan 07, 2019 10:17 pm

RpiName wrote:
Wed Nov 02, 2016 11:05 pm
mattmiller wrote:Just tried this on a PiZero but no luck - documentation talks about Pi2 onwards for WebRTC so that may be the issue
exactly, Pi Zero is not supported.
That is not true anymore:
"UV4L WebRTC has now landed on the Raspberry Pi Zero and Zero W models!"
https://www.linux-projects.org/2017/04/ ... or-pizero/
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Return to “Camera board”