recordingprocessing/libhandbrake.py

41 lines
1.4 KiB
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 logging
import subprocess
2013-07-08 17:21:42 +10:00
#==============================================================================
# HANDBRAKECOMMAND = ['HandBrakeCLI', '--verbose', '-i',
# "SUBSTITUTE WITH INPUT FILE", '-o',
# "SUBSTITUDE WITH OUTPUT FILE", '-f', 'mkv', '-e', 'x264',
# '-x264-preset', 'slower', '-x264-tune', 'animation', '-q',
# '20', '--loose-anamorphic', '--decomb', '--detelecine',
# '--denoise="2:1:2:3"', '--deblock']
#==============================================================================
2013-07-05 14:39:25 +10:00
class Encoder:
2013-07-08 17:21:42 +10:00
def __init__(self, handbrakeCommand):
self.handbrakeCommand = handbrakeCommand
def Encode(self, input, output, waitForCompletion=True, logger=None):
self.handbrakeCommand[3] = input
self.handbrakeCommand[5] = output
2013-07-05 14:39:25 +10:00
2013-07-08 17:21:42 +10:00
logger.debug("Handbrake command is: {0}".format(self.handbrakeCommand))
process = subprocess.Popen(self.handbrakeCommand)
2013-07-05 14:39:25 +10:00
if waitForCompletion:
process.wait()
if logger is not None:
logger.info("Handbrake completed with return code {0}".format(process.returncode))
return process.returncode
2013-07-05 21:30:01 +10:00
return None