ScreenVideo Encoder in Java

Does anyone know a Java video encoder for ScreenVideo (v1 or v2) that is free? I know that ffmpeg has a C ++ version, and Lee Felarca wrote one in AS3; but I really would like to have it in Java.

AS3: http://www.zeropointnine.com/blog/assets_code/SimpleFlvWriter.as.txt

+4
source share
4 answers

I suggest that the Xuggle library does what you want - although it may actually be a wrapper around a native library such as ffmpeg.

Here is a snippet of sample code that encodes screenshots of the desktop on flv (mp4):

final Robot robot = new Robot(); final Toolkit toolkit = Toolkit.getDefaultToolkit(); final Rectangle screenBounds = new Rectangle(toolkit.getScreenSize()); // First, let make a IMediaWriter to write the file. final IMediaWriter writer = ToolFactory.makeWriter("output.mp4"); // We tell it we're going to add one video stream, with id 0, // at position 0, and that it will have a fixed frame rate of // FRAME_RATE. writer.addVideoStream(0, 0, FRAME_RATE, screenBounds.width, screenBounds.height); // Now, we're going to loop long startTime = System.nanoTime(); for (int index = 0; index < SECONDS_TO_RUN_FOR*FRAME_RATE.getDouble(); index++) { // take the screen shot BufferedImage screen = robot.createScreenCapture(screenBounds); // convert to the right image type BufferedImage bgrScreen = convertToType(screen, BufferedImage.TYPE_3BYTE_BGR); // encode the image to stream #0 writer.encodeVideo(0,bgrScreen, System.nanoTime()-startTime, TimeUnit.NANOSECONDS); System.out.println("encoded image: " +index); // sleep for framerate milliseconds Thread.sleep((long) (1000 / FRAME_RATE.getDouble())); } // Finally we tell the writer to close and write the trailer if // needed writer.close(); 

This code is from this tutorial on the Xuggle website.

More advanced encoding is also on the Xuggle website here .

If the native shell is what you wanted, run the web search "IContainerFormat flv" for the other bits of the sample code.

In addition, a very similar question already exists.


Update: Original Java Implementation

Check out ScreenVideoEncoder.java from the bigbluebutton project on github.

+8
source

Werner Randelshofer posted a blank blog recorder on his blog and was kind enough to post a source: http://www.randelshofer.ch/blog/2011/05/pure-java-screen-recorder/ He wants to do what you want to.

+2
source

I believe that BigBlueButton has implemented one, but I do not know if they open it. Check there.

0
source

I donโ€™t know if you find anything good written in pure Java without using your own code. Video encoding is a very time-consuming task, which is why it is usually written in โ€œfastโ€ native code in languages โ€‹โ€‹such as C or even Assembler. Video encoding often uses special instructions for processors and GPUs to increase speed - all this is not available for Java, so it makes very little sense to write video encoders that support production in Java. If I were you, I would just take my own solution and put it in JNI, JNA or Swig (popular Java-to-native connectors). If you need high portability (e.g. 32-bit Windows, 64-bit Windows, 32-bit Linux, 64-bit Linux), just compile this native library for these four platforms and paste into your JARs. If you just need to write uncompressed video, it can be easily done in Java and it will be as fast as native code. Just take this SimpleFlvWriter.as that you posted and rewrite it in Java - this should not be a difficult task.

0
source

All Articles