-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscoder.py
36 lines (28 loc) · 1.07 KB
/
transcoder.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
import subprocess
def get_hwdevice(hwaccel):
if hwaccel == "none":
return ""
else:
return hwaccel
class Transcoder:
def __init__(self, ffmpeg_tools, hwaccel, output_dir):
self.ffmpeg_program = ffmpeg_tools + '/ffmpeg'
self.hwaccel = hwaccel
self.output_dir = output_dir
def transcode(self, inputFile, profile):
outputFile = self.output_dir + "/" + profile.build_output_file_name() + ".mp4"
print("Start transcode")
print('Output file: {outputFile}'.format(outputFile=outputFile))
call_params = [self.ffmpeg_program]
hwaccels = get_hwdevice(self.hwaccel)
if(hwaccels):
call_params.append("-hwaccel")
call_params.append(hwaccels)
call_params.extend(["-i", inputFile])
params = profile.build_params()
call_params.extend(params)
call_params.append(outputFile)
print("Wait...")
subprocess.call(call_params, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
print("End transcode")
return outputFile