ADD file via upload

This commit is contained in:
p26398547 2023-11-21 21:28:33 +08:00
parent 3eb92c350d
commit b5ab22c8f1
1 changed files with 54 additions and 0 deletions

54
main.py Normal file
View File

@ -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())