opencv-python icon indicating copy to clipboard operation
opencv-python copied to clipboard

Updated to Python 3.13 - Getting error creating video: "Could not find a valid device; can't configure encoder"

Open gloriouslyawkwardlife opened this issue 7 months ago • 0 comments

Raspberry Pi 5B, running Python 3.13.3…

I've started getting the following error since updating from Python 3.11 to Python 3.13:

[h264_v4l2m2m @ 0x555620e12290] Could not find a valid device
[h264_v4l2m2m @ 0x555620e12290] can't configure encoder
[ERROR:[email protected]] global cap_ffmpeg_impl.hpp:3264 open Could not open codec h264_v4l2m2m, error: Unspecified error (-22)
[ERROR:[email protected]] global cap_ffmpeg_impl.hpp:3281 open VIDEOIO/FFMPEG: Failed to initialize VideoWriter

Relevant code:

        # use CV2 to compile the frames into a 60 fps video.
        images = [img for img in sorted(os.listdir('/home/steven/tmp')) if img.endswith('.png')]
        frame = cv2.imread(os.path.join('/home/steven/tmp',images[0]))
        height, width, layers = frame.shape
        video = cv2.VideoWriter(f"/home/steven/Videos/{datetime.fromtimestamp(start).strftime('%Y-%m-%d_%H-%M-%S')} - {datetime.fromtimestamp(end).strftime('%Y-%m-%d_%H-%M-%S')}.mp4", cv2.VideoWriter_fourcc(*'avc1'), 60, (width, height))
        for image in images:
            video.write(cv2.imread(os.path.join('/home/steven/tmp',image)))
        cv2.destroyAllWindows()
        video.release()

gloriouslyawkwardlife avatar Jun 04 '25 13:06 gloriouslyawkwardlife