Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/java/com/aimmac23/node/RecordVideoCallable.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class RecordVideoCallable implements Callable<File> {

private LibVPX vpxLibrary;
private EncoderInterface encoder;
private File outputFile;

public RecordVideoCallable(int targetFramerate, ScreenshotSource screenshotSource, LibVPX vpxLibrary, EncoderInterface encoderLibrary) {
this.targetFramerate = targetFramerate;
Expand All @@ -33,12 +34,17 @@ public RecordVideoCallable(int targetFramerate, ScreenshotSource screenshotSourc
this.targetFramerateSleepTime = (int)((1.0 / targetFramerate) * 1000.0);
}

void setOutputFile(File outputFile) {
this.outputFile = outputFile;
}

@Override
public File call() throws Exception {
int frames = 0;

File outputFile = File.createTempFile("screencast", ".webm");

if (outputFile == null) {
outputFile = File.createTempFile("screencast", ".webm");
}

log.info("Starting new recording at " + targetFramerate + " fps with resolution "
+ screenshotSource.getWidth() + "x" + screenshotSource.getHeight());
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/aimmac23/node/VideoRecordController.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ public VideoRecordController(IRecordArgs recordArgs, LibVPX vpxLibrary, EncoderI
}

public void startRecording() throws Exception {
startRecording(null, 0);
}

public void startRecording(File outputVideo, int targetFramerate) throws Exception {
if(currentCallable != null) {
throw new IllegalStateException("Video recording currently in progress, cannot record again");
}

currentCallable = new RecordVideoCallable(targetFramerate, screenshotSource, vpxLibrary, encoderInterface);
final int frameRate = targetFramerate > 0 ? targetFramerate : this.targetFramerate;
currentCallable = new RecordVideoCallable(frameRate, screenshotSource, vpxLibrary, encoderInterface);
currentCallable.setOutputFile(outputVideo);
currentFuture = executor.submit(currentCallable);
}

Expand Down
40 changes: 40 additions & 0 deletions src/test/java/com/aimmac23/hub/TestScreenRecordMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.aimmac23.hub;

import java.io.File;
import java.io.IOException;

import org.apache.commons.lang3.SystemUtils;
import org.junit.Assert;
import org.junit.Test;

import com.aimmac23.node.VideoRecordController;
import com.aimmac23.node.args.SystemPropertyRecordArgs;
import com.aimmac23.node.jna.EncoderInterface;
import com.aimmac23.node.jna.JnaLibraryLoader;

public class TestScreenRecordMain {

public static void main(String[] args) throws Exception {
new TestScreenRecordMain().test4standardAlone();
//System.exit(0);
}

@Test
public void test4standardAlone() throws Exception, InterruptedException, IOException {
JnaLibraryLoader.init();
final EncoderInterface encoder = JnaLibraryLoader.getEncoder();
final File tmp = SystemUtils.getJavaIoTmpDir();
try (VideoRecordController controller =
new VideoRecordController(new SystemPropertyRecordArgs(), JnaLibraryLoader.getLibVPX(), encoder)) {
final File destVideo = new File(tmp,"demo1.webm");
controller.startRecording(destVideo, 15);
Thread.sleep(5000);
File recording = controller.stopRecording();
System.out.println("recorded video:" + recording);
Assert.assertTrue("Recording file does not exist!", recording.exists());
Assert.assertTrue("File is zero length!", recording.length() > 0);
Assert.assertEquals(destVideo, recording);
}
}

}