Skip to content
Advertisement

opencv cant write video from camera on python

im trying to save a video i get from a facetime camera on mac, i manage to show the video and flip it, but when i try to save it i get no file at all, and it wont show me any error, it did use to show me an error CAP_IMAGES: can’t find starting number (in the name of file): that it was a codec error related, i installed ffmpeg as sugested on other post and i did set the codec to mp4v, still i cant write the file, i do want to write it to a file and then broadcast via web (security camera)

any idea what might be wrong? i paste my code below, thanks

here is the code im using

JavaScript

Edit1: i did follow Christof advice and be more especific when opening the device, still i get the same behaivior i would try also using a debugger and see where the problem is, below is my new code

JavaScript

Edit2: simplyfied the code and set only first device i only get 0 anyway, heres my code using if not cap.isOpened()

JavaScript

Edit3: posting the general config for opencv on my machine, i did installed using pip command from terminal but before that i updated homebrew, for some reason homebrew erased all previuos stuff i had installed via pip so i had to reinstall opencv, wheels and all other stuff, im posting my modules as well

JavaScript

this are the modules installed by python via terminal

JavaScript

Advertisement

Answer

Instantiation of a VideoWriter appears to have failed. You say salida.isOpened() returns False.

VideoWriter usually requires that OpenCV was built with support for ffmpeg. Other backends, such as AVFoundation, commonly are only used to access video cameras.

Since your OpenCV was built without support for ffmpeg, your only option is to use the .avi video container format and the MJPG codec/fourcc. Those two are built into OpenCV and always available.

If you haven’t already got OpenCV for Python from PyPI, via the opencv-python package (or one of its variants), then you should try that. It’s the official OpenCV package for Python.

If you are willing to build OpenCV yourself, you can enable and disable features, and third-party dependencies, in the CMake configuration stage.

Advertisement