Open petered opened 1 year ago
I wish I could use this too
Now PyRTMP only supports video upstream.
Forwarding the video to OpenCV or anything can be done directly by writing an adapter to convert video chunks and feed to OpenCV (or something else). Please look at https://pyav.org/
Now PyRTMP only supports video upstream.
Forwarding the video to OpenCV or anything can be done directly by writing an adapter to convert video chunks and feed to OpenCV (or something else). Please look at https://pyav.org/
Thank you for the update.
Now PyRTMP only supports video upstream. Forwarding the video to OpenCV or anything can be done directly by writing an adapter to convert video chunks and feed to OpenCV (or something else). Please look at https://pyav.org/
I wanted to clarify. By adapter, do you mean something like FLVFileWriter?
class FLVFileWriter:
def __init__(self, output: str) -> None:
self.buffer = open(output, "wb")
self.writer = FLVWriter()
self.buffer.write(self.writer.write_header())
super().__init__()
def write(self, timestamp: int, payload: bytes, media_type: FLVMediaType):
self.buffer.write(self.writer.write(timestamp, payload, media_type))
self.buffer.flush()
def close(self):
self.buffer.close()
Do I get it right that we need to forward payload to PyAV encoder?
Context: I launch the RTMP server with:
python -m pyrtmp.rtmp
I then start streaming a video in terminal with
ffmpeg -stream_loop -1 -i /Users/peter/drone/e2_dual/raw/dji_2023-02-26_15-12-52_0167.mov -b:v 50M -f flv rtmp://127.0.0.1/live
And attempt to display the stream with opencv.
Problem 1: The client won't start streaming (solved) This happened because
message.publishing_name
in theisinstance(message, NSPublish)
block ofrtmp.py
was""
, and is fixed by just changing that line toflv = FLVFile(os.path.join(tempfile.gettempdir(), message.publishing_name or "file.flv"))
With that fix, the video starts streaming from terminal, showing
and I see lots of debug messages from the server like:
So that's good, something's getting through.
Problem 2: OpenCV cannot read the stream (not solved)
This script plots the livestream - and works fine when I use another RTMP server like "Local RTMP Server" (Mac) or "MonaServer" (Windows).
If I run this script, and the terminal, when serving with "Local RTMP Server", it works fine.
But, when serving with pyrtmp, it never gets frames, and outputs:
What needs to be done to
rtmp.py
to make it behave correctly? I assume it somehow needs to pass thisCAP_IMAGES
into the stream, but I'm not sure how.