[小脚本] 合并显示两个视频文件

就是给定连个视频一左一右显示, 方便对比

import numpy as np
import cv2 as cv
import cv2
def run():
    f1()

def f1():
    n = len(sys.argv)
    f1="./1.avi"
    f2="./2.avi"
    f3="./out.avi"

    if n==2:
        f2=sys.argv[1]
    elif n==3:
        f1=sys.argv[1]
        f2=sys.argv[2]
    elif n==4:
        f1=sys.argv[1]
        f2=sys.argv[2]
        f3=sys.argv[3]

    #video1 = cv2.VideoCapture('./videos/1.fit.avi')
    video1 = cv2.VideoCapture(f1)
    video2 = cv2.VideoCapture(f2)

    fps, width, height = get_info_from_video(video1)
    
    # fourcc = cv2.VideoWriter_fourcc(*'MP4V')
    videoWriter = cv2.VideoWriter(f3, cv2.VideoWriter_fourcc(*'XVID'), fps, (width, height//2))
    
    cnt=0
    res=1
    while res:
        res, frame1 = video1.read()
        if not res: break
        res, frame2 = video2.read()
        if not res: break
        frame1 = cv2.resize(frame1, (int(width // 2), int(height//2)), interpolation=cv2.INTER_CUBIC)
        frame2 = cv2.resize(frame2, (int(width // 2), int(height//2)), interpolation=cv2.INTER_CUBIC)
        img = np.hstack((frame1, frame2))
        #if 27==showimg(frame1): break
            
        videoWriter.write(img)
        cnt+=1
        if cnt%100==0: print(cnt)
    
    print(cnt)

    videoWriter.release()
    video1.release()
    video2.release()
    

   
def get_info_from_video(video):
    fps = int( video.get(cv2.CAP_PROP_FPS) )
    width = (int(video.get(cv2.CAP_PROP_FRAME_WIDTH)))
    height = (int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)))
    return fps, width, height

补一个减少视频大小的方法

ffmpeg -i out.avi -b:v 400k out.mp4
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值