recording screen and webcam to video file

I'm trying to create an application to record screen of user or from webcam and save into an video file.

I tried Java Media Framework to make it work but It's fail in Windows 64 bit. I found that Java Media Framework is quite old and it isn't supported now :(

My question is: Are there any another library help us record screen and video from Webcam ? If Java is not supported, What language could help?

I found some application have same feature: + http://www.screencast-o-matic.com/ + http://www.apowersoft.com/free-online-screen-recorder It's java applet that user can download from server without installing.

Thank you in advanced !

Update: I'm finding another solution in HTML5

Update: 2013/07/05** I found WebRTC 1.0 can reach the solution but Google Chrome hasn't suport Media Stream Recorder yet.


我有一个示例代码来使用com.xuggle包来记录屏幕

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.util.concurrent.TimeUnit;

import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.xuggler.ICodec;

public class ScreenRecordingExample {

    private static final double FRAME_RATE = 50;

private static final int SECONDS_TO_RUN_FOR = 20;

    private static final String outputFilename = "c:/mydesktop.mp4";

    private static Dimension screenBounds;

    public static void main(String[] args) {

        // let's make a IMediaWriter to write the file.
    final IMediaWriter writer = ToolFactory.makeWriter(outputFilename);

        screenBounds = Toolkit.getDefaultToolkit().getScreenSize();

        // 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, ICodec.ID.CODEC_ID_MPEG4, 
                   screenBounds.width/2, screenBounds.height/2);

        long startTime = System.nanoTime();

        for (int index = 0; index < SECONDS_TO_RUN_FOR * FRAME_RATE; index++) {

            // take the screen shot
            BufferedImage screen = getDesktopScreenshot();

            // 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);

            // sleep for frame rate milliseconds
            try {
                Thread.sleep((long) (1000 / FRAME_RATE));
            } 
            catch (InterruptedException e) {
                // ignore
            }

        }

        // tell the writer to close and write the trailer if  needed
        writer.close();

    }

    public static BufferedImage convertToType(BufferedImage sourceImage, int targetType) {

        BufferedImage image;

        // if the source image is already the target type, return the source image
        if (sourceImage.getType() == targetType) {
            image = sourceImage;
        }
        // otherwise create a new image of the target type and draw the new image
        else {
            image = new BufferedImage(sourceImage.getWidth(), 
                 sourceImage.getHeight(), targetType);
        image.getGraphics().drawImage(sourceImage, 0, 0, null);
        }

        return image;

    }

    private static BufferedImage getDesktopScreenshot() {
        try {
            Robot robot = new Robot();
        Rectangle captureSize = new Rectangle(screenBounds);
        return robot.createScreenCapture(captureSize);
        } 
        catch (AWTException e) {
            e.printStackTrace();
            return null;
        }

    }

}
链接地址: http://www.djcxy.com/p/81070.html

上一篇: 在csharp中通过usb WebCam录制视频

下一篇: 录制屏幕和网络摄像头到视频文件