recordingprocessing/libhandbrake.py

37 lines
882 B
Python
Raw Normal View History

2013-07-05 14:15:03 +10:00
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 5 14:11:00 2013
@author: shanef
2013-07-05 14:39:25 +10:00
Library to interface with handbrake to encode video files
2013-07-05 14:15:03 +10:00
"""
2013-07-05 14:39:25 +10:00
import subprocess
2013-07-11 00:30:00 +10:00
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