如何使用Python监听和解码RTMP视频流

huangapple go评论76阅读模式
英文:

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:

&gt; open() got an unexpected keyword argument &#39;listen&#39;

</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(&#39;rtmp://localhost:1935/live/app&#39;, options={&#39;listen&#39;: &#39;1&#39;})

av.open accepts an options dictionary argument.
In the code, &#39;listen&#39; is the key and &#39;1&#39; is the value.
This is the equivalent to -listen 1 argument of FFmpeg CLI.

huangapple
  • 本文由 发表于 2023年5月25日 18:57:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331542.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定