Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8195585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:11:12+00:00 2026-06-07T05:11:12+00:00

I am working on a Java application to record the screen. I am doing

  • 0

I am working on a Java application to record the screen. I am doing this using a Robot to take several screenshots, save them to a temporary folder and I then use JpegImagesToMovie.java to build these into a QuickTime movie file.

The problem I am experiencing is that, despite developing my script to run at 20fps, I only achieve around 5fps. I have tracked this down to the disk speed in that it is taking too long to save the image to disk and this is holding up the rest of the script.

Next, I modified the script to store the images in an array of BufferedImages and then write them to disk once recording has stopped which fixes the frame rate, however when recoding, Java will quickly run out of memory (After a few seconds of recording).

Does anyone have any ideas or experience with doing this. One solution I can think of is if there is a way to increase the compression on the JPEG images but I am unsure of how to do this.

Any help would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:11:14+00:00Added an answer on June 7, 2026 at 5:11 am

    One option you might want to consider is to do the processing on multiple threads. One thread can be dedicated to taking screenshots, and many other threads can write to disk. Since writing to disk is not a CPU-intensive operation you can have many of them running concurrently, each one writing to a different files. The following program works fine on my machine with 512M heap size:

    import javax.imageio.ImageIO;
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.Date;
    import java.util.Timer;
    import java.util.TimerTask;
    import java.util.concurrent.*;
    import java.util.concurrent.atomic.AtomicInteger;
    
    public class ImageWritingMain
    {
      public static void main(String[] args) throws Exception
      {
        // a queue
        final BlockingQueue<BufferedImage> queue = 
            new LinkedBlockingQueue<BufferedImage>();
    
        // schedule a thread to take 20 images per second and put them in 
        // the queue
        int fps = 20;
        final ScreenShotRecorder recorder = 
            new ScreenShotRecorder(new Robot(), queue);
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(recorder, 0, (1000L/fps));
    
        // make a directory to hold the screenshot images
        String id = new Date().toString().replace(' ', '-').replace(':', '-');
        File imageDir = new File("images-" + id);
        imageDir.mkdirs();
    
        // start 10 threads, and each thread reads from the queue and 
        // writes the image to a file
        int nWriterThreads = 10;
        ExecutorService threadPool = Executors.newFixedThreadPool(nWriterThreads);
        for (int i = 0; i < nWriterThreads; i++)
        {
          ImageWriter task = new ImageWriter(queue, imageDir);
          threadPool.submit(task);
        }
        System.out.println("Started all threads ..");
    
        // wait as long as you want the program to run (1 minute, for example) ...
        Thread.sleep(60 * 1000L);
        // .. and shutdown the threads
        System.out.println("Shutting down all threads");
        threadPool.shutdownNow();
        timer.cancel();
    
        if (! queue.isEmpty())
        {
          System.out.println("Writing " + queue.size() + " remaining images");
          // write the remaining images to disk in the main thread
          ImageWriter writer = new ImageWriter(queue, imageDir);
          BufferedImage img = null;
          while ((img = queue.poll()) != null)
          {
            writer.writeImageToFile(img);
          }
        }
      }
    }
    
    class ScreenShotRecorder extends TimerTask
    {
      private static final Rectangle screenRect = 
          new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
      private static final AtomicInteger counter = new AtomicInteger();
      private final Robot robot;
      private final BlockingQueue<BufferedImage> imageQueue;
    
      ScreenShotRecorder(Robot robot, BlockingQueue<BufferedImage> imageQueue)
      {
        this.robot = robot;
        this.imageQueue = imageQueue;
      }
    
      @Override
      public void run()
      {
        try
        {
          BufferedImage image = robot.createScreenCapture(screenRect);
          imageQueue.put(image);
          System.out.println(Thread.currentThread() + 
              ": Took screenshot #" + counter.incrementAndGet());
        }
        catch (InterruptedException e)
        {
          System.out.println("Finishing execution of " + Thread.currentThread());
          return;
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    }
    
    class ImageWriter implements Runnable
    {
      private static final AtomicInteger counter = new AtomicInteger();
      private final BlockingQueue<BufferedImage> imageQueue;
      private final File dir;
    
      ImageWriter(BlockingQueue<BufferedImage> imageQueue, File dir)
      {
        this.imageQueue = imageQueue;
        this.dir = dir;
      }
    
      @Override
      public void run()
      {
        while (true)
        {
          try
          {
            BufferedImage image = imageQueue.take();
            writeImageToFile(image);
          }
          catch (InterruptedException e)
          {
            System.out.println("Finishing execution of " + Thread.currentThread());
            return;
          }
          catch (Exception e)
          {
            e.printStackTrace();
          }
        }
      }
    
      public void writeImageToFile(BufferedImage image) throws IOException
      {
        File file = new File(dir, "screenshot-" + counter.incrementAndGet());
        ImageIO.write(image, "JPG", file);
        System.out.println(Thread.currentThread() + 
            ": Wrote " + file.getCanonicalPath());
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working a java application using H2 Database in embedded mode. My Application
I'm working on a Java application that uses JavaSpace. We're developing this in Eclipse.
I am working on a Java Web Application that exposes a web service. This
We are working on packaging Java 7 application for Windows using install4j. The problem
I am working on a Java application which has a threading issue. While using
I'm using Java for a web application, and I'm working with a MySql database.
I have a Java application that is working as a service. After several days
I have an existing and working java web application. I want to make this
I am working Java EE application. Requirements are very less as of now, only
Im working on a Java Application that edits Pdf files. Furthermore a shell script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.