From b5ab22c8f1183bb68a979f1124b3086a54674def Mon Sep 17 00:00:00 2001 From: p26398547 Date: Tue, 21 Nov 2023 21:28:33 +0800 Subject: [PATCH] ADD file via upload --- main.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..0adfe1c --- /dev/null +++ b/main.py @@ -0,0 +1,54 @@ +from ffmpy3 import FFmpeg +from cv2 import cv2 +import subprocess + +rtmpUrl = "rtmp://175.24.114.42:1935/myapp/test" +camera_path = "output.mp4" +cap = cv2.VideoCapture(0) + +reRate=0.6 #缩放比例 + +# Get video information +fps = int(cap.get(cv2.CAP_PROP_FPS)) +width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)*reRate) +height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)*reRate) + +# ffmpeg command +PicCommand = ['ffmpeg', + '-y', + '-f', 'rawvideo', + '-vcodec','rawvideo', + '-pix_fmt', 'bgr24', + '-s', "{}x{}".format(width, height), + '-r', str(fps), + '-i', '-', + '-c:v', 'libx264', + '-pix_fmt', 'yuv420p', + '-preset', 'ultrafast', + '-f', 'flv', + rtmpUrl] + + +SouCmd = ['ffmpeg', + '-re', + '-i', + '''C:\\1.mp3''', + '-vn', + '-acodec', + 'copy', + '-f', 'flv', + rtmpUrl] + +# 管道配置 +p = subprocess.Popen(PicCommand, stdin=subprocess.PIPE,shell=False) + +# read webcamera +while(cap.isOpened()): + ret, frame = cap.read() + reFrame=cv2.resize(frame,(0,0),None,reRate,reRate) + if not ret: + print("Opening camera is failed") + break + + + p.stdin.write(reFrame.tostring())