英文:
How to listen to and decode an RTMP video stream with Python
问题
如何使用Python监听并解码RTMP视频流,就像使用ffmpeg命令一样:
import av
container = av.open('rtmp://localhost:1935/live/app', options={'listen': True})
for frame in container.decode(video=0):
frame = frame.to_ndarray(format='bgr24')
# 对帧进行操作...
但是我遇到了一个错误:
open()收到了一个意外的关键字参数'listen'
<details>
<summary>英文:</summary>
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'
</details>
# 答案1
**得分**: 0
```python
PyAV正确的语法是:
container = av.open('rtmp://localhost:1935/live/app', options={'listen': '1'})
`av.open`接受一个`options`字典参数。
在代码中,`'listen'`是键,`'1'`是值。
这相当于FFmpeg CLI的`-listen 1`参数。
英文:
PyAV correct syntax is:
container = av.open('rtmp://localhost:1935/live/app', options={'listen': '1'})
av.open
accepts an options
dictionary argument.
In the code, 'listen'
is the key and '1'
is the value.
This is the equivalent to -listen 1
argument of FFmpeg CLI.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论