dcsimg
Results 1 to 11 of 11

Thread: VB.Net - Screen Recorder help

  1. #1

    Thread Starter
    Hyperactive Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    267

    Question VB.Net - Screen Recorder help

    I was thinking about using backgroundworkers for the Screen Recorder, but I'm gonna try sharing memory with FFmpeg to process my captured images. It might take me a few days, but I'm still open to other ideas.

    What's slowing the capture process down is the saving process within the same timer, but removing saving for testing purposes still didn't give me accurate intervals, but it was a huge improvement in frames captured per second.

    The below frames were captured from a 65 second short film. With an interval of 40, I should've captured 2600 images at 25fps. Dividing the frames captured below by 65 minutes, I captured close to 22fps. Not sure I can get it any better than this unless I use two background workers for capturing, but then their might be too many frames.

    Note: Again, the interval test was done by removing the save function to get greater speed. The attached zip below has the save function, so the intervals and frames per second will be way off. Slow recording and super fast playback. If you can fix this problem, please post it here.

    Name:  ScreenRecorder.PNG
Views: 353
Size:  9.1 KB
    Attached Files Attached Files
    Last edited by Peter Porter; Jul 15th, 2013 at 04:18 PM.

  2. #2
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    946

    Re: VB.Net - Need help incorporating backgroundworkers into screen capture program

    although ive never atempted this i think the same principle would apply with games and framrates.

    asuming the time frame at which each screenshot is taken and recorded is arguably the same every time then you could put a limiter on the process which calls each frame when viewing them, which basically would tell a loop not to process the next frame until x amount of time has passed.

    another way would be to record a time stamp when taking screenshots etc and then using that with a playback counter you synchronize the recorded frames with the playback clock, that way if something lags behind you keep the timeframe correct during playback.

    im not sure how tese would actually work, but in theory i think something like that would be what you need
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  3. #3

    Thread Starter
    Hyperactive Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    267

    Re: VB.Net - Need help incorporating backgroundworkers into screen capture program

    Hi GBeats,

    Thanks for the advice. I'm sorry if the playback image gave the impression that I'm trying to playback as I record. My application doesn't work that way. I have to stop recording in order to playback.

    The problem is that the VidRec timer is not recording fast enough because it's capturing as well as saving. Because of this the timer can't run at the interval set, so the frame rates per second are low. I think Backgroundworkers can fix this problem, or maybe arrays created on the fly to store the captured frames, then later saved after stopping the program from capturing.

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,263

    Re: VB.Net - Need help incorporating backgroundworkers into screen capture program

    A couple of basic points to consider:

    The Windows Forms Timer is notoriously inaccurate. From experience, it becomes erratic at intervals less than 15 or so. Using an interval of 1 will give you no joy.

    In the code you provided, you have set the record interval to 10 and the playback interval to 1, which even if the Timers worked the way you expected, would give you speed up on play back.

    You really need to do some simple profiling. On my PC, it takes roughly 60 milliseconds to copy the screen to the bmp and between 100 and 300 milliseconds to save an image to my highly fragged hard drive. So, for my PC, setting an interval less than 360 for your VidREC Timer is obviously counter productive. Other peoples computers will need different timings.

    Saving a file to a disc drive always takes longer than loading the same file from the drive. So say it took 200ms to load a frame and 400ms to save a frame. An interval of 300 for both timers will give the impression of a speeded up playback. You need to set both intervals to the same value, and that has to be larger than the slowest (400 in this particular example case).

    BackGround Workers (or any multi threading) probably won't help. The operations are very CPU intensive. On a single core CPU, I can't see multithreading giving an advantage (give it a try though, I could always be wrong ). Indeed, if you use multiple threads to max out your CPU, whatever Desktop operations you are trying to record are going to start to run sluggishly. On a multi core CPU, you might get the capture on one core and the save to disc on another core. However, writing to the same drive can't be parallelised, as far as I'm aware, so it'd always be one file at a time.

    Buffering might help. Won't enable the interval to be reduced to less than 60ms though (on my hardware). And given that it takes up to 3 times as long to write to the file as it does to create the bitmap (again , on my hardware), the buffer's going to fill up quite quickly. (At 15 fps and 2.6MB per image, you're looking at 2.3GB per minute being generated).

    You might consider streaming all the images to a single file. I don't know if that would speed up or slow down the writing/reading process. You might also consider using some sort of compression. That could be done on a third core of a suitable multi core CPU.

    Search on Google for alternative methods of capturing the screen image. There's probably something quicker that uses APIs (http://www.codeproject.com/Articles/...ing-the-screen might get you started - not looked at it yet)

    And I'm not going near the sound recording part. Thinking how to synchronise that makes my poor old brain hurt

    Keep at it though. Interesting project


    EDIT:The API's I was thinking of are apparently no faster than the native GDI+ Drawing methods you are using, at least for Windows 7. See here for example http://blog.bobcravens.com/2009/04/f...vista-vs-win7/ . Not looked into DirectX, though (sounds complicated).
    Last edited by Inferrd; Jul 15th, 2013 at 09:07 AM.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,232

    Re: VB.Net - Need help incorporating backgroundworkers into screen capture program

    There ought to be some kind of lossy recording technology possible. After all, unless you are trying to record a playing, full-screen, video, the bulk of the screen won't change from frame to frame. Figuring out what part has changed may be more difficulte than any benefit in speed, but that depends largely on what you are doing.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Hyperactive Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    267

    Re: VB.Net - Need help incorporating backgroundworkers into screen capture program

    Inferrd, thanks for the links, plus pointing out the mistake in my code. I thought it wasn't reading the intervals from the Combobox, but messed up setting it within the timer for testing.

    What I noticed, the Screen Recorder's timer seems to work better with intervals while recording over the Visual Basic window, 25fps, but slows down to around 10fps when I try to record a streaming video from online, but when I revert back to the Visual Basic window recording speeds up again. Do you have any idea how to fix that? I'm thinking a backgroundworker might get around this. 1 for capturing and the other saving buffered images, or maybe a shared buffer with FFmpeg.

  7. #7

    Thread Starter
    Hyperactive Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    267

    Re: VB.Net - Need help incorporating backgroundworkers into screen capture program

    Shaggy Hiker, I'm thinking FFmpeg could solve this, if not backgroundworkers. The screen recorder works fine over the Visual Basic window or MS-Word, but it has problems over a playing video from an online streaming service.

    It also slows to a crawl over my Desktop screen. Hope I can get around this.
    Last edited by Peter Porter; Jul 15th, 2013 at 12:21 PM.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,232

    Re: VB.Net - Need help incorporating backgroundworkers into screen capture program

    I'm not surprised that it slows down when dealing with a playing video. There are lots of things going on there. However, are you saying that it slows to a crawl when NOTHING is happening (the desktop screen)? That's a surprise. Are you capturing the foreground window, or the whole screen?
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Hyperactive Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    267

    Re: VB.Net - Need help incorporating backgroundworkers into screen capture program

    I just tried recording my desktop again with this browser window and Visual basic minimized, no streaming videos, but still the same problem. It records slower than what it does with streaming videos. The problem might be my computer, which is weird because it has 8 cores, but I am designing this to also work with 32bit systems.

    About to run a system analysis program to see if something is wrong.

  10. #10

    Thread Starter
    Hyperactive Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    267

    Re: VB.Net - Need help incorporating backgroundworkers into screen capture program

    Ok, I found the problem recording from Desktop. The Screen Recorder doesn't play well with Windows Aero. When I switched to Windows Classic, recording speeded up.

    Anyway, saving the captured images is what's slowing recording, so I might have to send the captures to shared memory for FFmpeg to pick up and process. From what I've tested by removing the save function, I got alot more frames per second, but still off. Probably the best I can do, even with FFmpeg taking care of the saving.

  11. #11
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: VB.Net - Screen Recorder help

    What I would worry more about is that .NET is not a real-time system. At some point GC will kick in and you'll drop frames. You'll always have to deal with the possibility, so either deal with it now (perhaps take a note of the system ticks each time you capture a frame and then you'll know whether to duplicate a frame) or switch to something that will enable you to write real-time applications such as C++

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width