-
Notifications
You must be signed in to change notification settings - Fork 0
/
libhandbrake.py
36 lines (25 loc) · 882 Bytes
/
libhandbrake.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
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 5 14:11:00 2013
@author: shanef
Library to interface with handbrake to encode video files
"""
import subprocess
def encode(handbrakecommand, inputfile, outputfile, waitforcompletion=True,
logger=None):
"""
Encode inputfile and save the result to outputfile. handbrakecommand is
a list of strings containing the arguments to handbrakecli.
"""
handbrakecommand[3] = inputfile
handbrakecommand[5] = outputfile
if logger:
logger.debug("Handbrake command is: {0}".format(handbrakecommand))
process = subprocess.Popen(handbrakecommand)
if waitforcompletion:
process.wait()
if logger is not None:
logger.info("Handbrake completed with return code {0}".format(
process.returncode))
return process.returncode
return None