Export_3ds: Improved distance cue node search
[blender-addons.git] / power_sequencer / operators / speed_up_movie_strip.py
blobb22f6711195b74b10696bc9aeb21ea13f8b5d7ba
1 # SPDX-FileCopyrightText: 2016-2020 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors
3 # SPDX-License-Identifier: GPL-3.0-or-later
5 import bpy
6 from math import ceil
8 from .utils.global_settings import SequenceTypes
9 from .utils.functions import slice_selection
10 from .utils.doc import doc_name, doc_idname, doc_brief, doc_description
13 class POWER_SEQUENCER_OT_speed_up_movie_strip(bpy.types.Operator):
14 """
15 *brief* Adds a speed effect to the 2x speed, set frame end, wrap both into META
17 Add 2x speed to strip and set its frame end accordingly. Wraps both the strip and the speed
18 modifier into a META strip.
19 """
21 doc = {
22 "name": doc_name(__qualname__),
23 "demo": "https://i.imgur.com/ZyEd0jD.gif",
24 "description": doc_description(__doc__),
25 "shortcuts": [
27 {"type": "TWO", "value": "PRESS", "alt": True},
28 {"speed_factor": 2},
29 "Speed x2",
32 {"type": "THREE", "value": "PRESS", "alt": True},
33 {"speed_factor": 3},
34 "Speed x3",
37 {"type": "FOUR", "value": "PRESS", "alt": True},
38 {"speed_factor": 4},
39 "Speed x4",
42 "keymap": "Sequencer",
44 bl_idname = doc_idname(__qualname__)
45 bl_label = doc["name"]
46 bl_description = doc_brief(doc["description"])
47 bl_options = {"REGISTER", "UNDO"}
49 speed_factor: bpy.props.IntProperty(
50 name="Speed factor", description="How many times the footage gets sped up", default=2, min=0
52 individual_sequences: bpy.props.BoolProperty(
53 name="Affect individual strips",
54 description="Speed up every VIDEO strip individually",
55 default=False,
58 @classmethod
59 def poll(cls, context):
60 return context.selected_sequences
62 def execute(self, context):
63 sequences = [s for s in context.selected_sequences if s.type in SequenceTypes.VIDEO]
65 if not sequences:
66 self.report(
67 {"ERROR_INVALID_INPUT"},
68 "No Movie meta_strip or Metastrips selected. Operation cancelled",
70 return {"FINISHED"}
72 selection_blocks = []
73 if self.individual_sequences:
74 selection_blocks = [[s] for s in sequences]
75 else:
76 selection_blocks = slice_selection(context, sequences)
78 for sequences in selection_blocks:
79 self.speed_effect_add(context, sequences)
81 self.report(
82 {"INFO"}, "Successfully processed " + str(len(selection_blocks)) + " selection blocks"
84 return {"FINISHED"}
86 def speed_effect_add(self, context, sequences):
87 if not sequences:
88 return
90 sequence_editor = context.scene.sequence_editor
91 sequencer = bpy.ops.sequencer
93 sequencer.select_all(action="DESELECT")
94 for s in sequences:
95 s.select = True
96 sequencer.meta_make()
97 meta_strip = sequence_editor.active_strip
99 sequencer.effect_strip_add(type="SPEED")
100 speed_effect = sequence_editor.active_strip
101 speed_effect.use_default_fade = False
102 speed_effect.speed_factor = self.speed_factor
104 duration = ceil(meta_strip.frame_final_duration / speed_effect.speed_factor)
105 meta_strip.frame_final_end = meta_strip.frame_final_start + duration
107 sequence_editor.active_strip = meta_strip
108 speed_effect.select = True
109 meta_strip.select = True
110 sequencer.meta_make()
111 sequence_editor.active_strip.name = (
112 meta_strip.sequences[0].name + " " + str(self.speed_factor) + "x"