Click here to Skip to main content
13,143,008 members (54,526 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Codeproject,

I am currently creating a screen recorder. And for this, I capture a screenshot every 40 miliseconds, I then scrape all the images together in an .avi. Screenshotting is not a problem, I currently use DirectX to do that:

        Surface s;
        public Surface CaptureScreen()
            s = Surface.CreateOffscreenPlain(d, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, SlimDX.Direct3D9.Format.A8R8G8B8, Pool.Scratch);
            d.GetFrontBufferData(0, s);
            return s;

Problem is that saving the file requires way more than 20 miliseconds, and I loop this void in a Timer Tick with the Interval of (1000 / FPS(25)).

        void Tick_Tick(object sender, EventArgs e)
            // -- Stop if not recording.
            if (!Recording)
            // -- Save the screenshot.
            Surface.ToFile(CaptureScreen(), FolderPath + "image" + Directory.GetFiles(FolderPath).Length + ".jpg", ImageFileFormat.Jpg);

This is really, really, really slow. And I would love to know if anyone has any suggestions on how to increase the speed, or maybe not even saving the file. I don't know.
Posted 2-Feb-13 6:25am
Yvar Birx2.4K
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Why are you struggling with saving frames? File creation consumes more resources than keeping a file open and writing frames in it. Even less with a good codec. Make the video directly. Try these for example:[^][^]
Yvar Birx 2-Feb-13 12:49pm
Cheers mate, shame I didn't thought of that. ;3
Edo Tzumer 3-Feb-13 1:21am
Of course!
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

This is a horrible way to do this. You can't create and write MB's of data to files every 20 milliseconds. You'll just completely flood the HD channel.

Get a VNC or Video Capture library to do this. They will do a FAR more efficient job than you're going to "homebrew".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100