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

10

20

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
Natalyanataniel answered 4/12, 2019 at 3:18 Comment(3)
I am not sure if that's your case but you need to set the codec as already answered here : #27392955Cree
Did you try it with cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('H', '2', '6', '5')); ?Cree
I've had the same error while trying to open a file in the wrong directory, so the error message was completely misleading, should have been "File not found".Tyra
G
17

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

Greatest answered 13/6, 2021 at 22:55 Comment(1)
In my case there was an extra space after mpegOnetoone
G
8

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

Goforth answered 21/4, 2021 at 17:10 Comment(0)
W
7

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

Willyt answered 7/7, 2021 at 1:27 Comment(0)
S
5

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.

Spermatophyte answered 12/5, 2020 at 10:15 Comment(1)
I had this same issue (on Ubuntu), which I resolved by adding ffmpeg to my OpenCV build. For future readers: If you build OpenCV yourself, look through the output of cmake for FFMPEG: YES. If you see FFMPEG: NO, then cmake was not able to locate the development files for ffmpeg.Predecease
A
3

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

Ashford answered 8/10, 2021 at 6:41 Comment(0)
L
2

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

Lawsuit answered 16/8, 2020 at 8:17 Comment(3)
"Maybe you can append a number to your path", maybe you wanted to say "to your filename"?Tyra
Consider adding an explanation for making such a change. Also, often the file path will be taken as an input, which we'll have to use as it is regardless of the whatever filename we are givenBlacking
Why would that fix the problem?Dogtrot
F
0

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

Fabyola answered 1/1, 2022 at 18:38 Comment(0)
K
0

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.

Kalmar answered 16/3, 2022 at 10:42 Comment(0)
G
0

For me, the problem was the filename needs to have a number on it. So in your case perhaps you can rename your file to a0.avi

Gerick answered 20/9, 2022 at 9:17 Comment(1)
CAP_IMAGES is the last reader module that is tried, meaning the usual modules (for video files and for camera devices) failed to make sense of the file name you passed or the file's content. -- CAP_IMAGES is for image sequences, i.e. numbered file names... for video files, no such logic exists. your perceived requirement does not exist and adding numbers to the name of a video file does nothing.Delitescent
E
0

For me, the error occurred before I was able to approve access to the camera. After I approved the use of the camera for the application, it worked.

Excavation answered 3/2, 2023 at 22:31 Comment(1)
How do you approve access to a camera???Suilmann

© 2022 - 2024 — McMap. All rights reserved.