'"Can't find starting number (in the name of file)" when trying to read frames from hevc (h265) video in opencv

I'm trying to read frames from a hevc(h265) .avi video in opencv-python (python3, latest version) but keeps throwing

OpenCV(4.1.1) 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): C:\Users\gabri\Desktop\2019-11-22_13\a.avi in function 'cv::icvExtractPattern'.

I've tried both in ubuntu and windows 10 using opencv-python, opencv-contrib-python and opencv-contrib-python-nonfree, but it didn't work. Thank you in advance.

Code used to read the video:

import cv2
import imutils

cap = cv2.VideoCapture("C:\\Users\\gabri\\Desktop\\2019-11-22_13\\a.avi")


while True:
    ret,frame = cap.read()
    if not ret:
        break
    frame = imutils.resize(frame,width = 960)
    cv2.imshow('image',frame)

    k = cv2.waitKey(1) & 0xff

    if k == 27:
       break


Solution 1:[1]

Perhaps this is late, but definitely there will be other people who face the same issue.

You can get this error in VideoWriter class if you do not specify your extension in the file name, in my case I have forgotten to write .mp4.

Hopefully this helps.

Solution 2:[2]

I had the same problem, compilation and linking ok, but the same cryptic error occurs at running.

It happened (with Windows) when opencv_videoio_ffmpeg430_64.dll was not accessible (it seems to be silently called by another opencv lib). Either you did not build opencv with the -DWITH_FFMPEG=ON, or alternatively your dll is not in the path.

Solution 3:[3]

I fixed this by passing the absolute path into VideoCapture and changing the filename from example.mov to example_1000.mov.

Solution 4:[4]

this error normally pop-up when video_path in functions cap = cv2.VideoCapture("video_path") or cv2.VideoWriter('path_to_folder/output_save.avi') is not correct
Mostly seen in windows

Solution 5:[5]

I had the same error and solved it by changing the video name to '001.avi'.

Solution 6:[6]

Maybe you can append a number to your path like 'a2.avi' instead of 'a.avi'.

Solution 7:[7]

File extension was missing in my case: changing movie to movie.mp4 solved the issue

Solution 8:[8]

My use case is probably not what is being asked in the question however since the error message produced by opencv is slightly misleading I'll leave a note for others who might encounter similar problem.

In my case I was receiving following error because the file was corrupted:

OpenCV(4.5.1) cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): /path/to/file.png in function 'icvExtractPattern'

I was receiving files through AWS API gateway and in order to avoid files being corrupted I had to add 'multipart/form-data' within 'Binary Media Types' section of APIGateway app settings.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ghostpunk
Solution 2 PJ127
Solution 3 jimmy Howerton
Solution 4 Prajot Kuvalekar
Solution 5 cmj
Solution 6 HsLuoyang
Solution 7 Nir
Solution 8 Greg0ry