How to calculate the size of a video in OpenCV?
In deep learning, we often need to get the information of the video, so how to calculate the size of the video? I need something in python to get the file size in bytes.
In deep learning, we often need to get the information of the video, so how to calculate the size of the video? I need something in python to get the file size in bytes.
There are couple of ways can do that,One of them is the following:
# -*- coding: utf-8 -*-
import os
import sys
class FileCheck():
def __init__(self):
self.file_dir = file_dir
def get_filesize(self):
# get the file size
file_byte = os.path.getsize(file_dir)
return self.sizeConvert(file_byte)
def sizeConvert(self, size):
# size convert
K, M, G = 1024, 1024 ** 2, 1024 ** 3
if size >= G:
return str(size / G) + 'G Bytes'
elif size >= M:
return str(size / M) + 'M Bytes'
elif size >= K:
return str(size / K) + 'K Bytes'
else:
return str(size) + 'Bytes'
if __name__ == '__main__':
file_dir = 'video/False_video.mp4'
res = FileCheck()
res1 = res.get_filesize()
print(res1)