diff --git a/src/main/java/com/aimmac23/node/RecordVideoCallable.java b/src/main/java/com/aimmac23/node/RecordVideoCallable.java index a5e3ffe..139a7cd 100644 --- a/src/main/java/com/aimmac23/node/RecordVideoCallable.java +++ b/src/main/java/com/aimmac23/node/RecordVideoCallable.java @@ -24,6 +24,7 @@ public class RecordVideoCallable implements Callable { private LibVPX vpxLibrary; private EncoderInterface encoder; + private File outputFile; public RecordVideoCallable(int targetFramerate, ScreenshotSource screenshotSource, LibVPX vpxLibrary, EncoderInterface encoderLibrary) { this.targetFramerate = targetFramerate; @@ -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()); diff --git a/src/main/java/com/aimmac23/node/VideoRecordController.java b/src/main/java/com/aimmac23/node/VideoRecordController.java index 814c9a6..737ac31 100644 --- a/src/main/java/com/aimmac23/node/VideoRecordController.java +++ b/src/main/java/com/aimmac23/node/VideoRecordController.java @@ -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); } diff --git a/src/test/java/com/aimmac23/hub/TestScreenRecordMain.java b/src/test/java/com/aimmac23/hub/TestScreenRecordMain.java new file mode 100644 index 0000000..96dae29 --- /dev/null +++ b/src/test/java/com/aimmac23/hub/TestScreenRecordMain.java @@ -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); + } + } + +}