First you could try with full path
videoFile = "/full/path/to/Test Tom and Jerry.mp4"
because code may run in different folder then you expect and then relative path may not find file. And cv2
doesn’t raise error when it can’t read file but it returns False
in cap.isOpened()
and in ret, frame = cap.read()
You can check "Current Working Directory"
with
import os
print( os.getcwd() )
You could also check if you have problem with other files and with different compressions. This way you can recognize if this is not problem with codec.
If you run code in script (not in Jupyter, IPython or other console) then you can get full path to folder with your script and use it to generate full path to other files
import os
BASE = os.path.dirname(os.path.abspath(__file__))
videoFile = os.path.join(BASE, "../Test Tom and Jerry.mp4")
By the way:
"\t"
has special meaning in string - it means key <tab>
- so path "\Test\test%d.jpg"
means "\Test<tab>est%d.jpg"
. Use /
instead of \
like /Test/test%d.jpg
or double \\
like "\\Train\\test%d.jpg"
or use prefix r
for "raw"
string like r"\Train\test%d.jpg"