Update for API change: scene.cursor_location -> scene.cursor.location
[blender-addons.git] / sequencer_kinoraw_tools / datamosh.py
blobf64adbed2acf42bb4f05d0f5355f6ebf8633e11e
1 # gpl: authors Carlos Padial, Turi Scandurra
3 import bpy
4 import os
5 from bpy.props import IntProperty
6 from bpy.types import (
7 Operator,
8 Panel,
10 from . import functions
13 proxy_qualities = [
14 ("1", "25%", ""), ("2", "50%", ""),
15 ("3", "75%", ""), ("4", "100%", ""),
16 ("5", "none", "")
20 # functions
21 def createdatamosh(context, strip):
22 preferences = context.preferences
23 prefs = preferences.addons[__package__].preferences
25 fileinput = bpy.path.abspath(strip.filepath)
26 fileoutput = fileinput.rpartition(".")[0] + "_datamosh.avi"
28 if prefs.all_keyframes:
29 command = "datamosh '{}' -a -o '{}'".format(fileinput, fileoutput)
30 else:
31 command = "datamosh '{}' -o '{}'".format(fileinput, fileoutput)
32 print(command)
33 os.system(command)
34 return fileoutput
37 def createavi(context, strip):
38 fileinput = bpy.path.abspath(strip.filepath)
39 fileoutput = fileinput.rpartition(".")[0] + "_.avi"
41 command = "ffmpeg -i '{}' -vcodec copy '{}'".format(fileinput, fileoutput)
43 print(command)
44 os.system(command)
46 return fileoutput
49 def createavimjpeg(context, strip):
50 fileinput = bpy.path.abspath(strip.filepath)
51 fileoutput = fileinput.rpartition(".")[0] + "_mjpeg.avi"
53 command = "ffmpeg -i '{}' -vcodec mjpeg -q:v 1 '{}'".format(fileinput, fileoutput)
55 print(command)
56 os.system(command)
58 return fileoutput
61 # classes
62 class CreateAvi(Operator):
63 bl_idname = "sequencer.createavi"
64 bl_label = "Create avi file"
65 bl_description = "Create an avi output file"
66 bl_options = {'REGISTER', 'UNDO'}
68 size: IntProperty(
69 name="proxysize",
70 default=1
73 @classmethod
74 def poll(self, context):
75 strip = functions.act_strip(context)
76 scn = context.scene
77 if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
78 return strip.type in ('MOVIE')
79 else:
80 return False
82 def execute(self, context):
83 strips = functions.get_selected_strips(context)
85 for strip in strips:
86 # deselect all other strips
87 for i in strips:
88 i.select = False
89 # select current strip
90 strip.select = True
91 if strip.type == "MOVIE":
92 if self.size == 1:
93 fileoutput = createavi(context, strip)
94 elif self.size == 2:
95 fileoutput = createavimjpeg(context, strip)
96 strip.filepath = fileoutput
98 # select all strips again
99 for strip in strips:
100 try:
101 strip.select = True
102 except ReferenceError:
103 pass
105 bpy.ops.sequencer.reload()
107 return {'FINISHED'}
110 class CreateDatamosh(Operator):
111 bl_idname = "sequencer.createdatamosh"
112 bl_label = "Create Datamosh"
113 bl_description = "Create Datamosh"
115 @classmethod
116 def poll(self, context):
117 strip = functions.act_strip(context)
118 scn = context.scene
119 if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
120 return strip.type in ('MOVIE')
121 else:
122 return False
124 def execute(self, context):
125 preferences = context.preferences
126 prefs = preferences.addons[__package__].preferences
127 strips = functions.get_selected_strips(context)
129 for strip in strips:
130 # deselect all other strips
131 for i in strips:
132 i.select = False
133 # select current strip
134 strip.select = True
135 if strip.type == "MOVIE":
136 fileoutput = createdatamosh(context, strip)
137 if prefs.load_glitch:
138 strip.filepath = fileoutput
140 # select all strips again
141 for strip in strips:
142 try:
143 strip.select = True
144 except ReferenceError:
145 pass
147 bpy.ops.sequencer.reload()
149 return {'FINISHED'}
152 class CreateGlitchToolPanel(Panel):
153 bl_label = "Glitch Tools"
154 bl_idname = "OBJECT_PT_GlitchTool"
155 bl_space_type = 'SEQUENCE_EDITOR'
156 bl_region_type = 'UI'
158 @classmethod
159 def poll(self, context):
160 if context.space_data.view_type in {'SEQUENCER',
161 'SEQUENCER_PREVIEW'}:
162 strip = functions.act_strip(context)
163 scn = context.scene
164 preferences = context.preferences
165 prefs = preferences.addons[__package__].preferences
166 if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
167 if prefs.use_glitch_panel:
168 return strip.type in ('MOVIE')
169 else:
170 return False
172 def draw_header(self, context):
173 layout = self.layout
174 layout.label(text="", icon="GAME")
176 def draw(self, context):
178 preferences = context.preferences
179 prefs = preferences.addons[__package__].preferences
181 layout = self.layout
183 layout.operator("sequencer.createavi", text="Create avi (same codec)")
184 layout.operator("sequencer.createavi", text="Create avi (mjpeg)").size = 2
186 layout.prop(prefs, "all_keyframes")
187 layout.prop(prefs, "load_glitch")
189 layout.operator("sequencer.createdatamosh")