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
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36

2 Answers2

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
Lakshya Kejriwal
  • 1,340
  • 4
  • 17
  • 27
  • @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? –  Sep 11 '17 at 08:27
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.

I.Newton
  • 1,753
  • 1
  • 10
  • 14
  • I.Newton i am using linux and here i can't find opencv_ffmpeg.dll. –  Sep 11 '17 at 08:42
  • **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.](https://stackoverflow.com/questions/11444926/videocapture-is-not-working-in-opencv-2-4-2/11465097#11465097) – I.Newton Sep 11 '17 at 09:02
  • 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" –  Sep 12 '17 at 05:13
  • 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](https://stackoverflow.com/questions/31040746/cant-open-video-using-opencv) – I.Newton Sep 12 '17 at 05:46