Raspberry Pi 3 network Screen mirroring

This entry, the last of this 2019 is just to check and alternative to be able to watch Netflix in my TV (Philips 37PFL8605H/12), in my previous entry I explore the option of installing Kodi on Raspberry 3 Model B and install Netflix add-on, but I face some problems playing HD content so I keep trying to find the best way of doing with my current hardware. Today I’ve found a blog entry in which it was explained how to use ffmpeg to mirror my laptop screen over the network, obviously the idea in this first try is playing Netflix in my laptop with my browser and then export my screen to watch it in my TV, as simple as that.

So I just installed Raspbian on my Pi 3 and setup a static network to connect directly my laptop and my Raspberry to reduce network latency, let’s run omxplayer:

pi@raspberrypi:~ $ cat /etc/network/interfaces
iface video inet static
	address 10.111.3.101
	netmask 255.255.255.0
raspberrypi:# ifup eth0=video

pi@raspberrypi:~ $ omxplayer -b --live udp://0.0.0.0:8888
Video codec omx-h264 width 1920 height 1080 profile 100 fps 15.000000
Subtitle count: 0, state: off, index: 1, delay: 0
Error: Unable to open font
V:PortSettingsChanged: 1920x1080@30.00 interlace:0 deinterlace:0 anaglyph:0 par:1.00 display:0 layer:0 alpha:255 aspectMode:0

The OMXPlayer will be simply listening for a network stream on port 8888 and try to play back the data sent to it.

Then on my laptop I have to run ffmpeg using H264 video encoder, remember that ffmpeg has to compiled with x11grab device support. FFmpeg will use x11grab to capture an area the size of 1920x1080 pixels from laptop screen (-i :0.0). It will then use its native H264 encoder to encode the video and send it as MPEG transport stream via UDP to the network device

$ cat /etc/hosts
...
10.111.3.101   raspberry.acme.local raspberry

$ ffmpeg -devices | grep x11grab
...
 D  x11grab         X11 screen capture, using XCB

$ ffmpeg -r 30 -f x11grab -s 1920x1080 -i :0.0 -c:v libx264 -pix_fmt yuv420p -preset veryfast -tune zerolatency -bsf:v h264_mp4toannexb -b:v 5000k -bufsize 1k -f mpegts udp://raspberry:8888

Reducing buffer size to 1K instead of 500K has improved the delay shown in my TV but it’s still needed to keep testing additional tweaks. I also modifies rate to 30.

References:


“It is better to be feared than loved, if you cannot be both”
–Niccolo Machiavelli

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s