2

I have an embedded linux system (yocto based) with a framebuffer UI (no X11) and a running web server.

Now I'm asking how to "mirror" the screen contents to a web page. Think of it like a web cam, except the stream is not coming from a camera, but from /dev/fb0.

Sounds like a quite obvious thing to do, but my web search didn't throw any matches. Do you have an idea on how to proceed?

1 Answer 1

2

The linux framebuffer video is available in ffmpeg via the fbdev device.

> ffprobe -f fbdev -i '/dev/fb0'                                                                           
[fbdev @ 0x2308100] w:1920 h:1080 bpp:32 pixfmt:bgra fps:25/1 bit_rate:1658880000
[fbdev @ 0x2308100] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, fbdev, from '/dev/fb0':
  Duration: N/A, start: 1673953008.518392, bitrate: 1658880 kb/s
  Stream #0:0: Video: rawvideo (BGRA / 0x41524742), bgra, 1920x1080, 1658880 kb/s, 25 fps, 1000k tbr, 1000k tbn

That should tell you some metadata about the video source, useful for testing. Replace ffprobe with ffmpeg to do the usual video transcoding:

> ffmpeg -f fbdev -i '/dev/fb0' -f matroska -crf 0 -filter:v 'scale=-1:720' - | mpv

That will send the encoded video stream to stdout, which should be played by mpv after a few seconds of buffering. If your headless server is accessible via SSH, you can reuse this pipe technique and do:

ssh server ffmpeg -f fbdev -i '/dev/fb0' -f matroska -crf 0 -filter:v 'scale=-1:720' - | mpv

This must be run from a machine with a GUI and a video player installed (mpv in the example above) which has SSH access to server. Alternatively, the video stream can be exposed over HTTP. Looking at this answer, for example, you could do this:

ffmpeg -f fbdev -i '/dev/fb0' -f mp4 -movflags frag_keyframe+empty_moov -listen 1 http://localhost:8080/

That makes ffmpeg a one-shot webserver, where you can point your favorite video player to, e.g. vlc http://localhost:8080/. Your browser might insist to downloading that file, which will probably require wrapping the url in some HTML.

Making a proper streaming web-server is a larger topic, and probably difficult to get right if you intend to have many visitors and support various devices. The topic seems to have been answered multiple times, but for other video sources.

I hope this will take you a step in the right direction.

Note: If you want to mess around with your framebuffer content while you're testing this, you can issue cat /dev/urandom >/dev/fb0 and cat /dev/zero >/dev/fb0

2
  • 2
    I have edited my question with more references and the simples ffmpeg-webserver trick I could find. I hope this is satisfactory. Commented Jan 20, 2023 at 20:31
  • @AdminBee the real new and hardly covered part of the question in this was how to take video stream from framebuffer with ffmpeg; it's perfectly answered. How to use ffmpeg to stream video is entirely different and widely covered topic. Actually better is to reduce the scope of the question for it to only contain one question, than to extend the answer to cover both parts and making it partially redundant. Commented Jan 21, 2023 at 8:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.