2023/3/2

bing 寫的,read input video resize and save to modified filename

主要是紀錄一下python 讀argument 和 filename 操作的code:
import cv2
import sys
import os

input_file = sys.argv[1]
path, filename = os.path.split(input_file)
filename, ext = os.path.splitext(filename)

output_file = filename + "s" + ext

cap = cv2.VideoCapture(input_file)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

fourcc = cv2.VideoWriter_fourcc(*'mp4v')
fps = cap.get(cv2.CAP_PROP_FPS)
out = cv2.VideoWriter(output_file, fourcc, fps, (width//2, height//2))

while cap.isOpened():
    ret, frame = cap.read()
    if ret:
        resized_frame = cv2.resize(frame, (width//2, height//2))
        out.write(resized_frame)
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

沒有留言:

張貼留言