Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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)
                return;
 
            // -- 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 7:25am
Yvar Birx2.4K
Rate this: bad
good
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:
http://www.c-sharpcorner.com/UploadFile/armoghanasif/CaptureDesktopActivities11122005013755AM/CaptureDesktopActivities.aspx[^]
http://mycomponent.blogspot.hu/2009/04/capture-screen-activitiesvideo-using.html[^]
  Permalink  
Comments
Yvar Birx at 2-Feb-13 12:49pm
   
Cheers mate, shame I didn't thought of that. ;3
Edo Tzumer at 3-Feb-13 1:21am
   
Of course!
5+
Rate this: bad
good
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".
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 DamithSL 165
4 Tomas Takac 144
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2014
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