How can I listen to and decode an RTMP video stream with Python? Such as with the ffmpeg command
ffmpeg -listen 1 -i rtmp://localhost:1935/live/app
I tried this:
import av
container = av.open('rtmp://localhost:1935/live/app',listen=True)
for frame in container.decode(video=0):
frame = frame.to_ndarray(format='bgr24')
...do some thing with the frame...
But I got an error:
open() got an unexpected keyword argument 'listen'
PyAV correct syntax is:
av.openaccepts anoptionsdictionary argument.In the code,
'listen'is the key and'1'is the value.This is the equivalent to
-listen 1argument of FFmpeg CLI.