This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreturn_video_height.py
83 lines (76 loc) · 3.01 KB
/
return_video_height.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- coding: utf-8 -*-
##############################################################################################
# This file is deprecated because Python 2.x is deprecated #
# A Python 3.x version of this file can be found at: #
# #
# https://github.com/Guymer/PyGuymer3/blob/master/return_video_height.py #
##############################################################################################
def return_video_height(fname, playlist = None):
# Check input ...
if fname.startswith(u"bluray:") and playlist is None:
raise Exception("a Blu-ray was specified but no playlist was supplied")
# Import modules ...
import json
import subprocess
# Find stream info ...
if fname.startswith(u"bluray:"):
proc = subprocess.Popen(
[
u"ffprobe",
u"-loglevel", u"quiet",
u"-probesize", u"3G",
u"-analyzeduration", u"1800M",
u"-print_format", u"json",
u"-show_streams",
u"-playlist", u"{0:d}".format(playlist),
fname
],
stderr = subprocess.PIPE,
stdout = subprocess.PIPE
)
stdout, stderr = proc.communicate()
if proc.returncode != 0:
raise Exception(u"\"ffprobe\" command failed")
else:
proc = subprocess.Popen(
[
u"ffprobe",
u"-loglevel", u"quiet",
u"-probesize", u"3G",
u"-analyzeduration", u"1800M",
u"-print_format", u"json",
u"-show_streams",
fname
],
stderr = subprocess.PIPE,
stdout = subprocess.PIPE
)
stdout, stderr = proc.communicate()
if proc.returncode != 0:
# HACK: Fallback and attempt to load it as a raw M-JPEG stream.
proc = subprocess.Popen(
[
u"ffprobe",
u"-loglevel", u"quiet",
u"-probesize", u"3G",
u"-analyzeduration", u"1800M",
u"-print_format", u"json",
u"-show_streams",
u"-f", u"mjpeg",
fname
],
stderr = subprocess.PIPE,
stdout = subprocess.PIPE
)
stdout, stderr = proc.communicate()
if proc.returncode != 0:
raise Exception(u"\"ffprobe\" command failed")
# Loop over streams ...
for stream in json.loads(stdout)[u"streams"]:
# Skip stream if it is not video ...
if stream[u"codec_type"].strip().lower() != u"video":
continue
# Return height ...
return int(stream[u"height"]) # [px]
# Return error ...
return -1