Welcome to mirror list, hosted at ThFree Co, Russian Federation.

datamosh.py « sequencer_kinoraw_tools - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 81f679bda4de608bd9bda05979a0826c7570f644 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# gpl: authors Carlos Padial, Turi Scandurra

import bpy
import os
from bpy.props import IntProperty
from bpy.types import (
        Operator,
        Panel,
        )
from . import functions


proxy_qualities = [
        ("1", "25%", ""), ("2", "50%", ""),
        ("3", "75%", ""), ("4", "100%", ""),
        ("5", "none", "")
        ]


# functions
def createdatamosh(context, strip):
    preferences = context.preferences
    prefs = preferences.addons[__package__].preferences

    fileinput = bpy.path.abspath(strip.filepath)
    fileoutput = fileinput.rpartition(".")[0] + "_datamosh.avi"

    if prefs.all_keyframes:
        command = "datamosh '{}' -a -o '{}'".format(fileinput, fileoutput)
    else:
        command = "datamosh '{}' -o '{}'".format(fileinput, fileoutput)
    print(command)
    os.system(command)
    return fileoutput


def createavi(context, strip):
    fileinput = bpy.path.abspath(strip.filepath)
    fileoutput = fileinput.rpartition(".")[0] + "_.avi"

    command = "ffmpeg -i '{}' -vcodec copy '{}'".format(fileinput, fileoutput)

    print(command)
    os.system(command)

    return fileoutput


def createavimjpeg(context, strip):
    fileinput = bpy.path.abspath(strip.filepath)
    fileoutput = fileinput.rpartition(".")[0] + "_mjpeg.avi"

    command = "ffmpeg -i '{}' -vcodec mjpeg -q:v 1 '{}'".format(fileinput, fileoutput)

    print(command)
    os.system(command)

    return fileoutput


# classes
class CreateAvi(Operator):
    bl_idname = "sequencer.createavi"
    bl_label = "Create avi file"
    bl_description = "Create an avi output file"
    bl_options = {'REGISTER', 'UNDO'}

    size = IntProperty(
            name="proxysize",
            default=1
            )

    @classmethod
    def poll(self, context):
        strip = functions.act_strip(context)
        scn = context.scene
        if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
            return strip.type in ('MOVIE')
        else:
            return False

    def execute(self, context):
        strips = functions.get_selected_strips(context)

        for strip in strips:
            # deselect all other strips
            for i in strips:
                i.select = False
            # select current strip
            strip.select = True
            if strip.type == "MOVIE":
                if self.size == 1:
                    fileoutput = createavi(context, strip)
                elif self.size == 2:
                    fileoutput = createavimjpeg(context, strip)
                strip.filepath = fileoutput

        # select all strips again
        for strip in strips:
            try:
                strip.select = True
            except ReferenceError:
                pass

        bpy.ops.sequencer.reload()

        return {'FINISHED'}


class CreateDatamosh(Operator):
    bl_idname = "sequencer.createdatamosh"
    bl_label = "Create Datamosh"
    bl_description = "Create Datamosh"

    @classmethod
    def poll(self, context):
        strip = functions.act_strip(context)
        scn = context.scene
        if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
            return strip.type in ('MOVIE')
        else:
            return False

    def execute(self, context):
        preferences = context.preferences
        prefs = preferences.addons[__package__].preferences
        strips = functions.get_selected_strips(context)

        for strip in strips:
            # deselect all other strips
            for i in strips:
                i.select = False
            # select current strip
            strip.select = True
            if strip.type == "MOVIE":
                fileoutput = createdatamosh(context, strip)
                if prefs.load_glitch:
                    strip.filepath = fileoutput

        # select all strips again
        for strip in strips:
            try:
                strip.select = True
            except ReferenceError:
                pass

        bpy.ops.sequencer.reload()

        return {'FINISHED'}


class CreateGlitchToolPanel(Panel):
    bl_label = "Glitch Tools"
    bl_idname = "OBJECT_PT_GlitchTool"
    bl_space_type = 'SEQUENCE_EDITOR'
    bl_region_type = 'UI'

    @classmethod
    def poll(self, context):
        if context.space_data.view_type in {'SEQUENCER',
                                            'SEQUENCER_PREVIEW'}:
            strip = functions.act_strip(context)
            scn = context.scene
            preferences = context.preferences
            prefs = preferences.addons[__package__].preferences
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                if prefs.use_glitch_panel:
                    return strip.type in ('MOVIE')
        else:
            return False

    def draw_header(self, context):
        layout = self.layout
        layout.label(text="", icon="GAME")

    def draw(self, context):

        preferences = context.preferences
        prefs = preferences.addons[__package__].preferences

        layout = self.layout

        layout.operator("sequencer.createavi", text="Create avi (same codec)")
        layout.operator("sequencer.createavi", text="Create avi (mjpeg)").size = 2

        layout.prop(prefs, "all_keyframes")
        layout.prop(prefs, "load_glitch")

        layout.operator("sequencer.createdatamosh")