Skip to content

Commit ce687e6

Browse files
committed
* update rtmp&rtsp support push audio stream
1 parent 6a0a570 commit ce687e6

File tree

6 files changed

+130
-12
lines changed

6 files changed

+130
-12
lines changed

docs/doc/en/video/rtmp_streaming.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,40 @@ Steps:
6565

6666
4. Done
6767

68+
69+
70+
## Support for Streaming Audio
71+
72+
MaixPy supports streaming both audio and video simultaneously. By binding a `Recorder` object,
73+
74+
> Note: This method is supported in MaixPy v4.7.9 and later versions
75+
76+
The following is an example code:
77+
78+
```python
79+
from maix import camera, time, app, rtmp, image, audio
80+
81+
cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP)
82+
audio_recorder = audio.Recorder()
83+
84+
host="192.168.0.63"
85+
port=1935
86+
app_name="live"
87+
stream_name="stream"
88+
client = rtmp.Rtmp(host, port, app_name, stream_name)
89+
client.bind_camera(cam)
90+
client.bind_audio_recorder(audio_recorder)
91+
client.start()
92+
93+
print(f"rtmp://{host}:{port}/{app_name}/{stream_name}")
94+
while not app.need_exit():
95+
time.sleep(1)
96+
```
97+
98+
In the code above, an `audio_recorder` object is created using `audio.Recorder()`, and the `bind_audio_recorder()` method of the `Rtmp` server is used to bind this object. Stream the audio data while pushing the video stream.
99+
100+
101+
68102
## Push streaming test to Bilibili
69103

70104
### Launch bilibili live stream

docs/doc/en/video/rtsp_streaming.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,29 @@ Steps:
6464

6565
6. Finished, after running the above code, you can play the video stream through [VLC](https://www.videolan.org/vlc/) software, the tested version of `VLC` is `3.0.20`. The default playback address is `rtsp://device ip:8554/live`.
6666

67-
## OSD
67+
## Support for Streaming Audio
6868

69-
Drawing lines and frames via OSD
69+
MaixPy supports streaming both audio and video simultaneously. By binding a `Recorder` object,
7070

71-
TODO
71+
> Note: This method is supported in MaixPy v4.7.9 and later versions
72+
73+
The following is an example code:
74+
75+
```python
76+
from maix import time, rtsp, camera, image, audio
77+
78+
cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP)
79+
audio_recorder = audio.Recorder()
80+
81+
server = rtsp.Rtsp()
82+
server.bind_camera(cam)
83+
server.bind_audio_recorder(audio_recorder)
84+
server.start()
85+
86+
print(server.get_url())
87+
88+
while True:
89+
time.sleep(1)
90+
```
91+
92+
In the code above, an `audio_recorder` object is created using `audio.Recorder()`, and the `bind_audio_recorder()` method of the `Rtsp` server is used to bind this object. You can use `ffplay rtsp://<device-ip>:8554/live` or `vlc 3.0.20` to receive the audio and video stream.

docs/doc/zh/video/rtmp_streaming.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,38 @@ while True:
6363

6464
4. 完成
6565

66+
## 支持推流音频
67+
68+
MaixPy支持同时推送音视频流, 通过绑定一个`Recorder`对象后可以在推送视频流的同时附带音频数据
69+
70+
> :MaixPy v4.7.8之后的版本支持该方法(不包括v4.7.8)
71+
72+
参考代码如下:
73+
74+
```python
75+
from maix import camera, time, app, rtmp, image, audio
76+
77+
cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP)
78+
audio_recorder = audio.Recorder()
79+
80+
host="192.168.0.63"
81+
port=1935
82+
app_name="live"
83+
stream_name="stream"
84+
client = rtmp.Rtmp(host, port, app_name, stream_name)
85+
client.bind_camera(cam)
86+
client.bind_audio_recorder(audio_recorder)
87+
client.start()
88+
89+
print(f"rtmp://{host}:{port}/{app_name}/{stream_name}")
90+
while not app.need_exit():
91+
time.sleep(1)
92+
```
93+
94+
上文中通过`audio.Recorder()`创建一个`audio_recorder`对象,并使用`Rtmp``bind_audio_recorder()`方法绑定该对象, 推流的同时把音频数据也推送出去了.
95+
96+
97+
6698
## 向Bilibili推流测试
6799

68100
### 启动bilibili直播

docs/doc/zh/video/rtsp_streaming.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,30 @@ while True:
6666

6767
6. 完成,运行上须代码后, 你可以通过[VLC](https://www.videolan.org/vlc/)软件播放视频流, 已测试的`VLC`版本是`3.0.20`. 默认播放地址为`rtsp://设备的ip:8554/live`
6868

69-
70-
## OSD
7169

72-
通过OSD来实现画线与画框
70+
## 支持推流音频
7371

74-
TODO
72+
MaixPy支持同时推送音视频流, 通过绑定一个`Recorder`对象后可以在推送视频流的同时附带音频数据
73+
74+
> :MaixPy v4.7.8之后的版本支持该方法(不包括v4.7.8)
75+
76+
参考代码如下:
77+
78+
```python
79+
from maix import time, rtsp, camera, image, audio
80+
81+
cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP)
82+
audio_recorder = audio.Recorder()
83+
84+
server = rtsp.Rtsp()
85+
server.bind_camera(cam)
86+
server.bind_audio_recorder(audio_recorder)
87+
server.start()
88+
89+
print(server.get_url())
90+
91+
while True:
92+
time.sleep(1)
93+
```
94+
95+
上文中通过`audio.Recorder()`创建一个`audio_recorder`对象,并使用`Rtsp``bind_audio_recorder()`方法绑定该对象, 使用`ffplay rtsp://设备的ip:8554/live`命令或者`vlc 3.0.20`就能接收音视频数据了

examples/vision/streaming/rtmp_stream.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
from maix import camera, time, app, rtmp, image
1+
from maix import camera, time, app, rtmp, image, audio
22

3-
cam = camera.Camera(320, 240, image.Format.FMT_YVU420SP)
3+
AUDIO_ENABLE=True
4+
audio_recorder = None
5+
cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP)
46

5-
host="192.168.0.30"
7+
host="192.168.0.63"
68
port=1935
79
app_name="live"
810
stream_name="stream"
911
client = rtmp.Rtmp(host, port, app_name, stream_name)
1012
client.bind_camera(cam)
13+
if AUDIO_ENABLE:
14+
audio_recorder = audio.Recorder()
15+
client.bind_audio_recorder(audio_recorder)
1116
client.start()
1217

1318
print(f"rtmp://{host}:{port}/{app_name}/{stream_name}")

examples/vision/streaming/rtsp.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
from maix import time, rtsp, camera, image
1+
from maix import time, rtsp, camera, image, audio
22

3-
cam = camera.Camera(2560, 1440, image.Format.FMT_YVU420SP)
3+
AUDIO_ENABLE=True
4+
audio_recorder = None
5+
cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP)
46
server = rtsp.Rtsp()
57
server.bind_camera(cam)
8+
if AUDIO_ENABLE:
9+
audio_recorder = audio.Recorder()
10+
server.bind_audio_recorder(audio_recorder)
611
server.start()
712

813
print(server.get_url())

0 commit comments

Comments
 (0)