VideoWriter not writing anything
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 1k
- Avg merge
- 22h 17m
- Merged PRs (30d)
- 3
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()
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.
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.
Assessment
- Tech stack
- opencv, python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100