Untitled
unknown
python
10 months ago
956 B
10
Indexable
import cv2
def convert_video(input_path, output_path):
# Đọc video gốc
cap = cv2.VideoCapture(input_path)
# Lấy thông tin video
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = cap.get(cv2.CAP_PROP_FPS)
# Thử với các codec khác nhau
fourcc = cv2.VideoWriter_fourcc(*'avc1') # hoặc 'XVID', 'H264', 'MP4V'
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
# Ghi frame vào video mới
out.write(frame)
cap.release()
out.release()
print(f"Đã chuyển đổi video sang: {output_path}")
# Sử dụng
input_video = r"C:\Users\Huy\Pictures\video1.mp4"
output_video = r"C:\Users\Huy\Pictures\video1_h264.mp4"
convert_video(input_video, output_video) Editor is loading...
Leave a Comment