Click here to Skip to main content
15,883,623 members
Please Sign up or sign in to vote.
4.00/5 (1 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:

C#
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)).

C#
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

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[^]
 
Share this answer
 
Comments
Yvar Birx 2-Feb-13 12:49pm    
Cheers mate, shame I didn't thought of that. ;3
Joezer BH 3-Feb-13 1:21am    
Of course!
5+
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".
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900