当前位置:   article > 正文

python 视频拼接_python视频拼接

python视频拼接
# -*- coding:utf-8 -*-
'''
 视频拼接
'''
import cv2
import numpy as np
 
cam1 = cv2.VideoCapture("./1sample_video.mp4")
cam2 = cv2.VideoCapture("./2sample_video.mp4")
 
# 获取视频1的宽度
ww = int(cam1.get(3))
# 获取视频1的高度
hh = int(cam1.get(4))
print(ww, hh)
# 获取视频的帧频
CAMERA_FPS = cam1.get(cv2.CAP_PROP_FPS)  
# 定义视频编码格式
fourcc = cv2.VideoWriter_fourcc(*'XVID')#也可以是'WMV1',其他格式参考https://www.fourcc.org/codecs.php
# 创建视频保存对象
videoWriter = cv2.VideoWriter('./out.avi', fourcc, CAMERA_FPS,(ww * 2, hh))#当是'WMV1'时,out.wmv

 
while True:
    # 读取视频
    (ok1, frame1) = cam1.read()
    (ok2, frame2) = cam2.read()
    if ok1 and ok2:
        # 重置视频大小,使两视频大小一致
        frame1 = cv2.resize(frame1, (ww, hh))
        frame2 = cv2.resize(frame2, (ww, hh))
        # 在视频中添加文字
        cv2.putText(frame1, "Video 1", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 2.0, (0, 255, 0), 2)
        cv2.putText(frame2, "Video 2", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 2.0, (0, 255, 0), 2)
        # 拼接处理
        image = np.concatenate([frame1, frame2], axis=1)  # axis=0时为垂直拼接;axis=1时为水平拼接
        
        # 视频保存
        videoWriter.write(image)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break
 
videoWriter.release()
cam1.release()
cam2.release()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/80558
推荐阅读
相关标签
  

闽ICP备14008679号