Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScreenVideo encoder in Java

Tags:

java

red5

encoder

Anyone know of a Java video encoder for ScreenVideo (v1 or v2) which is free? I know ffmpeg has a C++ version and Lee Felarca wrote one in AS3; but I really would like to have one in Java.
AS3: http://www.zeropointnine.com/blog/assets_code/SimpleFlvWriter.as.txt

like image 835
Paul Gregoire Avatar asked Dec 28 '22 07:12

Paul Gregoire


1 Answers

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

Here's a snippet of example code encoding desktop screenshots to a flv (mp4):

 final Robot robot = new Robot();
 final Toolkit toolkit = Toolkit.getDefaultToolkit();
 final Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());

 // First, let's 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, also on the Xuggle website here.

If a native wrapper is what you wanted, run a web search for "IContainerFormat flv" for other bits of example code.

Also, there is already a very similar question


Update: Native java implementation

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

like image 122
Andy Avatar answered Dec 30 '22 21:12

Andy