VideoWriter not writing anything
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 50/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- opencv, python
- Domain
- computer-vision
Research direction
Start by running the supplied main.py with video.mp4 in the stated Python and OpenCV environment, then inspect the generated output.mp4 and the VideoWriter setup. Compare it with the working ffmpeg-converted out.mp4; done means the script itself produces a playable output.mp4 without requiring a conversion step.
Written by the indexing model from the issue text.
Description
Description
cv2.VideoWriter is creating a file but not writing anything in the video
Environment
Ubuntu 25.04
Python 3.13.3
Open CV 4.13.0
How to recreate
Create main.py with the file content.
Create a video file named video.mp4
mkdir .venv
python -m venv .venv
. .venv/bin/activate
pip install opencv-contrib-python
python main.py
And I get the following output with a corrupted output.mp4 file:
OpenCV Version:
4.13.0
codec
1983148141
shape
(1576, 770)
fps
24.0
However, if I run
ffmpeg -i output.mp4 out.mp4
out.mp4 works
File
import cv2
import time
video = cv2.VideoCapture("video.mp4")
fps = video.get(cv2.CAP_PROP_FPS)
shape = (int(video.get(cv2.CAP_PROP_FRAME_WIDTH)), int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
writer = cv2.VideoWriter("output.mp4", fourcc, fps, shape)
print("OpenCV Version:")
print(cv2.__version__)
print("codec")
print(fourcc)
print("shape")
print(shape)
print("fps")
print(fps)
time.sleep(1.0)
while True:
ret, frame = video.read()
if not ret or frame is None:
break
if frame.ndim == 2:
frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
writer.write(frame)
video.release()
writer.release()
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 1k
- Avg merge
- 22h 17m
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from opencv/opencv-python
-
[DOC] README file Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
opencv/opencv-python#1217 · 3 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
opencv/opencv-python#1165 · 2 comments · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
opencv/opencv-python#1273 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
opencv/opencv-python#1272 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
opencv/opencv-python#1268 · 1 comment ·
All issues in opencv/opencv-python
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100