opencv python ffmpeg加水印推流

pip install opencv-python

pip install 安装软件指定版本

>pip install opencv-contrib-python==3.4.2.16

安装numpy

>pip install numpy

加水印推流

import cv2
import datetime
import numpy as np
import subprocess

# 视频采集 VideoCapure(res) 中参数是0,表示打开笔记本的内置摄像头,参数是视频文件路径则打开
# cap.read() 返回两个值,第一个为状态值,读到帧为true,第二个值为视频帧
# cap.release() 释放

cv2.namedWindow("img1", cv2.WINDOW_AUTOSIZE)    # 创建窗口
cap = cv2.VideoCapture("images\\car.mp4")
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
sizeStr = str(size[0]) + 'x' + str(size[1])

# RTMP服务器地址
rtmp = r'rtmp://txy.live-send.acg.tv/live-txy/'

command = ['ffmpeg',
    '-y', '-an',
    '-f', 'rawvideo',
    '-vcodec','rawvideo',
    '-pix_fmt', 'bgr24',
    '-s', sizeStr,
    '-r', '25',
    '-i', '-',
    '-c:v', 'libx264',
    '-pix_fmt', 'yuv420p',
    '-preset', 'ultrafast',
    '-f', 'flv',
    rtmp]
pipe = subprocess.Popen(command, shell=False, stdin=subprocess.PIPE)

while True:
    ret, frame = cap.read()
    if ret:
        str1 = str(datetime.datetime.now())
        AddText = frame.copy()

        cv2.putText(frame, str1, (50, 50), cv2.FONT_HERSHEY_COMPLEX, 1, (10, 20, 30), 1)
        res = np.hstack([frame, AddText])

        cv2.imshow('video', frame)

    # key = cv2.waitKey(60)  # waitKey() 函数的功能是不断刷新图像 , 频率时间为delay , 单位为ms

    if (cv2.waitKey(60) & 0xff == ord('q')):
        break

    pipe.stdin.write(frame.tostring())

cap.release()
pipe.terminate()
cv2.destroyAllWindows()

你可能感兴趣的:(python,opencv,python,pip,opencv)