forked from kieranjol/IFIscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ififuncs.py
91 lines (79 loc) · 3.32 KB
/
ififuncs.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
84
85
86
87
88
89
90
91
import subprocess
import sys
import base64
import time
import smtplib
import mimetypes
from email.mime.multipart import MIMEMultipart
from email import encoders
from email.message import Message
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
def make_mediainfo(xmlfilename, xmlvariable, inputfilename):
with open(xmlfilename, "w+") as fo:
xmlvariable = subprocess.check_output(['mediainfo',
'-f',
'--language=raw', # Use verbose output.
'--output=XML',
inputfilename]) #input filename
fo.write(xmlvariable)
def make_qctools(input):
qctools_args = ['ffprobe', '-f', 'lavfi', '-i',]
qctools_args += ["movie=%s:s=v+a[in0][in1],[in0]signalstats=stat=tout+vrep+brng,cropdetect=reset=1:round=1,split[a][b];[a]field=top[a1];[b]field=bottom[b1],[a1][b1]psnr[out0];[in1]ebur128=metadata=1,astats=metadata=1:reset=1:length=0.4[out1]" % input]
qctools_args += ['-show_frames', '-show_versions', '-of', 'xml=x=1:q=1', '-noprivate']
print qctools_args
qctoolsreport = subprocess.check_output(qctools_args)
return qctoolsreport
def write_qctools_gz(qctoolsxml, sourcefile):
with open(qctoolsxml, "w+") as fo:
fo.write(make_qctools(sourcefile))
subprocess.call(['gzip', qctoolsxml])
def get_audio_stream_count():
audio_stream_count = subprocess.check_output(['ffprobe', '-v', 'error', '-select_streams', 'a', '-show_entries', 'stream=index', '-of', 'flat', sys.argv[1]]).splitlines()
return len(audio_stream_count)
def get_mediainfo(var_type, type, filename):
var_type = subprocess.check_output(['MediaInfo', '--Language=raw', '--Full', type , filename ]).replace('\n', '')
return var_type
# example - duration = get_mediainfo('duration', '--inform=General;%Duration_String4%', sys.argv[1] )
def send_gmail(email_to, attachment, subject, email_body):
emailfrom = ""
emailto = email_to
#emailto = ", ".join(emailto)
fileToSend = attachment
username = ""
password = ""
msg = MIMEMultipart()
msg["From"] = emailfrom
msg["To"] = ", ".join(emailto)
msg["Subject"] = subject
msg.preamble = "testtesttest"
body = MIMEText(email_body)
msg.attach(body)
ctype, encoding = mimetypes.guess_type(fileToSend)
if ctype is None or encoding is not None:
ctype = "application/octet-stream"
maintype, subtype = ctype.split("/", 1)
if maintype == "text":
fp = open(fileToSend)
# Note: we should handle calculating the charset
attachment = MIMEText(fp.read(), _subtype=subtype)
fp.close()
elif maintype == "image":
fp = open(fileToSend, "rb")
attachment = MIMEImage(fp.read(), _subtype=subtype)
fp.close()
elif maintype == "audio":
fp = open(fileToSend, "rb")
attachment = MIMEAudio(fp.read(), _subtype=subtype)
fp.close()
else:
fp = open(fileToSend, "rb")
attachment = MIMEBase(maintype, subtype)
attachment.set_payload(fp.read())
def frames_to_seconds(audio_entry_point):
audio_frame_count = float(audio_entry_point)
audio_frame_count = float(audio_frame_count) / 24.000 # Change to EditRate variable.
audio_frame_count = round(audio_frame_count, 3)
return audio_frame_count