Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for specific workflows and automation for various movie genres in moviepy? #2048

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file.
Empty file.
23 changes: 23 additions & 0 deletions moviepy/workflows/Automater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import abc

# An abstract base class for automation
# The idea is you can create custom Automater classes that take videos as parameters
# and implement a method where you can automate the splitting of your video into sections
class Automater(abc.ABC):
def __init__(self, videos):
self.videos = videos # Your list of full video clips

# A method for the user to implement
# Provides time data to automates the splitting of your video into sections
# using the sectionVideos function
@abc.abstractmethod
def determineSections(self):
pass

# Returns a list of sectioned videos dependent on the output of determineSections
def sectionVideos(videoTimeData):
videos = []
# Iterate over key values
for video, time in videoTimeData:
videos.append(video.cutout(time[0], time[1])) # Cut the video out based on the time interval
return videos
14 changes: 14 additions & 0 deletions moviepy/workflows/Section.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import abc

# An abstract base class for sections
# Once your video has been split into sections, you can act on the information
# provided from each sectioned video clip
class Section(abc.ABC):
def __init__(self, sectionedVideos):
self.videos = sectionedVideos # Your list of sectioned video clips

# A user defined method for determining the template that your sectioned video clips should use
# Often will result in the creation of custom templates; the provided
@abc.abstractmethod
def determineTemplate(self):
pass
36 changes: 36 additions & 0 deletions moviepy/workflows/Template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip

# An abstract parent class for templates
# Templates provide a powerful way to approach video editing,
# taking sections and automatically creating a video based on the information
# encoded in the section and the template.
# This is where the real magic happens, taking a list of sectioned videos and
# turning them into one edited section of a video.
# Templates apply orientation and fx to clips in an organized manner
# This is a base class for templates that can be extended via inheritance
class BaseTemplate():
def __init__(self, videos, orientationFunction=lambda: None, audioFXFunction=lambda: None, videoFXFunction=lambda: None):
self.videos = videos
self.orientationFunction = orientationFunction
self.audioFXFunction = audioFXFunction
self.videoFXFunction = videoFXFunction

# Sets the orientation of each sectioned video
def setOrientations(self):
self.orientationFunction()
# Sets the audio fx of each sectioned video
def setAudioFX(self):
self.audioFXFunction()
# Sets the video fx of each sectioned video
def setVideoFX(self):
self.videoFXFunction()

# renders the video given the current template information
# shows the user the template and then returns it for further customized editing
def renderVideo(self):
# composite template
template = CompositeVideoClip([video for video in self.videos])
# preview template
template.preview()
# return template
return template
9 changes: 9 additions & 0 deletions moviepy/workflows/automaters/MusicAutomater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from moviepy.workflows.Automater import Automater
# Implements abstract Automater class
class MusicAutomater(Automater):
def __init__(self, videos):
super().__init__(videos)

# TODO: write my code to determine music vid sections based on the vid input here
def determineSections(self):
raise NotImplementedError
9 changes: 9 additions & 0 deletions moviepy/workflows/sections/MusicSection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from moviepy.workflows.Section import Section
# Implements abstract Section class
class MusicSection(Section):
def __init__(self, videos):
super().__init__(videos)

# TODO: write my code to determine which template to use based on videos here
def determineTemplate(self):
raise NotImplementedError
8 changes: 8 additions & 0 deletions moviepy/workflows/templates/EqualDivision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# What the base templates would do is provide support
# to make the determineTemplate function easier to create
from moviepy.workflows.Template import BaseTemplate

# Instantiate template
# In the case of equal division, the screens would have an equal orientation
# TODO
# equal_division = BaseTemplate()
21 changes: 21 additions & 0 deletions moviepy/workflows/templates/PictureInPicture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# What the base templates would do is provide support
# to make the determineTemplate function easier to create
from moviepy.workflows.Template import BaseTemplate
# Extend class
class PictureInPicture(BaseTemplate):
def __init__(self, videos):
super().__init__(videos)

# TODO: implement methods to customize video parameters
#
def setOrientations():
raise NotImplementedError
def setAudioFX():
raise NotImplementedError
def setVideoFX():
raise NotImplementedError

# Instantiate template
# In the case of picture_in_picture, a picture_in_picture setup would be created
# TODO
# picture_in_picture = BaseTemplate()
14 changes: 14 additions & 0 deletions moviepy/workflows/templates/Title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# What the base templates would do is provide support
# to make the determineTemplate function easier to create
from moviepy.workflows.Template import BaseTemplate
# Extend class
class Title(BaseTemplate):
# TODO: extend BaseTemplate in title class
def __init__(self, videos, orientationFunction, audioFXFunction, videoFXFunction):
super().__init__(videos, orientationFunction, audioFXFunction, videoFXFunction)


# Instantiate extended class
# In the case of title, some sort of title screen would be created
# TODO
# title = Title()