0

I read the following post Getting video properties with Python without calling external software and How can I identify a video format in Python3? and Extract metadata from a Video/Image since my goal is to read my *.mov video file metadata. My OpenCV version is 3.4.3 and I'm using the code as recommended in those discussions:

import cv2
vid = cv2.VideoCapture( 'test.mov')
height = vid.get(cv2.CAP_PROP_FRAME_HEIGHT) # always 0 in Linux python3
width  = vid.get(cv2.CAP_PROP_FRAME_WIDTH)  # always 0 in Linux python3
print ("opencv: height:{} width:{}".format( height, width))

However, both height and width are equal to 0. This cannot be possible. What am I doing wrong? Thanks

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Angelo
  • 1,594
  • 5
  • 17
  • 50
  • maybe you have to read first `frame` from stream. OR maybe `CV2` can't get this information for some video formats. Different format would need different code in `CV2` and someone would have to write it. – furas Jul 24 '21 at 22:20
  • BTW: as I know `CV2` may use `ffmpeg` or `gstream` for this - so it also use `external` program. Maybe it will be simpler to use directly `ffmpeg` or module `ffmpeg-python` or `MoviePy`. – furas Jul 24 '21 at 22:21
  • on `Linxu Mint 20.2` (based on `Ubuntu 20.04`) I used `ffmpeg` to convert file to `.mov`, `.avi`, `.mp4` and for all of them `cv2` gives me `height` and `width`. But I use the lastest `cv2` `'4.5.3'` – furas Jul 24 '21 at 22:52
  • in your first link I found your code with text `MacOS and Linux packages do not support video related functionality (not compiled with FFmpeg)"` and `... opencv needs the presence of the binary packages of FFmpeg at runtime` – furas Jul 24 '21 at 23:02
  • Double Check your path, cv2 returns a statement that looks like ```OpenCV: Couldn't read video stream from file "video.mov" [ERROR:0] global ../modules/videoio/src/cap.cpp (142) open VIDEOIO(CV_IMAGES): raised OpenCV exception: OpenCV(4.5.1) ../modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): video.mov in function 'icvExtractPattern'``` but allows you to continue your code – Ulto 4 Jul 24 '21 at 23:42
  • 1
    Sorry, I'm a little confused here. Isn't "vid = cv2.VideoCapture( 'test.mov')" supposed to open/read the video? it doesn't trigger any error message on my end. – Angelo Jul 25 '21 at 20:56

1 Answers1

-2

Replace .mov by .MOV and it should work. vid = cv2.VideoCapture( 'test.MOV')

fisakhan
  • 704
  • 1
  • 9
  • 27