Optimise the anonymised livestream pipeline

Open
#467 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
python, raspberry-pi

Research direction

Start with pyro_camera_api/services/anonymizer_rtsp.py and the existing FPSMeter logs. Measure decoder, model and encoder CPU, latency and FPS on a station, then evaluate the listed copy, box-timing, hardware codec and model-input options one at a time. Done means recording before-and-after measurements in the issue and merging useful changes while the stream stays real time with the new model.

Written by the indexing model from the issue text.

Description

module: engine type: enhancement

Part of pyronear/roadmap#41 (Livestream anonymisation). Independent of the model work.

Context

The blurred livestream (pyro_camera_api/services/anonymizer_rtsp.py) works like this: one ffmpeg decodes the RTSP to raw BGR frames, a thread runs the model on the last frame (BGR to RGB, PIL, letterbox), and an encoder thread copies the last frame, paints the boxes and sends it to a second ffmpeg (x264 to SRT). It works, but it spends CPU on copies and conversions, and the new model may be heavier.

What has to be done

  • Measure on a station: CPU per thread, latency, FPS of decoder, model and encoder (FPSMeter logs exist).
  • Fewer copies: give the raw frame to the model directly (NCNN can do BGR to RGB, no PIL), paint the boxes in place, avoid frame.copy() and tobytes() on every frame.
  • Box timing: boxes are painted on the current frame, not on the frame they come from. A moving object can show for a few frames. Delay the encoder by one inference, or keep the boxes longer and make them bigger.
  • Hardware decode and encode on the Pi (h264_v4l2m2m), or use a smaller camera substream.
  • Smaller model input, or run the model one frame out of N.
  • Measure again after each change, keep what helps.

Done when

  • Before and after measurements are in this issue
  • The useful optimisations are merged and the stream stays real time with the new model
Dominant language
Python
Stars
21
Forks
10
Avg merge
4d 4h
Merged PRs (30d)
13

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pyronear/pyro-engine

All issues in pyronear/pyro-engine

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.