opencv / opencv/opencv-python

VideoWriter fails silently for multiple codecs on macOS Intel

Open
#1,192 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.4k
Forks
1k
Avg merge
22h 17m
Merged PRs (30d)
3

Description

Summary

cv2.VideoWriter fails silently for multiple codecs (HFYU, XVID, mp4v) on macOS Intel (x86_64) in opencv-python-headless 4.13.0.90. No exception is raised, but isOpened() returns False and no video file is created.

This is a regression from 4.12.0.88, where all codecs work correctly.

Environment

  • OpenCV version: opencv-python-headless 4.13.0.90
  • Python version: 3.10.18
  • OS: macOS 15.7.2 (x86_64 / Intel)

Note: This bug only affects macOS Intel (x86_64), not macOS ARM (Apple Silicon).

Steps to reproduce

import os
import tempfile

import cv2
import numpy as np

print(f"OpenCV version: {cv2.__version__}")

test_dir = tempfile.mkdtemp()

codecs = ["MJPG", "HFYU", "XVID", "mp4v"]

print("\nTesting VideoWriter codecs:")
print("-" * 40)

for codec in codecs:
    video_path = os.path.join(test_dir, f"test_{codec}.avi")

    writer = cv2.VideoWriter(
        filename=video_path,
        fourcc=cv2.VideoWriter_fourcc(*codec),
        fps=25,
        frameSize=(200, 100),
    )

    opened = writer.isOpened()
    status = "OK" if opened else "FAILED"

    if opened:
        frame = np.random.randint(0, 255, size=(100, 200, 3), dtype="uint8")
        writer.write(frame)
        writer.release()
        os.remove(video_path)
    else:
        writer.release()

    print(f"{codec:6} : {status}")

os.rmdir(test_dir)

Expected behavior

All standard codecs should work:

OpenCV version: 4.12.0

Testing VideoWriter codecs:
----------------------------------------
MJPG   : OK
HFYU   : OK
XVID   : OK
mp4v   : OK

Actual behavior

Only MJPG works; other codecs fail silently:

OpenCV version: 4.13.0

Testing VideoWriter codecs:
----------------------------------------
[ WARN:0@0.056] global cap.cpp:781 open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.13.0) /Users/macmini_16g/GHA-Actions-Opencv-Python/_work/opencv-python/opencv-python/opencv/modules/videoio/src/cap_images.cpp:411: error: (-215:Assertion failed) !filename_pattern.empty() in function 'CvVideoWriter_Images'


MJPG   : OK
[ WARN:0@0.104] global cap.cpp:781 open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.13.0) /Users/macmini_16g/GHA-Actions-Opencv-Python/_work/opencv-python/opencv-python/opencv/modules/videoio/src/cap_images.cpp:411: error: (-215:Assertion failed) !filename_pattern.empty() in function 'CvVideoWriter_Images'


HFYU   : FAILED
[ WARN:0@0.104] global cap.cpp:781 open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.13.0) /Users/macmini_16g/GHA-Actions-Opencv-Python/_work/opencv-python/opencv-python/opencv/modules/videoio/src/cap_images.cpp:411: error: (-215:Assertion failed) !filename_pattern.empty() in function 'CvVideoWriter_Images'


XVID   : FAILED
mp4v   : FAILED

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Python reproduction with opencv-python-headless 4.13.0.90 and compare it with 4.12.0.88 on macOS Intel. Investigate the cv2.VideoWriter path and the reported codec-specific failures; done means HFYU, XVID, and mp4v open successfully and create video files without regressing MJPG.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
audio-video-rtc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.