Giter Club home page Giter Club logo

mjpeg-server's Introduction

MJPEG Server

MJPEG Server implements MJPEG over HTTP using FFmpeg or any other input source capable of piping a multipart JPEG stream to stdout.

Its primary use case is providing screen recordings for remote Webdriver tests, e.g. for blueimp/wdio.

It is resource efficient and by default only starts the screen recording process if there is at least one HTTP client connected to the server, stopping the recording when there are no more open client connections.

Installation

The MJPEG Server binary can be downloaded for Linux, MacOS and Windows from the releases page or built from source via go get:

go get github.com/blueimp/mjpeg-server

The screencast examples also require FFmpeg to be installed.

Usage

By default, mjpeg-server listens on port 9000 on all interfaces and starts the given recording command when the first HTTP client connects:

mjpeg-server [options] [--] command [args]

The command must write a multipart JPEG stream to stdout, e.g.:

--ffmpeg
Content-Type: image/jpeg

[IMAGE_DATA]
--ffmpeg
Content-Type: image/jpeg

[IMAGE_DATA]
...
--ffmpeg--

A sample multipart JPEG generation program can be tested by running the following command and opening http://localhost:9000 in your browser:

go run main.go -a 127.0.0.1:9000 -- go run mpjpeg/main.go -- gopher.jpg

It simply streams the provided JPEG images in an endless loop.

Options

Available MJPEG Server options can be listed the following way:

mjpeg-server -h
Usage of mjpeg-server:
  -a string
    	TCP listen address (default ":9000")
  -b string
    	Multipart boundary (default "ffmpeg")
  -d	Start command directly
  -p string
    	URL path (default "/")
  -v	Output version and exit

The -d option starts the given recording command directly on initialization of the MJPEG server and keeps it running independently of the number of connected HTTP clients, until the MJPEG server process is stopped.

Screencast

Linux

Start mjpeg-server using the x11grab device, selecting the X11 display via -i :DISPLAY and the matching screen resolution via -video_size WIDTHxHEIGHT option:

mjpeg-server -- ffmpeg \
  -loglevel fatal \
  -probesize 32 \
  -fpsprobesize 0 \
  -analyzeduration 0 \
  -fflags nobuffer \
  -f x11grab \
  -r 15 \
  -video_size 1440x900 \
  -i :0 \
  -f mpjpeg \
  -q 2 \
  -

MacOS

List the available avfoundation input devices:

ffmpeg -f avfoundation -list_devices true -i -

Start mjpeg-server, selecting the capture device via -i INDEX option:

mjpeg-server -- ffmpeg \
  -loglevel error \
  -probesize 32 \
  -fpsprobesize 0 \
  -analyzeduration 0 \
  -fflags nobuffer \
  -f avfoundation \
  -capture_cursor 1 \
  -r 15 \
  -pixel_format yuyv422 \
  -i 1 \
  -f mpjpeg \
  -q 2 \
  -

Windows

On Windows, we can use the built-in gdigrab input device to capture the whole desktop.

Start MJPEGServer using the following command in a Powershell console:

MJPEGServer -- ffmpeg `
  -loglevel error `
  -probesize 32 `
  -fpsprobesize 0 `
  -analyzeduration 0 `
  -fflags nobuffer `
  -f gdigrab `
  -r 15 `
  -i desktop `
  -f mpjpeg `
  -q 2 `
  -

License

Released under the MIT license.

Attributions

The Gopher image used for the tests was designed by Renee French.
The design is licensed under the Creative Commons 3.0 Attributions license.

Gopher

Author

Sebastian Tschan

mjpeg-server's People

Contributors

blueimp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mjpeg-server's Issues

Error fork/exec : no such file or directory

I have installed mjpeg-server on Ubuntu Focal Fossa. When i call the url from outside i see these logs:

sudo ./mjpeg-server -d
2020/10/25 18:38:26 fork/exec : no such file or directory
{"ID":"1","Time":"2020-10-25T17:38:38.697133947Z","RemoteIP":"yyyyyyyy","Method":"GET","Host":"xxxxxxxxxx:9000","RequestURI":"/","Referrer":"","UserAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36","ForwardedFor":"","ForwardedHost":"","ForwardedProto":""}
{"ID":"1","Time":"2020-10-25T17:38:38.697452011Z","Registered":true,"NumClients":1}

What could be the cause?

Thanks

Restart or exit when command exits?

Hi!

I'm trying to stream a v4l2 device, and I run mjpeg-server in a systemd service that starts after another service that writes to the video device starts. Sometimes I run into a race condition where the command passed to the mjpeg server can't yet access the camera and crashes. When that happens, I see exit status 255 logged, but from what I can tell the program makes no effort to restart it.

As a workaround I can pass something like bash -c 'while [[ true ]]; do gst-launch-1.0 ....; done', but I think there should be an option for mjpeg-server to either restart the process or also exit when the process exits (the latter would let systemd handle the restarting in my use case).

Cheers!

[wish] option for eager streaming

It is a great program, thank you very much.

"[it] starts the given recording command when the first HTTP client connects:"

Would it be possible to introduce an option for controlling this behavior. I found problematic a bit, when the data feed is pushed through named pipe (Windows), I need to wait for connection being established (i.e. ffmpeg) and ffmpeg does not start because there are no clients. So my app kind of freezes just waiting for a client.

Of course there is an easy workaround, simply start client, and then main app, but having such option would allow to start both parties in any order.

Reading stream with VLC or other media player

Once again thank you for really useful program and at the same time I am terribly sorry for bothering you, but maybe you could give me a hint why it happens:

  • I can play the output stream using any web browser, absolutely no problems, I simply enter the address and that's it
  • but I don't have any output (or error) while trying to play the stream using VLC (or other similar media player) -- I enter the same address and nothing happens

Out of curiosity I tried to save the stream using VLC to check what it sees, I got 160 bytes (I guess it was just a header of the file format).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.