From 9203af49b2831ac008e021f2c2fbba9802753e5a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Oct 2022 10:13:54 -0300 Subject: [PATCH] rawvideoRecorder --- .../basics/presentation/Presentation.java | 10 +-- .../basics/presentation/RawVideoRecorder.java | 67 +++++++++++++++++++ .../basics/presentation/VideoMaker.java | 15 +++++ 3 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 src/main/java/graphical/basics/presentation/RawVideoRecorder.java create mode 100644 src/main/java/graphical/basics/presentation/VideoMaker.java diff --git a/src/main/java/graphical/basics/presentation/Presentation.java b/src/main/java/graphical/basics/presentation/Presentation.java index 4ff104f..8ad5929 100644 --- a/src/main/java/graphical/basics/presentation/Presentation.java +++ b/src/main/java/graphical/basics/presentation/Presentation.java @@ -205,16 +205,11 @@ public void joinBackGroundTasks() { public void processFrame() { runBehaviors(); frameCounter++; - System.out.println("COUNTER(" + frameCounter + ")"); - var before1 = System.currentTimeMillis(); paintComponent(bufferedGraphics); if (!isDisablePreview) frame.repaint(); - System.out.println((System.currentTimeMillis() - before1) + "ms processando quadro"); var before2 = System.currentTimeMillis(); if (!disableCodec) videoCodec.addFrame(graphicEngine.getActualFrame()); - System.out.println((System.currentTimeMillis() - before1) + "ms de codec"); - if (disableCodec) { try { Thread.sleep(20); @@ -250,7 +245,8 @@ public void runBehaviors() { public void add(Gobject gobject) { gobjects.add(gobject); } - public void add(Gobject... gs){ + + public void add(Gobject... gs) { gobjects.addAll(Arrays.asList(gs)); } @@ -295,7 +291,7 @@ public void execute(Task... tasks) { public void cut() { - // wait(seconds(10)).execute(); + // wait(seconds(10)).execute(); if (!disableCodec) { videoCodec.saveVideo(); diff --git a/src/main/java/graphical/basics/presentation/RawVideoRecorder.java b/src/main/java/graphical/basics/presentation/RawVideoRecorder.java new file mode 100644 index 0000000..481747a --- /dev/null +++ b/src/main/java/graphical/basics/presentation/RawVideoRecorder.java @@ -0,0 +1,67 @@ +package graphical.basics.presentation; + +import codec.*; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.util.function.Consumer; + +public class RawVideoRecorder { + final private PresentationConfig presentationConfig; + + private VideoCodec videoCodec; + + public RawVideoRecorder(Consumer configurer) { + this.presentationConfig = new PresentationConfig(); + configurer.accept(presentationConfig); + applyConfig(); + start(); + } + + public RawVideoRecorder(PresentationConfig presentationConfig) { + this.presentationConfig = presentationConfig; + applyConfig(); + start(); + } + + private void applyConfig() { + if (presentationConfig.getCodec() != null) { + switch (presentationConfig.getCodec()) { + case JCODEC: + this.videoCodec = new JCodec(); + break; + case RAW_IMAGE: + this.videoCodec = new RawImageCodec(); + break; + case XUGGLE: + this.videoCodec = new XugglerCodec(presentationConfig); + break; + case GIF: + this.videoCodec = new GIFCodec(); + } + + } else { + this.videoCodec = new XugglerCodec(presentationConfig);//default + } + } + + private void start() { + var executionPath = System.getProperty("user.dir"); + File videoDir = new File(executionPath + "/video"); + videoDir.mkdir(); + + File rawDir = new File(executionPath + "/video/raw"); + rawDir.mkdir(); + + videoCodec.startNewVideo(executionPath + "/video/", "mv" + videoCodec.getFileFormat(), presentationConfig.getFramerate()); + } + + public void addFrame(BufferedImage bufI) { + videoCodec.addFrame(bufI); + } + + public void saveVideo() { + videoCodec.saveVideo(); + } + +} diff --git a/src/main/java/graphical/basics/presentation/VideoMaker.java b/src/main/java/graphical/basics/presentation/VideoMaker.java new file mode 100644 index 0000000..43f9675 --- /dev/null +++ b/src/main/java/graphical/basics/presentation/VideoMaker.java @@ -0,0 +1,15 @@ +package graphical.basics.presentation; + +import java.util.function.Consumer; + +public abstract class VideoMaker extends Presentation { + @Override + protected void buildPresentation() { + // do nothing + } + + @Override + public void build() { + // do nothing + } +}