Python Script
# ...
class SourceVideo(SourceMedia)
"""Contains the video's complete frame buffer."""
initialize(self, filePath)
super().initialize()
capture = cv2.VideoCapture(filePath)
while capture.isOpened():
_, frame = capture.read() # frame is a NumPy array
self.buffer.append(frame)
capture.release()
# ...
class TimelineWidgetItem(QtWidgets.QWidget)
"""Click-draggable widget with user-adjustable position and duration."""
initialize(self, sourceMedia, previousClip=None, nextClip=None)
hlayoutMain = QtWidgets.QHBoxLayout()
grabberL = QtWidgets.QButton()
grabberR = QtWidgets.QButton()
self.sourceMedia = sourceMedia
self.startPosition = 0 if previous is None else previous.endPosition
self.startFrame = 0
frameCount = self.startPosition + sourceMedia.length
self.endPosition = frameCount if next is None else next.startPosition
self.timelineFrames = []
# ...
# ...
class TimelineWidget(QtWidgets.QWidget)
"""Timeline containing TimelineWidgetItems."""
initialize(self)
self.timeline = QtWidgets.QHBoxLayout()
dropEvent(self, dropped)
"""Drop the TimelineWidgetItem according to the specified mouse position."""
for timelineItemIndex in self.timeline.count(),
timelineItem = self.timeline.ItemAt(timelineItemIndex)
if pos.x() < timelineItem.x() + timelineItem.size().width() // 2,
self.timeline.insertWidget(timelineItemIndex-1, dropped)
break
# ...
class AnimatedTextureTool()
initialize(self)
# ...
self.buildGUI()
# ...
buildGUI(self)
# Toolbar - UI
toolbarHlayout = QtWidgets.QHBoxLayout()
self.toolbarBtnImport = Forza.Widgets.FileBrowser("Import") # adds a new clip
self.toolbarNboxDuration = Forza.Widgets.NumberBox("Duration")
self.toolbarNboxFrameScalar = Forza.Widgets.NumberBox("Frame Size Scalar")
self.toolbarNboxFrameRate = Forza.Widgets.NumberBox("Frame Rate")
self.toolbarNboxFramesX = Forza.Widgets.NumberBox("Frames X")
self.toolbarNboxFramesY = Forza.Widgets.NumberBox("Frames Y")
self.toolbarChkboxSplitExported = Forza.Widgets.NumberBox("Flipbook Per Clip")
self.toolbarCboxOutputSizeX = Forza.Widgets.NumberBox("Output Size X")
self.toolbarCboxOutputSizeY = Forza.Widgets.NumberBox("Output Size Y")
self.toolbarBtnPlay = QtWidgets.QButton("Play")
self.toolbarBtnExport = QtWidgets.QButton("Export Timeline")
self.toolbarTxtboxOutputPath = QtWidgets.QTextBox()
# ...
# Player - UI(Upper RHS)
previewVlayout = QtWidgets.QVBoxLayout()
self.previewGviewVideo = QtWidgets.QGraphicsView() # displays the playhead-relative frame
# ...
# Selection - UI (Middle RHS)
hlayoutOperations = QtWidgets.QHBoxLayout()
self.operationsBtnSplit = QtWidgets.QButton("Split") # used for multi-texture flipbook shader
self.operationsBtnDelete = QtWidgets.QButton("Delete") # removes the selected clip
# ...
# Timeline - UI (Lower RHS)
timelineVlayout = QtWigets.QVBoxLayout()
self.timelineSldrPlayhead= QtWidgets.QSlider()
self.timelineWdgt = TimelineWidget()
# ...
# Toolbar - Signals
# ...
self.toolbarBtnExport.clicked.connect( # generate a flipbook from the current timeline
lambda: self.export(
[timelineWdgtItem for timelineWdgtItem in self.timelineWdgt],
self.toolbarNboxFramesX.value(),
self.toolbarNboxFramesY.value(),
self.toolbarCboxOutputSizeX.value(),
self.toolbarCboxOutputSizeY.value(),
self.toolbarTxtboxOutputPath.value()
)
)
# ...
export(self, clips, outputFramesX, outputFramesY, outputSizeX, outputSizeY, outputPath)
""""Converts the provided video clips into flipbook textures."""
for clip in clips,
flipbook = np.empty(outputSize, dtype=object)
j = 0 # X & Y are inverted, as expected when traversing matrices
i = 0
for frame in clip.timelineFrames,
flipbook [i, j] = frame
j += 1
if j >= outputFramesX,
j = 0
i += 1
if i >= outputFramesY,
break
np.save(outputFile, flipbook)
# ...
main()
animatedTextureTool = AnimatedTextureTool()Python Script
# ...
class SourceVideo(SourceMedia)
"""Contains the video's complete frame buffer."""
initialize(self, filePath)
super().initialize()
capture = cv2.VideoCapture(filePath)
while capture.isOpened():
_, frame = capture.read() # frame is a NumPy array
self.buffer.append(frame)
capture.release()
# ...
class TimelineWidgetItem(QtWidgets.QWidget)
"""Click-draggable widget with user-adjustable position and duration."""
initialize(self, sourceMedia, previousClip=None, nextClip=None)
hlayoutMain = QtWidgets.QHBoxLayout()
grabberL = QtWidgets.QButton()
grabberR = QtWidgets.QButton()
self.sourceMedia = sourceMedia
self.startPosition = 0 if previous is None else previous.endPosition
self.startFrame = 0
frameCount = self.startPosition + sourceMedia.length
self.endPosition = frameCount if next is None else next.startPosition
self.timelineFrames = []
# ...
# ...
class TimelineWidget(QtWidgets.QWidget)
"""Timeline containing TimelineWidgetItems."""
initialize(self)
self.timeline = QtWidgets.QHBoxLayout()
dropEvent(self, dropped)
"""Drop the TimelineWidgetItem according to the specified mouse position."""
for timelineItemIndex in self.timeline.count(),
timelineItem = self.timeline.ItemAt(timelineItemIndex)
if pos.x() < timelineItem.x() + timelineItem.size().width() // 2,
self.timeline.insertWidget(timelineItemIndex-1, dropped)
break
# ...
class AnimatedTextureTool()
initialize(self)
# ...
self.buildGUI()
# ...
buildGUI(self)
# Toolbar - UI
toolbarHlayout = QtWidgets.QHBoxLayout()
self.toolbarBtnImport = Forza.Widgets.FileBrowser("Import") # adds a new clip
self.toolbarNboxDuration = Forza.Widgets.NumberBox("Duration")
self.toolbarNboxFrameScalar = Forza.Widgets.NumberBox("Frame Size Scalar")
self.toolbarNboxFrameRate = Forza.Widgets.NumberBox("Frame Rate")
self.toolbarNboxFramesX = Forza.Widgets.NumberBox("Frames X")
self.toolbarNboxFramesY = Forza.Widgets.NumberBox("Frames Y")
self.toolbarChkboxSplitExported = Forza.Widgets.NumberBox("Flipbook Per Clip")
self.toolbarCboxOutputSizeX = Forza.Widgets.NumberBox("Output Size X")
self.toolbarCboxOutputSizeY = Forza.Widgets.NumberBox("Output Size Y")
self.toolbarBtnPlay = QtWidgets.QButton("Play")
self.toolbarBtnExport = QtWidgets.QButton("Export Timeline")
self.toolbarTxtboxOutputPath = QtWidgets.QTextBox()
# ...
# Player - UI(Upper RHS)
previewVlayout = QtWidgets.QVBoxLayout()
self.previewGviewVideo = QtWidgets.QGraphicsView() # displays the playhead-relative frame
# ...
# Selection - UI (Middle RHS)
hlayoutOperations = QtWidgets.QHBoxLayout()
self.operationsBtnSplit = QtWidgets.QButton("Split") # used for multi-texture flipbook shader
self.operationsBtnDelete = QtWidgets.QButton("Delete") # removes the selected clip
# ...
# Timeline - UI (Lower RHS)
timelineVlayout = QtWigets.QVBoxLayout()
self.timelineSldrPlayhead= QtWidgets.QSlider()
self.timelineWdgt = TimelineWidget()
# ...
# Toolbar - Signals
# ...
self.toolbarBtnExport.clicked.connect( # generate a flipbook from the current timeline
lambda: self.export(
[timelineWdgtItem for timelineWdgtItem in self.timelineWdgt],
self.toolbarNboxFramesX.value(),
self.toolbarNboxFramesY.value(),
self.toolbarCboxOutputSizeX.value(),
self.toolbarCboxOutputSizeY.value(),
self.toolbarTxtboxOutputPath.value()
)
)
# ...
export(self, clips, outputFramesX, outputFramesY, outputSizeX, outputSizeY, outputPath)
""""Converts the provided video clips into flipbook textures."""
for clip in clips,
flipbook = np.empty(outputSize, dtype=object)
j = 0 # X & Y are inverted, as expected when traversing matrices
i = 0
for frame in clip.timelineFrames,
flipbook [i, j] = frame
j += 1
if j >= outputFramesX,
j = 0
i += 1
if i >= outputFramesY,
break
np.save(outputFile, flipbook)
# ...
main()
animatedTextureTool = AnimatedTextureTool()