Skip to content

Commit

Permalink
rawvideoRecorder
Browse files Browse the repository at this point in the history
  • Loading branch information
chompa111 committed Oct 24, 2022
1 parent 4c3a6b7 commit 9203af4
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/main/java/graphical/basics/presentation/Presentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -295,7 +291,7 @@ public void execute(Task... tasks) {

public void cut() {

// wait(seconds(10)).execute();
// wait(seconds(10)).execute();

if (!disableCodec) {
videoCodec.saveVideo();
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/graphical/basics/presentation/RawVideoRecorder.java
Original file line number Diff line number Diff line change
@@ -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<PresentationConfig> 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();
}

}
15 changes: 15 additions & 0 deletions src/main/java/graphical/basics/presentation/VideoMaker.java
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 9203af4

Please sign in to comment.