Jump to content


Photo

Video Capture DLL


  • Please log in to reply
29 replies to this topic

#1 Frostblade

Frostblade

    GMC Member

  • GMC Elder
  • 3329 posts

Posted 04 July 2010 - 07:13 PM

I've been experimenting with Windows' AVIFile API for the last couple of days; based on this experimentation, I've scraped a video capture DLL together. It exports three functions that allow you to record everything displayed by the host game into an .avi file, compressed using a codec of your choice. The .dll can be downloaded here.

As noted, this dll is very bare-bones. I might come back to it and add a few features to it if it gathers any sort of interest. Any suggestions are of course welcome.

The three functions are as follows:

vcapture_begin( window_handle, filename, fps)

Deletes any file currently occupying filename, creates an avi file in its place and prepares it for recording. The DLL can only record into one file at a time. Pass window_handle() as the first argument, and the video's playback FPS as the third.
When this function is called, the game will pause and the user will be presented with a dialog to select a codec with which the video will be compressed. For some codecs, compression settings can be modified within the dialog. Only codecs installed on the host system will be displayed.
If the user selects Cancel on the dialog, this function returns false (and the following functions will cause your game to hang). Otherwise, the function will return true.

vcapture_frame()

Takes a snapshot of the game, and appends it into the current video file. This can probably be called anywhere outside a Draw event. If the window is minimized, out of focus or outside the desktop area, the frame appended will be incorrect. Bear in mind that this function's speed is dictated by the codec and compression settings used.

vcapture_save()

Ends all video capture operations and finalises the .avi file. The video's filesize will not be visible until this function is called. Once this function has been called, vcapture_begin can be called again to start a new video file. If your game ends after calling vcapture_frame but before calling this function, the file will fail to save and you'll most likely be left with a memory leak.

A few words of warning:
  • I haven't tested, or accounted for, what happens when the functions are called out of the correct sequence. Memory leaks seem likely.
  • Never use any codec marked as "uncompressed". They will leave you with a ridiculously large filesize, as large as a hundred megabytes for a couple of seconds of video. Ideally, to make best use of this tool, you should download a popular modern codec such as DivX or XVid.
  • Not every codec in the list is guaranteed to work. If some codecs don't save frames into the target file, it's probably not the fault of this dll.

  • 1

#2 santa22

santa22

    GMC Member

  • GMC Member
  • 251 posts

Posted 04 July 2010 - 07:35 PM

It looks like its just the dll, what about the scripts for the DLL?
  • 0

#3 Frostblade

Frostblade

    GMC Member

  • GMC Elder
  • 3329 posts

Posted 04 July 2010 - 07:41 PM

EDIT: Initiation and calling scripts have been included in the download link.
  • 0

#4 Pinpickle

Pinpickle

    Abscure Programmer

  • GMC Member
  • 1353 posts

Posted 04 July 2010 - 08:48 PM

This is awesome! Pretty much perfect quality screen recording for free.
For us with no idea what a codec is (I roughly know), what would you recommend for just a basic video that you want to edit and turn into a trailer/teaser? These names mean nothing to me except that I know that I shouldn't choose uncompressed.
  • 0

Posted Image
Posted Image


#5 Frostblade

Frostblade

    GMC Member

  • GMC Elder
  • 3329 posts

Posted 04 July 2010 - 09:21 PM

This is awesome! Pretty much perfect quality screen recording for free.
For us with no idea what a codec is (I roughly know), what would you recommend for just a basic video that you want to edit and turn into a trailer/teaser? These names mean nothing to me except that I know that I shouldn't choose uncompressed.

DivX and XVid are the only high-quality codecs I've used. If you don't have either already, I'd recommend downloading one of them. None of the defaults included with Windows can really compete; in the tests I've attempted, they've achieved filesizes perhaps 10 times smaller than (say) Windows Video 1, with no noticeable drop in quality.

If you're looking to host your video on Youtube, bear in mind that they compress any submission using their own software. The best thing to do is to submit your video to them in the highest quality that's practical (bearing in mind they have a filesize limit of 100mb), at a size no larger than 320x240.
  • 0

#6 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4248 posts
  • Version:GM:Studio

Posted 04 July 2010 - 10:19 PM

I just tried the DLL. Is it normal for the computer to totally hang when the first script is called (the first after the initializer)? I just had to force a shutdown to my computer as even the cursor couldn't move. :mellow:

I'm quite certain I called the scripts correctly: no other one than the frame saver was in a step-like event (and I made sure that wasn't called before the creation script)... How fast is this DLL anyway for those who got it working?
  • 0

#7 Frostblade

Frostblade

    GMC Member

  • GMC Elder
  • 3329 posts

Posted 04 July 2010 - 11:17 PM

The entire computer crashed? That's beyond "odd" and into the realms of "I didn't think it was possible". None of the code I write outside function calls is capable of it, and Windows function calls themselves tend to be very robust.

There are a few debugging routes I could go down, but I'd much prefer to have some sort of lead on how your computer is different to myself and Pinpickle's. Does it happen to be very old or very new? It's possible you're lacking in memory or running a 64-bit version of Windows.
  • 0

#8 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4248 posts
  • Version:GM:Studio

Posted 04 July 2010 - 11:43 PM

The entire computer crashed? That's beyond "odd" and into the realms of "I didn't think it was possible". None of the code I write outside function calls is capable of it, and Windows function calls themselves tend to be very robust.

There are a few debugging routes I could go down, but I'd much prefer to have some sort of lead on how your computer is different to myself and Pinpickle's. Does it happen to be very old or very new? It's possible you're lacking in memory or running a 64-bit version of Windows.

I've got Intel core i3 @ 2.13 GHz, 4 GB of RAM and 64-bit Windows 7 and the computer is really new.

I'll try again some time. But damn if it happens twice. o_0

EDIT: 4 GB of RAM, not 4 MB. xD

Edited by Tepi, 05 July 2010 - 01:21 PM.

  • 0

#9 Frostblade

Frostblade

    GMC Member

  • GMC Elder
  • 3329 posts

Posted 04 July 2010 - 11:53 PM

I've got Intel core i3 @ 2.13 GHz, 4 MB of RAM and 64-bit Windows 7 and the computer is really new.

The 64-bit OS is almost certainly the cause, and I'm afraid I don't know enough about how 64-bit Windows works to fix it- or even to know whether fixing it is possible. For now, in your shoes, I'd probably stay away from Game Maker DLLs altogether.
  • -1

#10 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 23 July 2010 - 04:59 AM

This is awesome, but i need to record with sound and i cant find any software to do that... oh well, this is good enough ( i guess sound can be added later... :\ )

edit: @Frostblade: i had a similar crash to the one tepi describes above, i had to restart the ocmputer because my mouse, sound and everything else freezed. After a second run it worked nice and smoothly, but it only happened the first time i used the dll.

Edited by manuel777, 26 July 2010 - 12:41 AM.

  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#11 B Factory LLC

B Factory LLC

    We're awesome!!

  • New Member
  • 511 posts

Posted 25 July 2010 - 09:25 PM

Cool. I'm going to check this out.
  • 0

If you are neutral in situations of injustice, you have chosen the side of the oppressor. If an elephant has its foot on the tail of a mouse and you say that you are neutral, the mouse will not

appreciate your neutrality.

Posted Image

Anti-Wikileaks Bill introduced in US Congress! (When the giant is mad, it hits hard...)

"So this is how liberty dies. With thunderous applause." - Padme

"The ruling class has the schools and press under its thumb. This enables it to sway the emotions of the masses." - Albert Einstein

Please check out my blog: My link


#12 madjamonline

madjamonline

    GMC Member

  • New Member
  • 76 posts

Posted 27 July 2010 - 11:39 AM

This is absolutely amazing!
The only two suggestions I have is to make an option to record the whole screen, and also the option to specify the video compression if you don't want the dialog to appear to start with.

One of the best DLL's I have ever used! Good job!
  • 0
Jamie

#13 bennelsey

bennelsey

    GMC Member

  • GMC Member
  • 25 posts

Posted 01 August 2010 - 10:24 AM

works like an epic charm :3

tho I did get confused as to what vcapture_frame() was, (since i didnt read its description)

might want to name it to something more intuitive, like vrecord_frame(), capture_frame sounds more like a screenshot than recording a frame for a video

Edited by bennelsey, 01 August 2010 - 10:25 AM.

  • 0

#14 Double U

Double U

    GMC Member

  • New Member
  • 19 posts

Posted 12 September 2010 - 05:02 PM

I don't know how to use this :mellow:
This is what i've got:
http://g2f.nl/8xy8tr <-- My .gmk
But, it doesn't work :( .
It saves to a .avi file,
but i can't open the file.

What is the problem?
  • 0

#15 databot

databot

    admin of moonlight games

  • New Member
  • 309 posts

Posted 12 September 2010 - 07:50 PM

Pretty good DLL Frostblade.

As stated in other posts, intergrated audio capture and selecting a codec ourselves would be nice.

MCI_command is somewhat laggy with regards to captruing audio in sync. I have got it close (1 sec extra/out of sync)
as for those wanting desktop capture, if u can find the desktop window handle and feed that in it should work.


Edit: Just found out reasons for audio discrepancy. Audio is not the problem the link between GML and DLL is the problem.
Because it's relying on the game for frame timing a difference in the FPS between game and record rate causes problems.

best way to solve this if you have the know-how frost is to add a timer thread to the DLL, that calls the capture frame itself when a specified time has passed (1/FPS).

Edited by databot, 12 September 2010 - 08:13 PM.

  • 0
Completed:
Scrip - Command line engine in the palm of your hands Get it Here
XML - XML simplified

#16 Frostblade

Frostblade

    GMC Member

  • GMC Elder
  • 3329 posts

Posted 13 September 2010 - 11:11 AM

best way to solve this if you have the know-how frost is to add a timer thread to the DLL, that calls the capture frame itself when a specified time has passed (1/FPS).

Considering that people are reporting full-computer crashes when I'm calling the bare minimum functions, threads are the last thing I want to start messing around with. Also, I don't really see the point in accurate timing for screencapture; when people are recording a gameplay video at (say) 30fps, they want 30 frames of the game per second rather than 30 frames of realtime capture (which would likely lead to repeated or missed frames, and record any lag that occurs).

I've been looking into ways I might be able to record audio from a specified game, and I haven't found anything that I could use. As far as I can tell, my options are:
-Somehow intercept all audio generated by the game window, using DirectSound. Since I've never used a DirectX component (and I'm pretty certain that DirectX is difficult or impossible to compile under gcc), this is out of the question.
-Emulate the above using the classic Windows Multimedia APIs. As far as I can tell, this isn't possible to do in a portable fashion (that accounts for unusual or multiple devices, and so on), and won't exclusively "listen" to a single window.

Could you elaborate on which MCI commands you're using? If possible, could you perform some basic tests of your method (such as running two different GM games at once and only capturing audio from one of them)?

Edited by Frostblade, 13 September 2010 - 11:12 AM.

  • 0

#17 Double U

Double U

    GMC Member

  • New Member
  • 19 posts

Posted 14 September 2010 - 02:45 PM

I don't know how to use this
This is what i've got:
http://g2f.nl/8xy8tr <-- My .gmk
But, it doesn't work .
It saves to a .avi file,
but i can't open the file.

What is the problem?

Can anybody help me, please?
  • 0

#18 whothat

whothat

    GMC Member

  • New Member
  • 18 posts
  • Version:GM8

Posted 04 December 2010 - 06:48 PM

what is a window_handle?


EDIT, nvm i see it now,
how do you delete posts?

EDIT i still cant get it to work, you should make an example

EDIT, k i got it to work, but you should still have an example with it

Edited by whothat, 06 December 2010 - 02:27 AM.

  • 0
Posted Image

#19 Luca_Scorpion

Luca_Scorpion

    GMC Member

  • New Member
  • 9 posts
  • Version:GM8

Posted 15 February 2012 - 04:59 PM

An example would be nice!
thx
  • 0

#20 NeoTalon27

NeoTalon27

    GMC Member

  • GMC Member
  • 220 posts
  • Version:GM:HTML5

Posted 20 February 2012 - 02:00 PM

I agree with Scorpion, I think this needs an example.
  • 0

#21 Saijee

Saijee

    GMC Member

  • GMC Member
  • 2443 posts
  • Version:Unknown

Posted 27 February 2012 - 06:12 AM

I third scorpion.
  • 0

#22 NeoTalon27

NeoTalon27

    GMC Member

  • GMC Member
  • 220 posts
  • Version:GM:HTML5

Posted 27 February 2012 - 06:26 AM

If nobody is making a tutorial, I will try to make one.
  • 1

#23 cactus

cactus

    GMC Member

  • GMC Member
  • 367 posts

Posted 28 February 2012 - 02:44 AM

Wow, this is great! Very easy to use and produces perfect results. Now I'm able to do HD trailers in great quality without hassle, thank you so much!

As a token of appreciation I made this example:
http://cactusquid.com/misc/vcap.zip (GM7 file, but tested and works in GM8.0 as well)

Edited by cactus, 28 February 2012 - 02:45 AM.

  • 0

#24 NeoTalon27

NeoTalon27

    GMC Member

  • GMC Member
  • 220 posts
  • Version:GM:HTML5

Posted 28 February 2012 - 01:48 PM

Thank you for the example, but why, of all the possible audio, did you pick Katy Perry???
  • 0

#25 cactus

cactus

    GMC Member

  • GMC Member
  • 367 posts

Posted 28 February 2012 - 04:27 PM

Thank you for the example, but why, of all the possible audio, did you pick Katy Perry???

I was briefly considering Bicycle Race by Queen, but decided it wasn't as catchy :)
Posted Image
  • 0

#26 GenoDoucette

GenoDoucette

    g e n o d o

  • GMC Member
  • 1008 posts
  • Version:GM:Studio

Posted 19 December 2012 - 06:50 PM

I may use this.. thanks :)
  • 0

ALWAYS >b3v6o7.jpg< ALWAYS


#27 samuelqwe

samuelqwe

    GMC Member

  • GMC Member
  • 32 posts
  • Version:GM8

Posted 03 March 2013 - 02:42 PM

It does not record... :(
  • 0

Website : My Website

-Leumas Games


#28 trg601

trg601

    Member of the GMC

  • GMC Member
  • 629 posts
  • Version:GM:Studio

Posted 27 June 2013 - 09:06 PM

Yay this is awesome!

and samuelqwe, you need to make it capture the frames (vcapture_frame) after you started it.

Look at cactus's example! (it's good)


  • 0
Because of the forum being archived, the above post is probably pretty old and may not reflect my current opinion.
If you want to find some of my games go to: Mutantbrain

#29 ScottOS

ScottOS

    GMC Member

  • New Member
  • 15 posts
  • Version:GM:Studio

Posted 28 December 2014 - 11:18 PM

I downloaded Frostblades's original .gml file but GameMaker Studio won't convert a gml.

 

I then tried the GM7 file from Cactus.  I was able to import it and convert, then after some modifications was able to get it partially work.  For some reason I'm getting an error that it can't write to the .dll file.

 

Has anyone used this .dll in GameMaker Studio?

 

One of the moderators (TsukaYuriko) suggested that I try AVI-Export (https://marketplace..../179/avi-export).  It's very similar and I can easily get it to run, but it doesn't record sound along with the video.

 

Cactus, how did you get this .dll to incorporate sound?


  • 0

#30 alvsoft

alvsoft

    GMC Member

  • Validating
  • 1 posts
  • Version:GM8

Posted 09 January 2015 - 08:56 PM

Thanks, useful!