小编Mit*_*don的帖子

使用 opencv 调整视频大小并保存

我正在尝试使用 opencv 重新调整视频大小,然后将其保存回我的系统。代码有效并且不会给出任何错误,但输出视频文件已损坏。我使用的 fourcc 是 mp4v,与 .mp4 配合良好,但输出视频仍然损坏。需要帮忙。

import numpy as np
    import cv2
    import sys
    import re
    vid=""
    
    if len(sys.argv)==3:
        vid=sys.argv[1]
        compress=int(sys.argv[2])
    else:
        print("File not mentioned or compression not given")
        exit()
    
    if re.search('.mp4',vid):
        print("Loading")
    else:
        exit()
    
    cap = cv2.VideoCapture(0)
    ret, frame = cap.read()
    
    def rescale_frame(frame, percent=75):
        width = int(frame.shape[1] * percent/ 100)
        height = int(frame.shape[0] * percent/ 100)
        dim = (width, height)
        return cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
    
    FPS= 15.0
    FrameSize=(frame.shape[1], frame.shape[0])
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')
    
    out = cv2.VideoWriter('Video_output.mp4', fourcc, FPS, …
Run Code Online (Sandbox Code Playgroud)

python opencv fourcc

6
推荐指数
1
解决办法
9429
查看次数

标签 统计

fourcc ×1

opencv ×1

python ×1