4,270
社区成员
发帖
与我相关
我的任务
分享import cv2
import subprocess as sp
import subprocess as sp
rtmpUrl = "rtmp://39.107.26.100:1935/myapp/test1"
camera_path = "video.mp4"
cap = cv2.VideoCapture(camera_path)
# Get video information
fps = int(cap.get(cv2.CAP_PROP_FPS))
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# ffmpeg command
command = ['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]
# 管道配置
p = sp.Popen(command, stdin=sp.PIPE)
# read webcamera
while (cap.isOpened()):
ret, frame = cap.read()
# print("running......")
if not ret:
print("Opening camera is failed")
break
p.stdin.write(frame.tostring())
return_value, frame = cap.read()
4,270
社区成员
发帖
与我相关
我的任务
分享加载中
OpenCV中国团队官方博客:https://blog.csdn.net/opencvchina
试试用AI创作助手写篇文章吧