cv2.VideoWriter_fourcc()支持MP4格式的参数
时间: 2023-05-31 11:06:53 浏览: 424
cv2.VideoWriter_fourcc()支持MP4格式的参数包括:
- MP4V:MPEG-4 Part 2 video codec
- X264:H.264/MPEG-4 AVC video codec
- XVID:MPEG-4 Part 2 video codec
- AVC1:Advanced Video Coding (H.264) video codec
示例代码:
```python
import cv2
# 设置输出视频文件名、编码器、帧率、分辨率
out = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'MP4V'), 25, (640, 480))
# 读取输入视频文件
cap = cv2.VideoCapture('input.avi')
while cap.isOpened():
ret, frame = cap.read()
if ret:
# 处理每一帧图像
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# 写入输出视频文件
out.write(frame)
# 显示处理后的图像
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
```
阅读全文