AVI manipulation

Blitz3D Forums/Blitz3D Programming/AVI manipulation

Chevron(Posted 2005) [#1]
Hello all, Does anyone know how I could import an avi file and save it out frame for frame to .bmp. Is there a .dll wrapper availible to use with blitz?


jfk EO-11110(Posted 2005) [#2]
There is a DLL that allows to save an avi. It will save frames as BMP and then tell the DLL to add the bmp to a destination AVI.

The main problem with saving single frames from an Avi is: BLitz will play the Avi realtime corrected, this means, wen you copy a frame to an imagebufffer and then save the buffer as a BMP, Blitz will miss some frames of the Avi that is playing (using OpenMovie and DrawMovie). There is no Pause function and no seek-Frame function so far.
I can tell you the best solution that I have found so far that works reliably (forget MCISendString, seekFrame doesn't work reliably)

Well I use MCISendString to obtain information about an Avi, all I need to know is: the number of Frames and the Rate it is played. MCISendString can tell you this (see Coder Archives, userlibs)

Then I have installed Avisynth. It's freeware and acts as a frameserver in the OS. Basicly you can open an Avisynth script as a Movie. The script includes the Avi source path, plus some modification commands etc, like sharpen, or blur, whatever.

Now I write a temporary avisynth script from within Blitz that look like this:
DirectShowSource("source.avi")
Trim(n,n+32)


Where n is the number of the wanted frame. Avisynth will now deliver a snippet of the original source avi, beginning at frame n, containig 32 fames. I am now playing this Movie to the backbuffer. 32 Imagebuffers are ready as a cache buffer. I will then copy the 32 frames to the imagebuffers using copyrect. Copying a frame of 720*576 Pixel (PAL) takes 0 to 1 milliseconds, so it's fast enough not to drop frames.

Now i can edit the 32 frames and save them to a destination avi, or as BMPs etc.
THen I add 32 to n and restart the process with the temporary Avisynth script. This is the fastest reliable method I have found so far. Accesing a single frame by Avisynth may be more simple, but it's also much slower.

BLitzaviDLL:
http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=pk-studiox6401162003184358&comments=no
avisynth:
http://www.avisynth.org/

You may automate the installation of Avisynth by testing if OPenMovie an Avisynth script will return zero, and if so, suggest to install Avisynth during the installation of your Tool.


Barliesque(Posted 2005) [#3]
What you need is in two parts: First, a library function to let you play an AVI into a buffer, and allow you to move to a particular frame. Then a second function to save the buffer to an image file. There are a couple of options for both tasks...

To play a specific frame of an AVI...
- BlitzMOVIE
http://www.harrimansoftware.com/BlitzMovie.htm
-BlitzAVI
http://www.studiox64.com/blitzavi.php


To save the image...
- You can use Blitz3D's own function SaveBuffer()
- or for formats other than BMP, try the FreeImage library:
http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=snarty09252003024804&comments=no
http://www.blitzbasic.com/Community/posts.php?topic=48558

For every application I can think of, PNG is a much better format to use than BMP, since it uses a lossless form of compression and is just as well supported in Blitz and elsewhere. You can save PNG files with the FreeImage library.

[EDIT] Pardon redundancies-- JFK and I wrote our replies at the same time. :)


jfk EO-11110(Posted 2005) [#4]
I'm afraid BLitzMovie cannot play a specific frame. It can only pause a movie. Also Version 2.0 seems to be not fully stabile.
Coppercircle is curretnly developing a solution for the described needs, but since he's busy with other stuff, it's not sure when it will be available.


Chevron(Posted 2005) [#5]
Thanks alot JFK. AVIsynth will do the trick, very nice peice of software.


John Blackledge(Posted 2005) [#6]
BlitzAvi is good, except for the stupid 80 character filename limit for the generated avi.


Yan(Posted 2005) [#7]
Blimey, you need to be able to use filenames that are longer than this sentence?


John Blackledge(Posted 2005) [#8]
Filenames including filepaths, sweetheart, often exceed 80 bytes. We're in the long filename generation now.


Barliesque(Posted 2005) [#9]
LOL


jfk EO-11110(Posted 2005) [#10]
BlitzAviDLL doesn't need a path, you can use a filename only, so it will save the avi in the current folder. BTW I didn't even know it has that limit. Never had any problems.


Doggie(Posted 2005) [#11]
Thank you dear...;)


Barliesque(Posted 2005) [#12]
Here's another utility you might want to check out:
http://www.codersworkshop.com/viewshowcase.php?id=56

"Avi4Bmp is a tool to convert an AVI, an MPG or a GIF to one large PNG (or BMP) 32bit file with all the frames in rows and columns. Perfect for BlitzBasic© LoadAnimImage()!"


John Blackledge(Posted 2005) [#13]
Yes, it does have that limit - there's a comment tucked away in the code where the author says he can't be bothered changing it, and I don't think it's possibly to hack it cause the dll is looking for an absolute location in the memory block.

The pain of this is that (as jfk says) you have to set the current dir to where you want the avi be built, then while recording make sure that no other of your processes tries to access what _was_ the current dir before.


Yan(Posted 2005) [#14]
Filenames including filepaths, sweetheart, often exceed 80 bytes. We're in the long filename generation now.

[pedantic mode]
Ah...You should have said Filepath if that's what you meant...;op
[/pedantic mode]

/me hides behind the cute fluffy kitten.


John Blackledge(Posted 2005) [#15]
[condescending mode]
Sorry for calling you sweetheart. It had been one of those days.
[/condescending mode]