MaixCAM MaixPy Video Streaming RTMP Push Streaming
Update history
Date | Version | Author | Update content |
---|---|---|---|
2024-05-31 | 1.0.0 | lxowalle | initial document |
Introduction
This document provides methods for pushing H264 video streams via RTMP
How to use
The following example shows pushing an h264 video stream to rtmp://192.168.0.30:1935/live/stream
from maix import camera, time, rtmp, image
cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP)
# rtmp://192.168.0.30:1935/live/stream
host = '192.168.0.30'
port = 1935
app = 'live'
stream = 'stream'
bitrate = 1000_000
r = rtmp.Rtmp(host, port, app, stream, bitrate)
r.bind_camera(cam)
r.start()
while True:
time.sleep(1)
Steps:
Import the camera、rtmp、time and image modules:
from maix import camera, time, rtmp, image
Initialize the camera:
cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP) # Initialise camera, output resolution 640x480 NV21 format
- Note that the RTMP module currently only supports the NV21 format, so the camera needs to be configured to output in NV21 format.
Initialise and start the Rtmp object
r = rtmp.Rtmp(host, port, app, stream, bitrate) r.bind_camera(cam) r.start()
r = rtmp.Rtmp(host, port, app, stream, bitrate)
is used to create anRtmp
object, wherehost
refers to the ip address or domain of the rtmp server,app
refers to the name of the application that is open to the rtmp server, andstream
refers to the name of the rtmp stream, which can also be used as the key for pushing the streamr.bind_camera(cam)
is used to bind aCamera
object, the originalCamera
object can not be used after binding.r.start()
is used to start thertmp
stream.
Done
Push streaming test to Bilibili
Launch bilibili live stream
Click on Live Streaming
Click on Live Streaming Settings
- Find the live streaming address
- Scroll down, select a category, and click Start Live!
- Get the push stream address
- server address:
rtmp://live-push.bilivideo.com/live-bvc
- key:
?streamname=live_xxxx&key=1fbfxxxxxxxxxxxxxffe0&schedule=rtmp&pflag=1
Push stream address: rtmp://live-push.bilivideo.com/live-bvc/?streamname=live_xxxx&key=1fbfxxxxxxxxxxxxxffe0&schedule=rtmp&pflag=1
Run the RTMP client
from maix import camera, time, rtmp, image
cam = camera.Camera(640, 480, image.Format.FMT_YVU420SP)
# rtmp://live-push.bilivideo.com/live-bvc/?streamname=live_xxxx&key=1fbfxxxxxxxxxxxxxffe0&schedule=rtmp&pflag=1
host = 'live-push.bilivideo.com'
port = 1935
app = 'live-bvc'
stream = '?streamname=live_xxxx&key=1fbfxxxxxxxxxxxxxffe0&schedule=rtmp&pflag=1'
bitrate = 1000_000
r = rtmp.Rtmp(host, port, app, stream, bitrate)
r.bind_camera(cam)
r.start()
while True:
time.sleep(1)
Above get bilibili's push stream address as rtmp://live-push.bilivideo.com/live-bvc/?streamname=live_xxxx&key=1fbfxxxxxxxxxxxxxffe0&schedule=rtmp&pflag=1
Can be detached:
- server address is
live-push.bilivideo.com
- port is
1935
, if there is no port number, the default is1935
- application name is
live-bvc
- stream name is
?streamname=live_xxxx&key=1fbfxxxxxxxxxxxxxffe0&schedule=rtmp&pflag=1
Run the code and you will be able to see the maixcam
screen in the live stream, if you find that the live stream is not displayed, try to close the live stream first, then reopen it and run the code again.
Try it~!