1

I want to ensure that an online video at example.com/video.mp4 wasn't filed on a smartphone and will have video dimensions similar to 1920 x 1080.

Its easy to get dimensions with the video downloaded,

import cv2
vcap = cv2.VideoCapture('video.mp4') # 0=camera
width = vcap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
height = vcap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)

But I don't want to download the mp4 file PLUS I want to quickly find the file size -- which I can't do if I download the file.

jonbon
  • 1,142
  • 3
  • 12
  • 37
  • I assume you mean, download the complete file? I wonder if the easy solution is to try one of these libraries on a corrupt, partially downloaded file? – Mikhail Jan 14 '19 at 09:36
  • 1
    @Mikhail correct, I want to download "as little as possible" or preferably access some meta-data that reveals the dimensions. – jonbon Jan 14 '19 at 09:47
  • Take a look at this - https://stackoverflow.com/questions/4969497/video-meta-data-using-python and also this - https://stackoverflow.com/questions/51342429/how-to-extract-metadata-of-video-files-using-python-3-7 – Employee Jan 14 '19 at 10:25

1 Answers1

1

I've managed to get dimensions by downloading 100KB piece of video file:

import cv2
import requests

def get_dimensions(url):
    r = requests.get(url, stream=True)
    with open('output', 'wb') as f:
        for chunk in r.iter_content(chunk_size=100000):
            if chunk:
                f.write(chunk)
                break

    vcap = cv2.VideoCapture('output')
    return int(vcap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(vcap.get(cv2.CAP_PROP_FRAME_HEIGHT))

I've tested it on several files from internet and here what I've got:

>> get_dimensions('http://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_1920_18MG.mp4')
(1920, 1080)
>> get_dimensions('http://file-examples.com/wp-content/uploads/2018/04/file_example_AVI_640_800kB.avi')
(640, 360)
>> get_dimensions('https://www.sample-videos.com/video123/mkv/720/big_buck_bunny_720p_1mb.mkv')
(1280, 720)
Alderven
  • 7,569
  • 5
  • 26
  • 38