Skip to content

Commit

Permalink
Updates for AvsPmod 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vdcrim committed Nov 24, 2012
1 parent 692fa61 commit 3de480b
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 158 deletions.
6 changes: 3 additions & 3 deletions Auto-crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ def autocrop_frame(frame, tol=70):
"""Return crop values for a specific frame"""
avs_clip = avsp.GetWindow().currentScript.AVI
width, height = avs_clip.vi.width, avs_clip.vi.height
if avs_clip.clipRaw is not None: # Get pixel color from the original clip
version = avsp.GetWindow().version
if version > '2.3.1' or avs_clip.clipRaw is not None: # Get pixel color from the original clip
avs_clip._GetFrame(frame)
get_pixel_color = avs_clip.GetPixelRGB if avs_clip.IsRGB else avs_clip.GetPixelYUV
else: # Get pixel color from the video preview (slower)
bmp = wx.EmptyBitmap(width, height)
mdc = wx.MemoryDC()
mdc.SelectObject(bmp)
dc = mdc if avsp.GetWindow().version > '2.3.1' else mdc.GetHDC()
avs_clip.DrawFrame(frame, dc)
avs_clip.DrawFrame(frame, mdc.GetHDC())
img = bmp.ConvertToImage()
get_pixel_color = lambda x, y : (img.GetRed(x, y), img.GetGreen(x, y), img.GetBlue(x, y))
w, h = width - 1, height - 1
Expand Down
94 changes: 58 additions & 36 deletions Create GIF with ImageMagick.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,45 +63,67 @@


# run in thread
from os import getcwdu, walk, name
from os.path import isfile, splitext, basename, join
from sys import getfilesystemencoding
import os
import os.path
import sys
import subprocess
import shlex
import wx

# Check convert.exe path
if name == 'nt':
convert_path = avsp.Options.get('convert_path')
if not convert_path or not isfile(convert_path):
avsp.Options['convert_path'] = None
for parent, dirs, files in walk('tools'):
for file in files:
if file == 'convert.exe':
convert_path = join(getcwdu(), parent, file)
break
def check_executable_path(executable, check_PATH_Windows=True, check_PATH_nix=False,
error_message=None):
"""Check if executable is in the 'tools' directory or its subdirectories or PATH"""

def prompt_path(executable, message_prefix):
"""Prompt for a path if not found"""
if avsp.MsgBox(_("{0}\n\nPress 'Accept' to specify a path. Alternatively copy\n"
"the executable to the 'tools' subdirectory.".format(message_prefix)),
_('Error'), True):
filter = _('Executable files') + ' (*.exe)|*.exe|' if os.name == 'nt' else ''
filter = filter + _('All files') + ' (*.*)|*.*'
executable_path = avsp.GetFilename(_('Select the {0} executable').format(executable),
filter)
if executable_path:
avsp.Options['{0}_path'.format(executable)] = executable_path
return True

tools_dir = avsp.GetWindow().toolsfolder
executable_lower = executable.lower()
for parent, dirs, files in os.walk(tools_dir):
for file in files:
if file.lower() in (executable_lower, executable_lower + '.exe'):
avsp.Options['{0}_path'.format(executable)] = os.path.join(parent, file)
return True
if os.name == 'nt':
if check_PATH_Windows:
try:
path = subprocess.check_output('for %i in ({0}) do @echo. %~$PATH:i'.
format(executable + '.exe'), shell=True).strip().splitlines()[0]
if not os.path.isfile(path) and not os.path.isfile(path + '.exe'):
raise
except: pass
else:
continue
break
else:
if avsp.MsgBox(_("'convert.exe' from ImageMagick not found\n\n"
"Press 'Accept' to specify a path. Alternatively copy\n"
"the executable to the 'tools' subdirectory."),
_('Error'), True):
convert_path = avsp.GetFilename(_('Select the convert.exe executable'),
_('Executable files') + ' (*.exe)|*.exe|' +
_('All files') + ' (*.*)|*.*')
if not convert_path:
return
else: return
avsp.Options['convert_path'] = convert_path
else:
try:
convert_path = subprocess.check_output(['which', 'convert']).splitlines()[0].strip()
except:
avsp.MsgBox(_("'convert' executable from ImageMagick not found"),
_('Error'))
avsp.Options['{0}_path'.format(executable)] = path
return True
else:
if check_PATH_nix:
try:
path = subprocess.check_output(['which', 'convert']).strip().splitlines()[0]
except: pass
else:
avsp.Options['{0}_path'.format(executable)] = path
return True
if error_message is None:
error_message = _("{0} not found").format(executable)
return prompt_path(executable, error_message)

# Check convert path
convert_path = avsp.Options.get('convert_path', '')
if not os.path.isfile(convert_path):
if not check_executable_path('convert', False, True,
_("'convert' from ImageMagick not found")):
return
convert_path = avsp.Options['convert_path']

# Prompt for options
speed_factor = avsp.Options.get('speed_factor', 2)
Expand All @@ -119,7 +141,7 @@
dither_dict = dict(zip(dither_list, dither_cmd))
output_path = avsp.GetScriptFilename()
if output_path:
output_path = splitext(output_path)[0] + '.gif'
output_path = os.path.splitext(output_path)[0] + '.gif'
gif_filter = (_('GIF files') + ' (*.gif)|*.gif|' + _('All files') + '|*.*')
while True:
options = avsp.GetTextEntry(
Expand Down Expand Up @@ -198,12 +220,12 @@
# http://www.py2exe.org/index.cgi/Py2ExeSubprocessInteractions
# http://bugs.python.org/issue3905
# http://bugs.python.org/issue1124861
code = getfilesystemencoding()
code = sys.getfilesystemencoding()
cmd = ur'"{0}" miff:- -dispose None -loop {1} -set delay {2} {3} {4} {5} "{6}"'.format(
convert_path, loops, delay, add_params, dither_dict[dither], optimize,
output_path).encode(code)
cmd = shlex.split(cmd)
if name == 'nt':
if os.name == 'nt':
info = subprocess.STARTUPINFO()
try:
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
Expand Down
92 changes: 57 additions & 35 deletions Create mask with ImageMagick.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,44 +72,66 @@


# run in thread
from sys import getfilesystemencoding
from os import getcwdu, walk, name
from os.path import isfile, basename, join
import sys
import os
import os.path
import subprocess
import re

# Check convert.exe path
if name == 'nt':
convert_path = avsp.Options.get('convert_path')
if not convert_path or not isfile(convert_path):
avsp.Options['convert_path'] = None
for parent, dirs, files in walk('tools'):
for file in files:
if file == 'convert.exe':
convert_path = join(getcwdu(), parent, file)
break
def check_executable_path(executable, check_PATH_Windows=True, check_PATH_nix=False,
error_message=None):
"""Check if executable is in the 'tools' directory or its subdirectories or PATH"""

def prompt_path(executable, message_prefix):
"""Prompt for a path if not found"""
if avsp.MsgBox(_("{0}\n\nPress 'Accept' to specify a path. Alternatively copy\n"
"the executable to the 'tools' subdirectory.".format(message_prefix)),
_('Error'), True):
filter = _('Executable files') + ' (*.exe)|*.exe|' if os.name == 'nt' else ''
filter = filter + _('All files') + ' (*.*)|*.*'
executable_path = avsp.GetFilename(_('Select the {0} executable').format(executable),
filter)
if executable_path:
avsp.Options['{0}_path'.format(executable)] = executable_path
return True

tools_dir = avsp.GetWindow().toolsfolder
executable_lower = executable.lower()
for parent, dirs, files in os.walk(tools_dir):
for file in files:
if file.lower() in (executable_lower, executable_lower + '.exe'):
avsp.Options['{0}_path'.format(executable)] = os.path.join(parent, file)
return True
if os.name == 'nt':
if check_PATH_Windows:
try:
path = subprocess.check_output('for %i in ({0}) do @echo. %~$PATH:i'.
format(executable + '.exe'), shell=True).strip().splitlines()[0]
if not os.path.isfile(path) and not os.path.isfile(path + '.exe'):
raise
except: pass
else:
continue
break
else:
if avsp.MsgBox(_("'convert.exe' from ImageMagick not found\n\n"
"Press 'Accept' to specify a path. Alternatively copy\n"
"the executable to the 'tools' subdirectory."),
_('Error'), True):
convert_path = avsp.GetFilename(_('Select the convert.exe executable'),
_('Executable files') + ' (*.exe)|*.exe|' +
_('All files') + ' (*.*)|*.*')
if not convert_path:
return
else: return
avsp.Options['convert_path'] = convert_path
else:
try:
convert_path = subprocess.check_output(['which', 'convert']).splitlines()[0].strip()
except:
avsp.MsgBox(_("'convert' executable from ImageMagick not found"),
_('Error'))
avsp.Options['{0}_path'.format(executable)] = path
return True
else:
if check_PATH_nix:
try:
path = subprocess.check_output(['which', 'convert']).strip().splitlines()[0]
except: pass
else:
avsp.Options['{0}_path'.format(executable)] = path
return True
if error_message is None:
error_message = _("{0} not found").format(executable)
return prompt_path(executable, error_message)

# Check convert path
convert_path = avsp.Options.get('convert_path', '')
if not os.path.isfile(convert_path):
if not check_executable_path('convert', False, True,
_("'convert' from ImageMagick not found")):
return
convert_path = avsp.Options['convert_path']

# Get options
mask_path = avsp.GetScriptFilename()
Expand Down Expand Up @@ -188,9 +210,9 @@
'polygon {0}'.format(' '.join(['{0},{1}'.format(x, y) for x, y in points]))]
if blur: cmd.extend(blur)
cmd.append(mask_path)
code = getfilesystemencoding()
code = sys.getfilesystemencoding()
cmd = [arg.encode(code) for arg in cmd]
if name == 'nt':
if os.name == 'nt':
info = subprocess.STARTUPINFO()
try:
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
Expand Down
Loading

0 comments on commit 3de480b

Please sign in to comment.