Opencv-python: cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

Created on 9 Jan 2020  路  5Comments  路  Source: opencv/opencv-python

Expected behavior

I am using Opencv Python version 4.1.2.30 for write image to video as mention in code but unfortunately when I run Script in Pycharm it run correctly but when I convert script to EXE from pyinstaller with PYQT5 its give me error like as below.
'

Actual behavior

[ERROR:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp (392) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): Detected_video.avi in function 'cv::icvExtractPattern

Steps to reproduce

  • example code
    pathIn = IMG_OUTPUT_FOLDER image_interval = 1 # Interval between two images fps = 1 / image_interval files = video_df frame_array = [] for i in range(len(files.index)): img_name = files.loc[i, 'Image_Name'] filename = os.path.join(pathIn, img_name) # reading each files img = cv2.imread(filename) height, width, layers = img.shape size = (width, height) # inserting the frames into an image array frame_array.append(img) os.chdir(VIDEO_OUTPUT_FOLDER) out = cv2.VideoWriter("Detected_video.avi", cv2.VideoWriter_fourcc(*'DIVX'), fps, size) for i in range(len(frame_array)): # writing to a image array out.write(frame_array[i]) out.release() os.chdir(CWD_PATH)
  • operating system
    windows 10
  • architecture (e.g. x64)
  • opencv-python version 4.1.2.30

Most helpful comment

Only reason I can think of is that PyInstaller does not copy the FFmpeg dll during the packaging process.

If you have a look at e.g. ...Python37\Lib\site-packages\cv2 folder, there is something like opencv_videoio_ffmpeg412_64.dll next to cv2.cp37-win_amd64.pyd.

Does the opencv_videoio_ffmpeg412_64.dll file exist in the package which was created in PyInstaller? If not, add it to the spec file (binaries): https://pyinstaller.readthedocs.io/en/stable/spec-files.html#spec-file-operation

All 5 comments

Only reason I can think of is that PyInstaller does not copy the FFmpeg dll during the packaging process.

If you have a look at e.g. ...Python37\Lib\site-packages\cv2 folder, there is something like opencv_videoio_ffmpeg412_64.dll next to cv2.cp37-win_amd64.pyd.

Does the opencv_videoio_ffmpeg412_64.dll file exist in the package which was created in PyInstaller? If not, add it to the spec file (binaries): https://pyinstaller.readthedocs.io/en/stable/spec-files.html#spec-file-operation

Hello, I do not know if you can explain a little more please, because I did not understand much, I have the same problem and try to apply the solution but I still get the same error.

84565078_2873661995988770_1375629178245742592_n

opencv_videoio_ffmpeg412_64.dll file exist in the package which was created in PyInstaller
but still i get error

This is not PyInstaller support forum. Please open an issue to PyInstaller repository if you encounter issues with PyInstaller.

Check if the path to the video file is correct or files exist. This mistake appears when you try implement .shape to the empty frame Also it is possible if a variable was inited inside an internal function and you try to call it otside

Was this page helpful?
0 / 5 - 0 ratings