How to get over 30FPS using Java in a Screen Capture Program?

前端 未结 2 913
遥遥无期
遥遥无期 2020-12-17 06:40

I\'m currently using the Robot classes in Java to record the screen. However, it does not achieve the minimum of 30 frames per second. I\'m not re-creating objects, and am b

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 06:56

    Build on @Samuel's answer, according to the official ffmpeg documentation you should be able to keep it pretty cross platform if you make the file parameter passed to the FFmpegFrameGrabber (which is really an input parameter that gets passed down as the -i option to ffmpeg) adhere to the different formats each device expects.

    ie:

    for Windows: dshow expects -i video="screen-capture-recorder"

    for OSX: avfoundation expects -i ":"

    and for Linux: x11grab expects -i :+,.

    So just passing those values (arguments to -i) to the constructor and setting the format (via setFormat) accordingly should do the trick:

    Examples:

    for Windows:

    new FFmpegFrameGrabber("video=\"screen-capture-recorder\"")
        .setFormat("dshow");
    

    for OSX:

    new FFmpegFrameGrabber("\":\"")
        .setFormat("avfoundation");
    

    for Linux:

    new FFmpegFrameGrabber(":+,")
        .setFormat("x11grab");
    

    PS: Haven't tested this fully so not sure if the quotes are actually necessary.

提交回复
热议问题