import cv2
import ffmpeg
import cv2
import numpy as np
import glob
video_f = 'D:/.Download/cctv.mp4' # 视频文件名
output_f = 'D:/.Download/logoafter.mp4' # 输出视频文件名
video = cv2.VideoCapture(video_f)
# 获取视频宽度
frame_width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
# 获取视频高度
frame_height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(frame_height,frame_width)
start_x, start_y, w, h = 740,420, 100, 28 # logo位置
logo_f = '1.jpg'
logo = cv2.imread(logo_f)
logo = cv2.resize(logo, (w,h))
print(logo.shape)
ret, frame = video.read()
img_h, img_w = frame.shape[:2]
output_video = cv2.VideoWriter(output_f, cv2.VideoWriter_fourcc(*'DIV3'), 30, (img_w, img_h))
idx = 0
while True:
ret, frame = video.read()
print(type(frame))
print(frame.shape)
idx += 1
if frame is None:
break
if idx > 0 and idx < 1213:
frame[start_y:start_y + h, start_x:start_x + w, :]=logo
output_video.write(frame)
cv2.imshow('f', frame)
print(idx)
cv2.waitKey(1)