-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathworker.py
40 lines (34 loc) · 1.01 KB
/
worker.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
from task import Task
import subprocess
import os
import shutil
import sys
def ffmpeg(arg):
torun = Task(createfrom=arg)
# Get the output file extension:
destExtension = torun.outfile.split(".")[-1]
print torun.outfile.split(".")
tmpfile = "tmp." + destExtension
codeccheck = subprocess.Popen(["ffmpeg", "-codecs"], stdout=subprocess.PIPE)
allcodecs = codeccheck.communicate()[0]
if allcodecs.find("libfdk_aac") == -1:
print "Install libfdk_aac for better audio quality!"
if torun.forcefdk == True:
print "Server has disabled workers without libfdk_aac!"
sys.exit()
else:
if "libfdk_aac" in torun.arguments:
libfdk_pos = torun.arguments.index("libfdk_aac")
torun.arguments[libfdk_pos] = "aac"
torun.arguments.append("-strict")
torun.arguments.append("-2")
out=subprocess.call(["ffmpeg","-i", torun.infile]+torun.arguments+[tmpfile])
if not out == 0:
print "FFMPEG FAILED"
else:
shutil.move(tmpfile,torun.outfile)
os.remove(torun.infile)
try:
os.remove(tmpfile)
except:
pass