樹莓派 3A+ 好好玩︰樂直播 《三》

有興趣寫程式之人,還是需要親自動手作呦☆

這裡列出 github 上的兩個派生三 python3 參考︰

/pysdk-live

rtsp-server for python, dependecy live555

pysdk-live

rtsp server based on live555 in python3

dependecy

sudo apt-get install liblivemedia-dev
sudo apt-get install libasound2-dev
sudo apt-get install liblog4cpp5-dev

refer to

https://github.com/mpromonet/v4l2rtspserver

https://github.com/yxteagle/pysdk-uvc

───

/pysdk-uvc

cam for python

pysdk-uvc

Linux摄像头UVC驱动的Python3封装

dependecy

sudo apt-get installlibv4l-dev

 

容易安裝︰

python3 setup.py build
sudo python3 setup.py install

略作修改︰

pi@raspberrypi:~/pysdk-live/tests cat tests.py  import os from multiprocessing import Process, Queue from pylive import live from pyuvc import uvc  ※ 修改︰ video1 to video0 DEV = '/dev/video0' STREAM_NUM = 4 BASE_RTSP_PORT = 8554 IMG_WIDTH = 1280 IMG_HEIGHT = 720 STREAM_DATA_LIST = []   class Capture:      def __init__(self):         params = {             'width': IMG_WIDTH,             'height': IMG_HEIGHT,             'fps': 30,             'fmt_type': uvc.H264             }         print('Start capture: %s' % DEV)         r = uvc.open(             fd=DEV,             **params             )         if r != 0:             print('Open capture failed, test exit(%d)' % r)             os._exit(0)      def init_stream_list(self):         for _ in range(STREAM_NUM):             STREAM_DATA_LIST.append(Queue())      def start_stream_loop(self):         while 1:             data = uvc.get_frame()             for i in STREAM_DATA_LIST:                 i.put(data)   class Live:      def __init__(self, i):         self._i = i      def _live_loop(self):         data_factory = STREAM_DATA_LIST[self._i]          def callback():             return data_factory.get()          live.start(             url='unicast',             width=IMG_WIDTH,             height=IMG_HEIGHT,             bufferSize=uvc.get_buffer_size(),             callback=callback,             # fd=uvc.get_fd(),             # queueSize=10,             rtspPort=BASE_RTSP_PORT+self._i,             # user='admin',             # passwd='admin',             # audioDev='default',             # audioFreq=44100,             # audioNbChannels=2,             # murl='multicast',             # rtspOverHTTPPort=8080             )      def start_live_loop_thread(self):         print('start live loop process: %d' % self._i)         p = Process(target=self._live_loop)         p.daemon = True         p.start()   def test_multi():     c = Capture()     c.init_stream_list()     for i in range(STREAM_NUM):         Live(i).start_live_loop_thread()     c.start_stream_loop()   def test_base():      def callback():         return uvc.get_frame()      Capture()     live.start(         url='unicast',         width=IMG_WIDTH,         height=IMG_HEIGHT,         bufferSize=uvc.get_buffer_size(),         callback=callback,         # fd=uvc.get_fd(),         # queueSize=10,         rtspPort=8554,         # user='admin',         # passwd='admin',         audioDev='default',         # audioFreq=44100,         # audioNbChannels=2,         # audioFmt='S16_BE',         # murl='multicast',         # rtspOverHTTPPort=8080         )   if __name__ == '__main__':     test_base()     # test_multi() </pre>    <span style="color: #666699;">就可以跑起來也☺</span>  <span style="color: #ff9900;">sudo modprobe bcm2835-v4l2</span> <pre class="lang:default decode:true ">pi@raspberrypi:~/pysdk-live/tests python3 tests.py 
Start capture: /dev/video0
PYUVC version: 0.3
frame size: 1280*720
frame rate: 30
fmt type: 875967048
Driver: "bm2835 mmal"
Card: "mmal service 16.1"
Bus: "platform:bcm2835-v4l2"
Version: 1.0
Capabilities: 85200005
Input: 0
V4L2 pixel formats:
0: [0x32315559] 'YU12' (Planar YUV 4:2:0)
1: [0x56595559] 'YUYV' (YUYV 4:2:2)
2: [0x33424752] 'RGB3' (24-bit RGB 8-8-8)
3: [0x4745504A] 'JPEG' (JFIF JPEG)
4: [0x34363248] 'H264' (H.264)
5: [0x47504A4D] 'MJPG' (Motion-JPEG)
6: [0x55595659] 'YVYU' (YVYU 4:2:2)
7: [0x59555956] 'VYUY' (VYUY 4:2:2)
8: [0x59565955] 'UYVY' (UYVY 4:2:2)
9: [0x3231564E] 'NV12' (Y/CbCr 4:2:0)
10: [0x33524742] 'BGR3' (24-bit BGR 8-8-8)
11: [0x32315659] 'YV12' (Planar YVU 4:2:0)
12: [0x3132564E] 'NV21' (Y/CrCb 4:2:0)
13: [0x34524742] 'BGR4' (32-bit BGRA/X 8-8-8-8)
PYLIVE version: 0.3
unicast url: unicast
Number of frame queue(queueSize): 10
rtspPort: 8554
rtspOverHTTPPort: 0
verbose(0,1,2): 0
RTCP expiration timeout in seconds(timeout): 65
repeat config before IDR frame(repeatConfig): 1
audioFreq: 44100
audioNbChannels: 2
audioFmt(default S16_BE): 2018-12-09 17:57:46,166 [NOTICE] - pylive/LibLive.cpp:229
	Create ALSA Source...default
2018-12-09 17:57:46,166 [NOTICE] - pylive/DeviceSource.cpp:63
	begin thread
2018-12-09 17:57:46,166 [NOTICE] - pylive/ALSACapture.cpp:27
	Open ALSA device: "default"
2018-12-09 17:57:46,166 [NOTICE] - pylive/H264_V4l2DeviceSource.cpp:48
	profile-level-id=640028;sprop-parameter-sets=J2QAKKwrQCgC3QDxImo=,KO4CXLA=
2018-12-09 17:57:46,177 [ERROR ] - pylive/ALSACapture.cpp:34
	cannot open audio device: default error:No such file or directory
2018-12-09 17:57:46,177 [NOTICE] - pylive/ALSACapture.cpp:83
	ALSA device: "default" buffer_size:0 period_size:0 rate:44100
2018-12-09 17:57:46,177 [NOTICE] - pylive/LibLive.cpp:98
	Play this stream using the URL "rtsp://192.168.11.12:8554/unicast"
RTCPInstance::RTCPInstance error: totSessionBW parameter should not be zero!
2018-12-09 18:01:17,861 [NOTICE] - pylive/DeviceSource.cpp:110
	V4L2DeviceSource::doStopGettingFrames
2018-12-09 18:01:17,861 [NOTICE] - pylive/DeviceSource.cpp:110
	V4L2DeviceSource::doStopGettingFrames

 

可以判讀結果乎◎