Avi Texture!

Blitz3D Forums/Blitz3D Programming/Avi Texture!

Play(Posted 2004) [#1]
Hi!

The simplest way to get animated textures. Just load avi file of any size or length using Load_Movie, then start it by Start_Movie, and use Update_Movie in main loop.

If your avi, wmv (you can use DivX, mpeg4 etc. as well) has for example ressolution of 640x480 and your texture/image/frontbuffer has the ressolution of 256x128 just set XSize and YSize parameter to 256,128 when loading movie.

XSize and YSize are optional parameter - don't fill them if movie has the same ressolution as image/texture buffer - it will work a bit faster.

I think that's all.

Include file:



And example (change "ktech.avi"!)



Have Fun!!!


Play(Posted 2004) [#2]
Oh, one more thing!

If you want to open the same movie file a few times at once, in order to play it simultaneously for example at different ressolutions , don't open the same file! It may cause sever slown down! It's better to have a few copies of the same file and load movies from different ones.

I tested my program with 6 files loaded at one time and it worked smoothly, but when I loaded the same file 6 times the fps dropped down.


Genexi2(Posted 2004) [#3]
Yer using the DrawMovie command...doesnt that cap the FPS of the program itself to the FPS of the video file?


Play(Posted 2004) [#4]
Good question. I'll check it!


Play(Posted 2004) [#5]
Yes, you are right Genexi2.

What a stupid function! :)


Dirk Krause(Posted 2004) [#6]
This is another approach:
http://www.blitzbasic.com/Community/posts.php?topic=29010


jhocking(Posted 2004) [#7]
"doesnt that cap the FPS of the program itself to the FPS of the video file?"
Well I'll be a monkey's uncle. I didn't know that.


Paolo(Posted 2004) [#8]
"doesnt that cap the FPS of the program itself to the FPS of the video file?"

NOT exactly.
When you load a movie, the movie is being played at the background and it only "get into calculation" when you write the DrawMovie() command. So if you have a game that is running at 60fps but your movie is running at 30fps, then just use something like this.

draw=not draw
if draw then DrawMovie(movie)

this way the movie will be drawn once every two frames and it won't affect your fps ... (to make this really correct you will have to use the millisecs() actually)

And the best way to have a movie on a 3D element is by drawing the movie just before the RenderWorld and then copyrect the movie to a texture

cheers!
Paolo.


jhocking(Posted 2004) [#9]
Is the movie incremented every time you call DrawMovie? My impression was that it does not, that if you call DrawMovie again before the movie has gotten to the next frame the command will simply draw the same frame again.


Paolo(Posted 2004) [#10]
I think (not sure now :) when you call DrawMovie, the program will 'wait' until the next movie frame, and that's way the fps drops to the movie's fps ...


jhocking(Posted 2004) [#11]
I'm going to have to run a test, because this line from the command reference has me confused:

the movie is played back at normal speed 'behind the scenes', and DrawMovie simply draws the most recent frame


Barliesque(Posted 2004) [#12]
I'm wondering if this issue has something to do with why BlitzMOVIE was created. Does anyone here know what the advantage is of using BlitzMOVIE over Blitz's own instruction set? ...does it support an Alpha Channel?


Play(Posted 2004) [#13]
Unfortunately BlitzMovie is very slow - copying video to buffer pixel by pixel is not a good method.

Oh, my code can work a bit faster. We don't have to copy backbuffer to image/texture buffer. Just before DrawMovie(blitz one) function put "SetBuffer (TMovieStorage\Buffer)" and delete the line which starts with "CopyRect.."

I didn't check that, but I think that will work.

As far as fps is concerned, yes we can do the timing ourselves, so we call DrawMovie every 1/40, 1/3s. I think it's good solution.


Pax(Posted 2005) [#14]
Sorry for reviving this topic (kinda old now), how would that millisec() function work? (currently video is capped to 30 fps at most)

thank you.


John Blackledge(Posted 2005) [#15]
Yeah nice, but....
Add this line after your text FPS line -

Text 520,40,"AvailVidMem():"+AvailVidMem()

- and you see that we still have the same memory leak problem every time it loops.


Naughty Alien(Posted 2005) [#16]
hehe..yes...I'm trying to solve this past 1 week ... :))


John Blackledge(Posted 2005) [#17]
Naughty Alien, I've been trying to solve this for 6 months, but no use.
If only CloseMovie() would free the memory involved.
But it doesn't, and there isn't any other free command that will work with movies.


Naughty Alien(Posted 2005) [#18]
..its weird since in Blitz3D documentation (example of use) staying line comment
; Remove the movie from memory before closing down
CloseMovie(movie)

but obviously its not true..I hope BRL will fix this issue..


John Blackledge(Posted 2005) [#19]
Well, I have asked them to read one of the other threads concerning this problem. No reply so far.


Pax(Posted 2005) [#20]
John, after adding
Text 520,40,"AvailVidMem():"+AvailVidMem()

Indeed memory was "leaking". Funny enough, after several loops the fps dropped from 20 (I have two video streams running in 3 different entities, which i guess makes it for the slow playback) to 17 when the loop starts again, then speeds up to 20 again. For the memory, it didn't ever got to 0, but stalled at 1864960.

Now regarding my original question, does anyone knows how to use the millisecs command to avoid capping the fps of the whole scene to 20? Not that I'm quite happy with the memory leak, however so far this is just a "quick" prototype test.

Thank you.


Paolo(Posted 2005) [#21]
I'm using this method and it works with no frame-cap
for me:

basically you have to call the DrawMovie command
when you know for sure that the movie is in the next
frame, so if your movie is at 30fps, you call the DrawMovie()
every 33 millisecs, if your movie is at 20, you call it every 50 millis and so on...
	;--- VIDEO  ---------------------
	movies_millis=MilliSecs()-movies_millis
	movies_storemillis=movies_storemillis+movies_millis
	movies_millis=MilliSecs()
	If movies_storemillis>32
	movies_storemillis=0

	DrawMovie( ? ) ;draw movie here
	CopyRect  ? ;copyrect to texture here

	EndIf
	;----------------------------------


[edit]
I forgot to say that the code above works within the
Mark Sibly's render-tween code from the Castle demo...