Skip to main content

Lightweight remote image/video preview server for Python scripts

Project description

previewier

CI

Lightweight Python 3.10+ library for remote preview of images/video from scripts running on servers.

Goals

  • Minimal integration into existing scripts.
  • Lightweight HTTP preview (MJPEG) without heavy web frameworks.
  • Optional RTSP stream for standard players.
  • Optional recording to file with PyAV and configurable codec/container.

Install

Base package:

pip install previewier

With optional features:

pip install "previewier[opencv,av]"

Quick start (minimal code changes)

from previewier import PreviewServer

server = PreviewServer(
    host="0.0.0.0",
    http_port=8080,
    enable_http=True,
    enable_rtsp=True,
    rtsp_port=8554,
    rtsp_path="/preview",
    rtsp_codec="libx264",
    save_path="recordings/out.mp4",
    save_codec="libx264",
    fps=25,
)
server.start()

# In your frame loop:
# frame: numpy ndarray, BGR, shape [H, W, 3]
server.publish_frame(frame)

# On shutdown:
server.stop()

Context manager mode:

from previewier import PreviewServer

with PreviewServer(host="0.0.0.0", http_port=8080) as server:
    # frame loop
    server.publish_frame(frame)

HTTP preview URL:

  • http://<server-ip>:8080/ (live MJPEG page)
  • http://<server-ip>:8080/snapshot.jpg (latest frame)

RTSP URL:

  • rtsp://<server-ip>:8554/preview

API

PreviewServer(...) key options:

  • enable_http=True: enable built-in MJPEG HTTP server.
  • enable_rtsp=False: enable RTSP publish via PyAV.
  • rtsp_codec="libx264": RTSP codec, e.g. libx264, libx265, mpeg4.
  • save_path=None: if set, writes video using PyAV.
  • save_codec="libx264": recording codec, e.g. libx264, libx265, mpeg4, mjpeg.
  • save_pix_fmt="yuv420p": output pixel format for recorder.

Methods:

  • start() / stop()
  • publish_frame(frame) for ndarray BGR frame
  • publish_jpeg(jpeg_bytes) if you already have JPEG bytes

Notes

  • For publish_frame, install at least one JPEG backend:
    • OpenCV: pip install previewier[opencv]
    • Pillow: pip install previewier[pillow]
  • RTSP mode requires PyAV: pip install previewier[av].
  • RTSP mode publishes to an external RTSP server endpoint (for example MediaMTX).
  • If host="0.0.0.0", RTSP publish target is normalized to 127.0.0.1.
  • Recording requires PyAV: pip install previewier[av].

Example

See examples/basic_cv2.py.

Development

Install dev tools in your .venv:

pip install -e ".[dev]"

Enable git hooks:

pre-commit install --hook-type pre-commit --hook-type pre-push
pre-commit run --all-files

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

previewier-0.1.1.tar.gz (155.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

previewier-0.1.1-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file previewier-0.1.1.tar.gz.

File metadata

  • Download URL: previewier-0.1.1.tar.gz
  • Upload date:
  • Size: 155.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for previewier-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a2e62185c04352cf506f6584310fe7a4bd0f96306302f1ee0f6a066a2dbf038d
MD5 568b6681179fcbca7a75279b71aecf7e
BLAKE2b-256 fc06cab1df4b103bf27791374d56a5a63d6a05740594f864d18b4ea9e4dbab8c

See more details on using hashes here.

File details

Details for the file previewier-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: previewier-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for previewier-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f9f9b6bf110cf5ba3c9960f1645d66bf795d6703b6e07cd2ef6e7278ece11792
MD5 834e6b02f3355afb48343be1055a3cc5
BLAKE2b-256 ddf8fd09b85d8212ef886af2a26f2c5b018aceccdca940110b93d3f866628aee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page