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_MP4_video_level.py
47 lines (40 loc) · 1.6 KB
/
return_MP4_video_level.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
# -*- 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_MP4_video_level.py #
##############################################################################################
def return_MP4_video_level(fname):
# Import modules ...
import json
import subprocess
# Find stream info ...
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:
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
# Skip stream if it is not H.264 video ...
if stream[u"codec_name"].strip().upper() != u"H264":
continue
# Return level ...
return stream[u"level"]
# Return error ...
return u"ERROR"