0

Actually I was loading a video Using k=cv2.VideoCapture("it.mp4") which is in the same folder but when I check it is opened or not it shows "False". and when i use k.open() to open it, it shows me this error:

Traceback (most recent call last):
File "", line 1, in
TypeError: Required argument 'filename' (pos 1) not found

As I think it is not getting the file but the video is in the same folder. I am stuck on this since a long time.

Here is the code:-

import numpy as np
import cv2
cap=cv2.VideoCapture("it.mp4")
k=cap.isOpened()
if k==False:
    cap.open()

And it shows the below error:-

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Required argument 'filename' (pos 1) not found
3
  • 1
    Does it open when you give it the absolute path? Commented Sep 10, 2017 at 16:12
  • @Zindarod Thanx for the comment, and it don't open the video when i give absolute path. Commented Sep 10, 2017 at 16:19
  • Post your code. Commented Sep 10, 2017 at 16:30

2 Answers 2

2

By looking at your code it is easy to figure out why you are getting this error. The reason is that you are using cap.open() without any arguments. You need to pass the filename to cap.open() in order to initialize the cv2.VideoCapture. So your code should be

import numpy as np
import cv2
cap=cv2.VideoCapture("it.mp4")
k=cap.isOpened()
if k==False:
   cap.open("it.mp4")

In order to read the frames from cap you can use a loop like this

while(True):
     ret, frame = cap.read()
     cv2.imshow('frame',frame)
     if cv2.waitKey(1) & 0xFF == ord('q'):
        break
Sign up to request clarification or add additional context in comments.

1 Comment

@Lakshaykejriwal thanx for helping but when i am typing cap.open("it.mp4) it is showing me Flase. It is not reading that video file. How to fix that?
0

You need to pass an argument for the cap.open(). In your case-

cap.open("it.mp4")

It must either be the device id in case you are using a camera or a filename which you want to read. Check out the page here.

But the actual issue here i think is that your opencv is not able to read the video you passed and which is the issue you are trying to fix. Either the file name or the extension is wrong.

If its neither, simply go to the path C:\opencv\build\x86\vc12\bin , copy the opencv_ffmpegabcd.dll and paste it in your python root directory. abcd here is your opencv version. If its a 64bit setup, copy the corresponding one.

4 Comments

I.Newton i am using linux and here i can't find opencv_ffmpeg.dll.
1. Try converting the .mp4 to .avi (can do with vlc player) and try. Sometimes its an easy fix 2. To configure ffmpeg properly, follow this link.
I installed ffmpeg in absolutely correct way but still it is not reading the video file. When i use cap.open("it.mp4"). It shows me "False"
cap.isOpened() still gives you false? That shouldn't have happened if 1. Your video name, extension are correct. 2 ffmpeg is alright. Try the video in .avi . Also check this correct way with ffmpeg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.