Files
go2rtc/internal/mjpeg/README.md
T
Sergey Krashevich 38cc05c22d feat(jpeg): Add keyframe caching with expiration mechanism to JPEG http handler (#1155)
* feat(mjpeg): add keyframe caching with expiration and cleanup goroutine

* mjpeg: make keyframe cache duration and default usage configurable

* mjpeg: document and add config options for MJPEG snapshot caching

* mjpeg: fix errors after rebase

* Code refactoring for frame.jpeg cache #1155

---------

Co-authored-by: Alex X <alexey.khit@gmail.com>
2026-01-18 14:23:50 +03:00

3.1 KiB

MJPEG

Important. For stream in MJPEG format, your source MUST contain the MJPEG codec. If your stream has an MJPEG codec, you can receive MJPEG stream or JPEG snapshots via API.

You can receive an MJPEG stream in several ways:

  • some cameras support MJPEG codec inside RTSP stream (ex. second stream for Dahua cameras)
  • some cameras have an HTTP link with MJPEG stream
  • some cameras have an HTTP link with snapshots - go2rtc can convert them to MJPEG stream
  • you can convert H264/H265 stream from your camera via FFmpeg integraion

With this example, your stream will have both H264 and MJPEG codecs:

streams:
  camera1:
    - rtsp://rtsp:12345678@192.168.1.123/av_stream/ch0
    - ffmpeg:camera1#video=mjpeg

API examples

MJPEG stream

http://192.168.1.123:1984/api/stream.mjpeg?src=camera1`

JPEG snapshots

http://192.168.1.123:1984/api/frame.jpeg?src=camera1
  • You can use width/w and/or height/h params.
  • You can use rotate param with 90, 180, 270 or -90 values.
  • You can use hardware/hw param read more.
  • You can use cache param (1m, 10s, etc.) to get a cached snapshot.
    • The snapshot is cached only when requested with the cache parameter.
    • A cached snapshot will be used if its time is not older than the time specified in the cache parameter.
    • The cache parameter does not check the image sizes from the cache and those specified in the query.

Stream as ASCII to Terminal

Tips

  • this feature works only with MJPEG codec (use transcoding)
  • choose a low frame rate (FPS)
  • choose the width and height to fit in your terminal
  • different terminals support different numbers of colours (8, 256, rgb)
  • escape text param with urlencode
  • you can stream any camera or file from a disc

go2rtc.yaml - transcoding to MJPEG, terminal size - 210x59 (16/9), fps - 10

streams:
  gamazda: ffmpeg:gamazda.mp4#video=mjpeg#hardware#width=210#height=59#raw=-r 10

API params

  • color - foreground color, values: empty, 8, 256, rgb, SGR
    • example: 30 (black), 37 (white), 38;5;226 (yellow)
  • back - background color, values: empty, 8, 256, rgb, SGR
    • example: 40 (black), 47 (white), 48;5;226 (yellow)
  • text - character set, values: empty, one char, block, list of chars (in order of brightness)
    • example: %20 (space), block (keyword for block elements), ox (two chars)

Examples

% curl "http://192.168.1.123:1984/api/stream.ascii?src=gamazda"
% curl "http://192.168.1.123:1984/api/stream.ascii?src=gamazda&color=256"
% curl "http://192.168.1.123:1984/api/stream.ascii?src=gamazda&back=256&text=%20"
% curl "http://192.168.1.123:1984/api/stream.ascii?src=gamazda&back=8&text=%20%20"
% curl "http://192.168.1.123:1984/api/stream.ascii?src=gamazda&text=helloworld"