Skip to content

Commit fad4367

Browse files
authored
Update pyfunc.py
1 parent 30d1951 commit fad4367

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

ethon/pyfunc.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
#vasusen-code/thechariotoflight/dronebots
1313
#__TG:ChauhanMahesh__
14-
15-
import subprocess
14+
1615
import cv2
1716

1817
#fastest way to get total number of frames in a video
@@ -39,6 +38,37 @@ def videometadata(file):
3938
data = {'width' : width, 'height' : height, 'duration' : duration }
4039
return data
4140

41+
# function to find the resolution of the input video file
42+
43+
import subprocess
44+
import shlex
45+
import json
46+
47+
def findVideoResolution(pathToInputVideo):
48+
cmd = "ffprobe -v quiet -print_format json -show_streams"
49+
args = shlex.split(cmd)
50+
args.append(pathToInputVideo)
51+
# run the ffprobe process, decode stdout into utf-8 & convert to JSON
52+
ffprobeOutput = subprocess.check_output(args).decode('utf-8')
53+
ffprobeOutput = json.loads(ffprobeOutput)
54+
55+
# find height and width
56+
height = ffprobeOutput['streams'][0]['height']
57+
width = ffprobeOutput['streams'][0]['width']
58+
59+
# find duration
60+
out = subprocess.check_output(["ffprobe", "-v", "quiet", "-show_format", "-print_format", "json", pathToInputVideo])
61+
ffprobe_data = json.loads(out)
62+
duration_seconds = float(ffprobe_data["format"]["duration"])
63+
64+
return int(height), int(width), int(duration_seconds)
65+
66+
def duration(pathToInputVideo):
67+
out = subprocess.check_output(["ffprobe", "-v", "quiet", "-show_format", "-print_format", "json", pathToInputVideo])
68+
ffprobe_data = json.loads(out)
69+
duration_seconds = float(ffprobe_data["format"]["duration"])
70+
return int(duration_seconds)
71+
4272
def video_metadata(file):
4373
height = 720
4474
width = 1280

0 commit comments

Comments
 (0)