I'm attmepting to open a video file in OpenCV following the tutorials seen here OpenCV Python Tutorial
However, upon running the block of code nothing happens. My code is as follows:
import numpy as np
import cv2
cap = cv2.VideoCapture('768x576.avi')
while(cap.isOpened()):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
I have ffmpeg installed on my system & in my system path. Additionally I have gstreamer installed on my machine as well. This file can be opened in windows media player, manipulated in ffmpeg & also opened in VLC.
I'm at a loss here as this should be a straight forward tutorial.
Edit 1: I've installed a bunch of different codecs including the K-Lite Codec Pack and XVid. If I open the file with ffmpeg -i this is what I get
C:\sandbox>ffmpeg -i 768x576.avi
ffmpeg version N-64539-gc8b2cf4 Copyright (c) 2000-2014 the FFmpeg developers
built on Jul 8 2014 22:10:23 with gcc 4.8.3 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-
libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libope
njpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsox
r --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab -
-enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx
--enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-
libxavs --enable-libxvid --enable-decklink --enable-zlib
libavutil 52. 91.100 / 52. 91.100
libavcodec 55. 68.102 / 55. 68.102
libavformat 55. 45.100 / 55. 45.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 10.100 / 4. 10.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, avi, from '768x576.avi':
Metadata:
encoder : MEncoder 2:1.0~rc2-0ubuntu19
Duration: 00:01:19.50, start: 0.000000, bitrate: 818 kb/s
Stream #0:0: Video: msmpeg4v3 (div3 / 0x33766964), yuv420p, 768x576, 816 kb/
s, 10 fps, 10 tbr, 10 tbn, 10 tbc
At least one output file must be specified
Edit 2: When I try to do this line by line the following happens
C:\sandbox>python
Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun 11 2014, 10:40:02) [MSC v.1
500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>>
>>> import numpy as np
>>> import cv2
>>> print cv2.__version__
2.4.9
>>>
>>> cap = cv2.VideoCapture('768x576.avi')
>>> print cap
<VideoCapture 0000000002DC3810>
>>> print cap.get(5)
0.0
>>>
Edit 3: The answer wasn't the 100% answer but the comments going down that rabbit hole lead me to this OpenCV VideoCapture cannot read video in Python but able in VS11 and THAT is how I figured out my issue