【python】两个视频抽帧横向合并为新视频

用于对比YOLO视频检测出来的实验结果

import cv2
import numpy as np


if __name__ == '__main__':
    source1 = "video/test1.mp4"
    source2 = "video/test2.mp4"

    RESULT_PATH = 'result.mp4'

    vidcap1 = cv2.VideoCapture(source1)
    vidcap2 = cv2.VideoCapture(source2)
    success1, image1 = vidcap1.read()
    success2, image2 = vidcap2.read()

    videoWriter = None

    count = 0
    while success2 and success1:

        image = np.concatenate([image1, image2], axis=1)
        # cv2.imwrite('images/{}.jpg'.format(i), image)
        cv2.putText(image1, source1,  (5,50), 0, 0.5, [225, 255, 255], thickness=1, lineType=cv2.LINE_AA)
        cv2.putText(image2, source2,  (5,50), 0, 0.5, [225, 255, 255], thickness=1, lineType=cv2.LINE_AA)
        if videoWriter is None:  # 初始化输出格式和相关信息
            # 指定视频编码格式 MPEG-4编码 .mp4 可指定结果视频的大小
            fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')  # opencv3.0
            # VideoWriter(filename, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object
            # 设置输出的路径,格式,fps,帧图片的大小
            videoWriter = cv2.VideoWriter(
                RESULT_PATH, fourcc, 30, (image.shape[1], image.shape[0]))
        videoWriter.write(image)

        # 接着读取
        success1, image1 = vidcap1.read()
        success2, image2 = vidcap2.read()
        # print('Read a new frame: ', success1)
        count += 1
    videoWriter.release()
    vidcap1.release()
    vidcap2.release()



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值