Page MenuHome

sequencer_extra_actions_proxy.py

sequencer_extra_actions_proxy.py

# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program 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 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
'name': 'Extra Sequencer Actions Proxy',
'author': 'Carlos Padial',
'version': (0, 1),
'blender': (2, 6, 3, 0),
'api': 46461,
'category': 'Sequencer',
'location': 'Sequencer',
'description': 'import clip from file browser and set proxy custom file',
'warning': 'You need Extra Sequencer Actions Addon installed',
'wiki_url': 'http://wiki.blender.org/index.php?title=Extensions:2.6/Py/Scripts/Sequencer/Extra_Sequencer_Actions_Proxy'
'Extensions:2.6/Py/Scripts/Sequencer/',
'tracker_url': 'http://projects.blender.org/tracker/index.php?func=detail'\
'&aid=31683&group_id=153&atid=467',
'support': 'COMMUNITY'}
'''
Installation:
- Install the script by copying its .py file to your Blender addons
folder. Enable the script in User Preferences > Addons > Sequencer.
Usage:
- Place + proxy
Place active file from File Browser to Sequencer Editor on current
frame. Then set proxy custom file
- Insert + proxy
Same as above, but also shift forward forward all strips after current
frame.
Note: This addon is based in Turi script Extra-sequencer-actions
- In order to get insert option working, need to install this addon:
http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Sequencer/Extra_Sequencer_Actions
- Thanks turi!
'''
import bpy
import os.path
from bpy.types import Menu
from bpy.types import Header
from bpy.props import IntProperty
from bpy.props import FloatProperty
from bpy.props import EnumProperty
from bpy.props import BoolProperty
from bpy.props import StringProperty
# ##### UTILS #####
def act_strip(context):
try:
return context.scene.sequence_editor.active_strip
except AttributeError:
return None
def detect_strip_type(filepath):
imb_ext_image = [
# IMG
".png", ".tga", ".bmp", ".jpg", ".jpeg", ".sgi", ".rgb", ".rgba",
".tif", ".tiff", ".tx", ".jp2", ".hdr", ".dds", ".dpx", ".cin",
".exr",
# IMG QT
".gif", ".psd", ".pct", ".pict", ".pntg", ".qtif",
]
imb_ext_movie = [
".avi", ".flc", ".mov", ".movie", ".mp4", ".m4v", ".m2v",
".m2t", ".m2ts", ".mts", ".mv", ".avs", ".wmv", ".ogv",
".dv", ".mpeg", ".mpg", ".mpg2", ".vob", ".mkv", ".flv",
".divx", ".xvid", ".mxf",
]
imb_ext_audio = [
".wav", ".ogg", ".oga", ".mp3", ".mp2", ".ac3", ".aac",
".flac", ".wma", ".eac3", ".aif", ".aiff", ".m4a",
]
extension = os.path.splitext(filepath)[1]
extension = extension.lower()
if extension in imb_ext_image:
type = 'IMAGE'
elif extension in imb_ext_movie:
type = 'MOVIE'
elif extension in imb_ext_audio:
type = 'SOUND'
else:
type = None
return type
# ##### INITIALIZATION #####
def initSceneProperties(scn):
try:
if bpy.context.scene.scene_initialized2 == True:
return False
except AttributeError:
pass
bpy.types.Scene.default_proxy_sufix = StringProperty(
name='default proxy sufix',
description='default proxy filename sufix',
default="-25")
scn.default_proxy_sufix = "-25"
bpy.types.Scene.default_proxy_extension = StringProperty(
name='default proxy extension',
description='default proxy file extension',
default=".mkv")
scn.default_proxy_extension = ".mkv"
bpy.types.Scene.default_proxy_path = StringProperty(
name='default proxy path',
description='default proxy file path (relative to original file)',
default="")
scn.default_proxy_path = ""
bpy.types.Scene.scene_initialized2 = BoolProperty(
name='Init2',
default=False)
scn.scene_initialized2 = True
return True
# ##### CLASSES #####
# PLACE FROM FILE BROWSER
class Sequencer_Extra_PlaceFromFileBrowserProxy(bpy.types.Operator):
bl_label = 'Place'
bl_idname = 'sequencerextra.placefromfilebrowserproxy'
bl_description = 'Place or insert active file from File Browser and add proxy file with according sufix and extension'
insert = BoolProperty(
name='Insert',
default=False
)
proxy_sufix = StringProperty(
name='proxy sufix',
description='proxy filename sufix',
default="-25")
proxy_extension = StringProperty(
name='proxy extension',
description='proxy file extension',
default=".mkv")
proxy_path = StringProperty(
name='proxy path',
description='proxy file path (relative to original file)',
default="")
bl_options = {'REGISTER', 'UNDO'}
initSceneProperties(bpy.context.scene)
def invoke(self, context, event):
scn = context.scene
self.proxy_sufix = scn.default_proxy_sufix
self.proxy_extension = scn.default_proxy_extension
self.proxy_path = scn.default_proxy_path
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
scn = context.scene
for a in context.window.screen.areas:
if a.type == 'FILE_BROWSER':
params = a.spaces[0].params
break
try:
params
except UnboundLocalError:
self.report({'ERROR_INVALID_INPUT'}, 'No visible File Browser')
return {'CANCELLED'}
if params.filename == '':
self.report({'ERROR_INVALID_INPUT'}, 'No file selected')
return {'CANCELLED'}
path = params.directory + params.filename
frame = context.scene.frame_current
strip_type = detect_strip_type(params.filename)
try:
if strip_type == 'IMAGE':
image_file = []
filename = {"name": params.filename}
image_file.append(filename)
f_in = scn.frame_current
f_out = f_in + scn.render.fps - 1
bpy.ops.sequencer.image_strip_add(files=image_file,
directory=params.directory, frame_start=f_in,
frame_end=f_out, relative_path=False)
elif strip_type == 'MOVIE':
bpy.ops.sequencer.movie_strip_add(filepath=path,
frame_start=frame, relative_path=False)
# check if proxy exists, otherwise, uncheck proxy custom file
proxy_filepath = params.directory+self.proxy_path
proxy_filename = params.filename.rpartition(".")[0]+self.proxy_sufix+self.proxy_extension
proxypath = proxy_filepath+proxy_filename
if os.path.isfile(proxypath) == True:
strip = act_strip(context)
strip.use_proxy = True
strip.use_proxy_custom_file = True
proxy_filepath = params.directory+self.proxy_path
proxy_filename = params.filename.rpartition(".")[0]+self.proxy_sufix+self.proxy_extension
strip.proxy.filepath = proxypath
else:
#strip = act_strip(context)
#strip.use_proxy = True
pass
elif strip_type == 'SOUND':
bpy.ops.sequencer.sound_strip_add(filepath=path,
frame_start=frame, relative_path=False)
else:
self.report({'ERROR_INVALID_INPUT'}, 'Invalid file format')
return {'CANCELLED'}
except:
self.report({'ERROR_INVALID_INPUT'}, 'Error loading file')
return {'CANCELLED'}
scn.default_proxy_sufix = self.proxy_sufix
scn.default_proxy_extension = self.proxy_extension
scn.default_proxy_path = self.proxy_path
if self.insert == True:
try:
bpy.ops.sequencerextra.insert()
except:
self.report({'ERROR_INVALID_INPUT'}, 'Execution Error, '\
'check your Blender version, may you need Turi scripts')
return {'CANCELLED'}
else:
strip = act_strip(context)
scn.frame_current += strip.frame_final_duration
bpy.ops.sequencer.reload()
return {'FINISHED'}
# ##### UI #####
def sequencer_header_func(self, context):
if context.space_data.view_type in ('SEQUENCER', 'SEQUENCER_PREVIEW'):
self.layout.operator('sequencerextra.placefromfilebrowserproxy',
text='Place + Proxy', icon='PLUGIN')
if context.space_data.view_type in ('SEQUENCER', 'SEQUENCER_PREVIEW'):
self.layout.operator('sequencerextra.placefromfilebrowserproxy',
text='Insert + Proxy', icon='PLUGIN').insert = True
# ##### REGISTRATION #####
def register():
bpy.utils.register_class(Sequencer_Extra_PlaceFromFileBrowserProxy)
bpy.types.SEQUENCER_HT_header.append(sequencer_header_func)
def unregister():
bpy.utils.unregister_class(Sequencer_Extra_PlaceFromFileBrowserProxy)
bpy.types.SEQUENCER_HT_header.remove(sequencer_header_func)
if __name__ == '__main__':
register()

File Metadata

Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
69/1f/ffe2f1ab118b829344177fe9449a

Event Timeline