User avatar
felix3008
Posts: 38
Joined: Sun Dec 30, 2012 2:04 am

Windows desktop mirroring with 30fps, <1 sec latency & audio

Sun Oct 19, 2014 10:12 pm

Intro

I don't know if it's the right forum to post this as it seems to fit in three different forums (multimedia, network, media).
Also, please note that English is not my first language. So if something is unclear, please let me know so i can rephrase it.

Anyway, this is a quick tutorial on how to mirror your windows desktop to the raspberry pi using nginx and Open broadcaster software. The latency and quality is dependent on your network and pc but i managed to get a [email protected] stream with audio and 700ms delay running on a 54mbit wifi network and a dual-core laptop so you can probably expect acceptable results.

Here's how it could look: http://youtu.be/jRK9Tmxjc9Y (Sorry for my crappy cam)

Things you need:
  • windows machine (Network enabled)
    raspberry pi (Network enabled)
    monitor or tv connected to the raspberry pi
Setup (Raspberry Pi):

1. Download, compile and install nginx with the rtmp-module

Code: Select all

sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev
wget http://nginx.org/download/nginx-1.6.2.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
tar -zxvf nginx-1.6.2.tar.gz
unzip master.zip
cd nginx-1.6.2
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master
make
sudo make install
cd ..
rm -R nginx-1.6.2
rm -R rtmp-module-master
2. edit the configuration

Open the nginx config file with:

Code: Select all

sudo nano /usr/local/nginx/conf/nginx.conf
Edit the first line to say:

Code: Select all

user pi;
And add this to the end of the file:

Code: Select all

rtmp {
        server {
                listen 1935;
                chunk_size 128;

                application live {
                        live on;
                        exec_push omxplayer --live rtmp://localhost:1935/live/stream;
                        record off;
                }
        }
}
3. (Optional) Start nginx on boot

Code: Select all

sudo bash -c "echo 'sudo /usr/local/nginx/sbin/nginx' > /etc/init.d/nginx"; sudo chmod 775 /etc/init.d/nginx; sudo /usr/sbin/update-rc.d -f nginx defaults
Setup (Windows):

1. Download Open broadcaster software
(For example here: https://obsproject.com/download)

2. Install it
(You know how that's done... next, next, next, i agree, next... :lol: )

3. Configure it

Open OBS and go to settings -> broadcast settings
Select streaming service -> Custom
FMS URL -> rtmp://<IP-of-your-pi>:1935/live
Playpath /Stream key -> stream

(Play with the encoder settings until you get the results you want)
(For my configuration see the screenshots below)

4. Edit the scene to your liking
(I have mine set for full screen capture)

How to use

1. Start the nginx server

Code: Select all

sudo /usr/local/nginx/sbin/nginx
2.Just start streaming with OBS. The raspberry pi will start mirroring in a few seconds.

3. (Optional) You can stop the server with

Code: Select all

sudo /usr/local/nginx/sbin/nginx -s stop
Troubleshooting

Q: I have no audio / only audio via the analog out!
A: Add "-o hdmi" to the omxplayer line in the nginx config file.

Q: My audio is stuttering /randomly cutting of!
A: Remove "--live" from the omxplayer line in the nginx config file. (Note: This increases latency about 3 seconds)

Q: What's the song in the video?
A: Darude - Sandstorm. Just kidding, it's "Infinite Breeze" by BinaryCounter (me ^^) https://www.youtube.com/watch?v=fwlaB05PpwU

Examples / Screenshots

Latency test

Image

My settings

Image
Image
Image

Outro

I would appreciate any feedback possible. If you have any problems, just ask me.
Also i would welcome it if you could share your results in this thread.
(Warning: Shameless self promotion)
Oh and if it helped you please consider subscribing to my youtube channel "BinaryCounter" for self-made electronic music of all sorts. Thanks!

User avatar
felix3008
Posts: 38
Joined: Sun Dec 30, 2012 2:04 am

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Tue Oct 21, 2014 10:17 am

Edited the first post to include the server starting and shutdown process.
Everything should work now.

slasham
Posts: 2
Joined: Wed Nov 12, 2014 3:58 am

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Sat Nov 15, 2014 7:02 pm

Hi,

Does this method allow remote access to the original computer? or does it just mirror the screen?

Thanks,

User avatar
Forgotten01
Posts: 162
Joined: Sun Dec 01, 2013 6:06 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Mon Dec 22, 2014 4:36 am

Just tested this last night with my handheld UMPC build on a Linksys 54 megabit wireless G router with basically 480P @ 60fps and it worked beautifully, the only thing is that the 700ms latency is annoying and rules out remote gaming, any way to deal with it?
Engineers like to solve problems. If there are no problems handily available, they will create their own problems.
Scott Adams

Omaebaka
Posts: 1
Joined: Wed Jan 28, 2015 11:23 am

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Wed Jan 28, 2015 11:28 am

Hi, i've just tested on my raspberry pi b+.

I've follow your instructions above, but on my raspberr pi desktop show nothing.

(Sorry formy bad language in english)

Thanks,

adv
Posts: 1
Joined: Thu Feb 12, 2015 12:09 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Thu Feb 12, 2015 12:16 pm

Hello Felix,

this is something very interesting.

Simple question because I didn't tested Open Broadcaster yet :D

Is it possible to broadcast to several pi ?

Thank you ;)

Regards, Antoine.

User avatar
Forgotten01
Posts: 162
Joined: Sun Dec 01, 2013 6:06 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Thu Feb 12, 2015 10:28 pm

Actually, yes you can broadcast to more than one pi, just as long as your network can handle it
Engineers like to solve problems. If there are no problems handily available, they will create their own problems.
Scott Adams

aramaziakin
Posts: 9
Joined: Wed Dec 31, 2014 9:09 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Sat Feb 14, 2015 9:02 pm

Great guide, this works really well, only trouble I'm having is resolution mismatch problems as the pc monitor I'm mirroring is 1440x900 and the tv the pi is attached to is 1080p. Any tips on getting a decent sized picture on the tv, best solution I've found so far is setting the pc monitor I'm mirroring to 720p before I start OBS.

xNuno
Posts: 2
Joined: Mon Feb 23, 2015 3:44 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Mon Feb 23, 2015 3:45 pm

Hi,

Just followed you guide and I'm not able to see any omxplayer window...I can see the process on "TOP" but no windows at all...

Can you help me?

xNuno
Posts: 2
Joined: Mon Feb 23, 2015 3:44 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Wed Feb 25, 2015 12:17 am

It works now...Thanks Felix...Forgot to put the "stream" pass on OBS

Momro
Posts: 25
Joined: Tue Aug 26, 2014 10:14 am

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Fri Mar 20, 2015 1:55 pm

This might be really awesome (my Pi is still processing the installation). If this really works, you'll have saved me a lot of work :-D

Really looking forward to testing this on 24/7 basis. I'm gonna keep you posted!

[edit]
Mh, I don't see anything on the Pi's connected TV. There's only the console waiting for input. The nginx server is running as your guide said, and Windows can connect (I guess) to the Pi's server because it doesn't post any errors. To see if this is the case, I stopped the service, reconnected from Windows and got an error message saying that the distant server was not there. Any idea how to troubleshoot this? :-/

Nico1980
Posts: 1
Joined: Mon Mar 30, 2015 7:49 am

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Mon Mar 30, 2015 7:52 am

Legend, been using this setup for a while now, works quite well once you scale the resolution down a bit!

It also works much better than reading a RTST stream directly from omxplayer.
I tried using VLC player as a streaming server and playing the stream on the pi directly
(omxplayer rtsp://source_ip_address:8554/), and while it worked, it paused every few seconds, so the extra steps in your setup are very justified.

nullandvoid
Posts: 1
Joined: Sun Apr 26, 2015 1:17 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Sun Apr 26, 2015 1:26 pm

I have exactly the same issue as Momro. Nginx has an established connection, omxplayer is doing something according to top, and OBS isn't reporting any connection problems. However the pi, that is connected to non-hdmi tv, is only showing the command line waiting for input. I am out of troubleshooting ideas, since everything appears to be fine, yet still it isn't working.

Edit:
I just ran omxplayer with the -g flag via the nginx.conf. In the omxplayer.log I discover the following error: "ERROR: COMXPlayer::OpenFile - avformat_open_input rtmp://localhost:1935/live/stream" . Unfortunately googling "ERROR: COMXPlayer::OpenFile - avformat_open_input" doesn't yield that many results, so I am basically back at square one again.

japdevil
Posts: 1
Joined: Mon Apr 27, 2015 11:14 am

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Mon Apr 27, 2015 11:23 am

Hi, i've followed your instructions, however i am unable to stream either my laptop or desktop screen to the Pi. The nginx process is running and when starting OBS i can see the session connected on port 1935 but nothing happens on the Pi.

Error logs show the following:
2015/04/27 10:24:09 [emerg] 2760#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2015/04/27 10:24:09 [emerg] 2760#0: bind() to 0.0.0.0:1935 failed (98: Address already in use)
2015/04/27 10:24:09 [emerg] 2760#0: still could not bind()

Any ideas?

Process and connection seem to be established.

tcp 0 0 raspberrypi.local:1935 lptop.local:52567 ESTABLISHED

root 2217 1 0 10:24 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 2221 2217 0 10:24 ? 00:00:08 nginx: worker process
pi 2673 2532 0 11:22 pts/0 00:00:00 grep --color=auto nginx

Edit: I've ran through the installation procedure again and no longer get the "Address already in use" errors. However i am still unable to stream my desktop to the Pi. When starting OBS on my desktop i dont see anything omxplayer process start.

Any help here would be great. Many thanks

futaris
Posts: 6
Joined: Wed Sep 28, 2011 1:50 am

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Sun May 03, 2015 10:07 am

Works for me with a Raspberry Pi Model B (256MB). But using the latest omxplayer_0.3.6-git20150402-74aac37_armhf on the latest raspbian on OSMC, I was getting around 2 seconds delay with a Core i5-3317U, until I added:

"tune=zerolatency"

and reduced

Scene Buffering Time (ms): 60

That brings it closer to a 1 second delay. If you're not on a 802.11n network the latency is higher.

I suspect a lot of that delay is because of the 2.4GHz 802.11g network I was using at the time.

Using a SoftAP on the OBS machine should help.
Last edited by futaris on Mon May 04, 2015 1:22 am, edited 1 time in total.

futaris
Posts: 6
Joined: Wed Sep 28, 2011 1:50 am

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Mon May 04, 2015 1:17 am

Incidentally for reference,

Streaming a tab from Samsung Chromebook (ARM) to a Chromecast, gives a latency of about: 400ms
Streaming a screen from a Samsung Galaxy Note 4 to a Chromecast, gives a latency of about: 130ms

goldenbucks
Posts: 6
Joined: Tue Apr 21, 2015 2:19 am

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Sat May 09, 2015 11:24 am

I have problem with :

cd ..
[email protected] ~ $ rm -R nginx-1.6.2
[email protected] ~ $ rm -R rtmp-module-master
rm: cannot remove `rtmp-module-master': No such file or directory

is that rm function is just to delete the zip package? if yes so it wont be a problem then

and I have another problem, I followed your guide but when starting the OBS to start the mirroring, there is nothing appeared on my raspberry pi, I already start the nginx on the pi before that, but nothing comes out from my Pi 's HDMI screen,

when i am about to running OBC there was a warning about havent added the source yet, and the screen inside the OBC windows is blank black
please help me thanks, i really need your help please my life is on this one
Last edited by goldenbucks on Sat May 09, 2015 1:06 pm, edited 2 times in total.

goldenbucks
Posts: 6
Joined: Tue Apr 21, 2015 2:19 am

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Sat May 09, 2015 12:05 pm

japdevil wrote:Hi, i've followed your instructions, however i am unable to stream either my laptop or desktop screen to the Pi. The nginx process is running and when starting OBS i can see the session connected on port 1935 but nothing happens on the Pi.

Error logs show the following:
2015/04/27 10:24:09 [emerg] 2760#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2015/04/27 10:24:09 [emerg] 2760#0: bind() to 0.0.0.0:1935 failed (98: Address already in use)
2015/04/27 10:24:09 [emerg] 2760#0: still could not bind()

Any ideas?

Process and connection seem to be established.

tcp 0 0 raspberrypi.local:1935 lptop.local:52567 ESTABLISHED

root 2217 1 0 10:24 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 2221 2217 0 10:24 ? 00:00:08 nginx: worker process
pi 2673 2532 0 11:22 pts/0 00:00:00 grep --color=auto nginx

Edit: I've ran through the installation procedure again and no longer get the "Address already in use" errors. However i am still unable to stream my desktop to the Pi. When starting OBS on my desktop i dont see anything omxplayer process start.

Any help here would be great. Many thanks
https://rtcamp.com/tutorials/nginx/trou ... dy-in-use/

here is the Link to fix that

no h8 m8
Posts: 2
Joined: Fri Jun 12, 2015 5:37 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Fri Jun 12, 2015 5:54 pm

Hi, I tried to follow your guide and everything worked as you mentioned it.
But when I try to connect the Broadcast software with my raspberry the screen connected to the raspberry is not able to find a source. When I restart the Pi, it boots as usual (shell).

So I started the server with the command:
sudo /usr/local/nginx/sbin/nginx
The output:
#nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] still could not bind()

I tried to fix it with the method featured above.
(sudo fuser -k 80/tcp)
But it didn‘t help

Terminal Program: Putty
Raspberry V.: Raspberry 2B

I’m looking forward to your response

User avatar
DougieLawson
Posts: 37079
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Fri Jun 12, 2015 7:39 pm

Try installing lsof. Then use
sudo lsof -i TCP:80
to see what task is bound to port 80.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

no h8 m8
Posts: 2
Joined: Fri Jun 12, 2015 5:37 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Fri Jun 12, 2015 8:30 pm

DougieLawson wrote:Try installing lsof. Then use
sudo lsof -i TCP:80
to see what task is bound to port 80.
The output:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 2181 root 6u IPv4 6085 0t0 TCP *:http (LISTEN)
nginx 2183 nobody 6u IPv4 6085 0t0 TCP *:http (LISTEN)

ty for your fast answer

User avatar
DougieLawson
Posts: 37079
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Fri Jun 12, 2015 9:31 pm

So were you trying to restart nginx without terminating the original instance?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Arkon
Posts: 2
Joined: Fri Jun 12, 2015 10:16 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Sat Jun 13, 2015 6:35 am

If you strugle with omxplayer not starting after the stream started on your pc make sure, that you uncommented the first line in nginx.conf like mentioned in step 2. Take a close look and you will notice it's not just changing the user. You have to delete the #

In addition I addet the full path to omxplayer in the server config. It's now:

Code: Select all

exec_push /usr/bin/omxplayer --live rtmp://localhost:1935/live/stream;

With these two changes the player starts when it receives the stream.

Tomate131
Posts: 1
Joined: Tue Jul 21, 2015 4:19 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Tue Jul 21, 2015 4:26 pm

Hello, I have copied the first command but when the Raspberry Pi searches if its installed he show often: not found...

Then he didn't find the PCRE library...

How can I fix it?

TheHNIC
Posts: 1
Joined: Thu Aug 27, 2015 9:42 pm

Re: Windows desktop mirroring with 30fps, <1 sec latency & a

Thu Aug 27, 2015 9:46 pm

I haven't had a chance to install the programs yet, but before I take time to do so.
Is there a way to start the necessary programs on reboot? The Pis I'll be using are located at my school so I won't always have physical access to them and will need to start screen mirroring and remote access...well remotely.
I apologize if I just overlooked a response on this topic

Return to “Media centres”