From: paul Date: Sat, 9 Apr 2011 14:51:25 +0000 (+0000) Subject: plugin for x264 video encoder X-Git-Url: http://git.plutz.net/?a=commitdiff_plain;ds=sidebyside;h=fea0db4e9008950d7927ea3bfaecf23fbe37c79e;hp=db6a479eb83489f98839ae01cc63f5d633e8784a;p=viper plugin for x264 video encoder svn path=/trunk/; revision=2 --- diff --git a/plugins/v_x264.py b/plugins/v_x264.py new file mode 100644 index 0000000..38678fe --- /dev/null +++ b/plugins/v_x264.py @@ -0,0 +1,121 @@ +#encoding: utf-8 +#Copyright 2009 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class V_x264(V_Plugin): + def build_dialog(self): + self.subgets['l_profile'] = Label(self, text = 'Profile:') + self.subgets['l_profile'].grid(row = 0, column = 0) + self.subgets['o_profile'] = Pmw.OptionMenu(self, initialitem = 2, + items = ['baseline', 'main', 'high']) + self.subgets['o_profile'].grid(row = 1, column = 0) + + self.subgets['l_preset'] = Label(self, text = 'Preset:') + self.subgets['l_preset'].grid(row = 0, column = 1) + self.subgets['o_preset'] = Pmw.OptionMenu(self, initialitem = 5, + items = ['ultrafast', 'superfast', 'veryfast', 'faster', + 'fast', 'medium', 'slow', 'slower', 'veryslow', + 'placebo']) + self.subgets['o_preset'].grid(row = 1, column = 1) + + self.subgets['l_keyint'] = Label(self, text = 'Keyframe\nInterval:') + self.subgets['l_keyint'].grid(row = 0, column = 2) + self.subgets['s_keyint'] = Spinbox(self, from_ = 1, to = 2000, increment = 25, width = 5) + self.subgets['s_keyint'].delete(0, END) + self.subgets['s_keyint'].insert(END, 250) + self.subgets['s_keyint'].grid(row = 1, column = 2) + + self.subgets['psy'] = False + self.subgets['c_psy'] = Checkbutton(self, text = 'Psychovisual\nOptimization:', command = self.c_psy) + self.subgets['c_psy'].deselect() + self.subgets['c_psy'].grid(row = 0, column = 3) + self.subgets['o_psy'] = Pmw.OptionMenu(self, initialitem = 0, items = [' ']) + self.subgets['o_psy'].grid(row = 1, column = 3) + + self.subgets['bitrate'] = False + self.subgets['c_bitrate'] = Checkbutton(self, text = 'Force avg.\nBitrate:', command = self.c_bitrate) + self.subgets['c_bitrate'].deselect() + self.subgets['c_bitrate'].grid(row = 0, column = 4) + self.subgets['s_bitrate'] = Spinbox(self, from_ = 0, to = 20000, increment = 100, width = 6) + self.subgets['s_bitrate'].delete(0, END) + self.subgets['s_bitrate'].insert(END, 4000) + self.subgets['s_bitrate'].config(state = 'disabled') + self.subgets['s_bitrate'].grid(row = 1, column = 4) + + self.subgets['fastdecode'] = False + self.subgets['c_fastdecode'] = Checkbutton(self, text = 'Fastdecode', command = self.c_fastdecode) + self.subgets['c_fastdecode'].deselect() + self.subgets['c_fastdecode'].grid(row = 2, column = 1, columnspan = 2) + + self.subgets['zerolatency'] = False + self.subgets['c_zerolatency'] = Checkbutton(self, text = 'Zerolatency', command = self.c_zerolatency) + self.subgets['c_zerolatency'].deselect() + self.subgets['c_zerolatency'].grid(row = 2, column = 3, columnspan = 2) + + def c_psy(self): + if self.subgets['psy']: + self.subgets['o_psy'].setitems([' ']) + else: + self.subgets['o_psy'].setitems(['film', 'animation', 'grain', 'stillimage', 'psnr', 'ssim']) + self.subgets['psy'] = not self.subgets['psy'] + + def c_bitrate(self): + if self.subgets['bitrate']: + self.subgets['s_bitrate'].config(state = 'disabled') + else: + self.subgets['s_bitrate'].config(state = 'normal') + self.subgets['bitrate'] = not self.subgets['bitrate'] + + def c_fastdecode(self): + self.subgets['fastdecode'] = not self.subgets['fastdecode'] + + def c_zerolatency(self): + self.subgets['zerolatency'] = not self.subgets['zerolatency'] + + def name(self): + return 'h264 (via x264)' + + def subcommand(self): + opts = ('profile=' + self.subgets['o_profile'].getvalue() + + ':preset=' + self.subgets['o_preset'].getvalue() + + ':keyint=' + self.subgets['s_keyint'].get()) + if self.subgets['psy']: + opts += ':tune=' + self.subgets['o_psy'].getvalue() + if self.subgets['fastdecode']: + opts += ',fastdecode' + if self.subgets['zerolatency']: + opts += ',zerolatency' + elif self.subgets['fastdecode'] and self.subgets['zerolatency']: + opts += ':tune=fastdecode,zerolatency' + elif self.subgets['fastdecode']: + opts += ':tune=fastdecode' + elif self.subgets['zerolatency']: + opts += ':tune=zerolatency' + + return ['-ovc', 'x264', '-x264encopts', opts] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-ovc', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('x264') == 0: + result = True + return result