import cv2
import imageio
from tqdm import tqdm
from pathlib import Path
if __name__ == '__main__':
cap = cv2.VideoCapture("test2.mp4")
fps = int(cap.get(cv2.CAP_PROP_FPS))
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
print(fps, frame_count)
print(height, width)
# fourcc = cv2.VideoWriter_fourcc(*'MP42')
# videoWrite = cv2.VideoWriter("split.avi", fourcc, fps, (width,height))
imageio_writer = imageio.get_writer("io.mp4", fps=fps)
n, cnt= 0, 0
pbar = tqdm(total=frame_count)
while cap.isOpened():
ret, frame = cap.read()
if ret and (frame is not None):
n += 1
cnt = 0
# videoWrite.write(frame)
imageio_writer.append_data(frame[...,::-1])
if n > fps*60*13:
break
elif (not ret) and (frame is None):
cnt += 1
if cnt >= 5000:
break
else:
print(f"ret:{ret}\tframe:{frame}\tn:{n}\ti:{i}")
pbar.update()
pbar.close()
# videoWrite.release()
imageio_writer.close()
cap.release()
cv2.destroyAllWindows()
python图片合成视频
最新推荐文章于 2024-07-14 15:11:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)