Page 1 of 1

Creatiing "VIDEOs" in GE

PostPosted: Thu Aug 21, 2008 9:30 am
by feral
the following demo shows how to create Video using GE.
syncmov.jpg
screengrab

syncmov1.zip
ged and data
(2.37 MiB) Downloaded 1053 times

I will post a full tutorial in a few days.(sorry have to work away for a couple of days)

In the mean time please download and enjoy :D

use the up/down cursor keys to enlarge or shrink picture ( you will need to keep tapping them)

NOTE: if you do not need to enlarge/shrink your video, then this part can be done away with and the whole thing will run much faster.. it is useful tho for saving disk/memory space as you can bring your video in half size and double it on screen.

NOTE: the video I used was the first one I found on the net and is substandard ( obviously taken with a cellphone)
the method used here should display your own videos at the same resolution as your originals ( this demo video is simply just not the best example)

NOTE: the random black bits on the movie are caused by GE thinking that the top left pixel of each frame represents a transparent color.. this can be easy fixed and will be in my tutorial..

this demo also illustrates how to synchronize the audio with the video.. if the frame rate drops... this method automatically skips frames to keep the video in sync with the audio. The method used here (in this demo) is a bit rough but I will polish it up when I do the tutorial.

to test how well the sound sync is, simply zoom in real close until the frames per second ( on screen) start to drop below 30
( which is what the video is running at) and you will notice that the sound still stays in sync.

To really test it, set your Game Config frame rate to 20 or even 10 frames per second.. and it should still work.

My preffered method of synchronization was to use milliseconds... but there does not seem to be an easy way to do this with GE ? can anyone tell me how to read in milliseconds ????

NOTE: the "pics" which make up this video are in JPEG format.. they have been compressed this way ONLY to be able to save space to upload the demo. In your game you will be best to save the pics TO bitmaps. ( export the movie file as bitmaps)

GE will convert them all to bitmaps anyway, when you export your game as an EXE.. If, however, you want to show demos with GED files here on th board, then you will probably have to compress the graphics to keep within the 10mb upload limit. Just remember that you will lose quality that you do not have to, if you leave them that way before exporting.

I will explain more of this in the tutorial..

enjoy :D
feral

PS :there SHOULD BE SOUND !! if not...the sound might be a little low in volume ( due to the poor quality of the demo video), so...please turn it UP :lol:

Re: Creatiing "VIDEOs" in GE

PostPosted: Thu Aug 21, 2008 9:57 am
by feral
BTW: This technique is not just for "cut-scenes" or clever intro screens

the "video" is just like any other actor.. and can be placed like any other actor...

so.... imagine...

a real video of a sandstorm as a backdrop to your desert warfare game,

or, a video of a real soccer crowd as a back drop to your soccer game.

or, even videos of real cars in your racing game..

the possibilities :shock:

:lol: feral :lol:

Re: Creatiing "VIDEOs" in GE

PostPosted: Thu Aug 21, 2008 12:54 pm
by DarkParadox
Nice job, but, one question.....


How did you extract the sound?!?!

Re: Creatiing "VIDEOs" in GE

PostPosted: Thu Aug 21, 2008 1:11 pm
by feral
HOW THE HECK DID YOU EXTRACT THE SOUND?!?!?!?!


Almost any Video Editor program will allow you to save the sound track as a separate wav file....and,...it will also (usually) allow you to save the video as a series of bitmaps..

for this sample I used VirtualDub, ( not a endorsement or advertisement) it is simply the first of many freeware apps I found..

more to come in the tutorial

Re: Creatiing "VIDEOs" in GE

PostPosted: Thu Aug 21, 2008 3:31 pm
by pyrometal
lol, very nice feral! I see you're still using my font too! lol

Re: Creatiing "VIDEOs" in GE

PostPosted: Thu Aug 21, 2008 9:12 pm
by DarkParadox
ive been looking for a while, but i cant find one that supports .FLV can you help me?!?!?!

Re: Creatiing "VIDEOs" in GE

PostPosted: Thu Aug 21, 2008 11:25 pm
by feral
pyrometal wrote:lol, very nice feral! I see you're still using my font too! lol


sorry pyro, I thought I read somewhere it was ok to use ? if not let me know.. :(

It is a very nice font and much easier then trying to upload a truetype everytime ..

Re: Creatiing "VIDEOs" in GE

PostPosted: Thu Aug 21, 2008 11:35 pm
by feral
diormeh wrote:ive been looking for a while, but i cant find one that supports .FLV can you help me?!?!?!


Ok, without getting into the complexities of what a frame server is etc etc.. you will need to find a "service" (ie a website) that will convert the video on the fly and provide you with a converted or downloadable version

simply google for "flv download" ( or for other "served" videos like youtube etc ) search for "download youtube" you will find many sites offering conversion to downloadable versions

usually then you paste the URL of the wanted "video" into the service, it downloads the to itself, and converts it, then provides you with a link to the needed downloadable version.

keep in mind that if the video is non-downloadable in the first place, it is often because it is copyrighted. so please check 8)

Also keep in mind that server shared videos are often of very low quality in order for them to be served this way..

if you still have problems pm me :)

Re: Creatiing "VIDEOs" in GE

PostPosted: Fri Aug 22, 2008 3:01 am
by pyrometal
Yes, of course you can use my font! Your the one whom asked me to use it before as well, lol.

Re: Creatiing "VIDEOs" in GE

PostPosted: Tue Aug 26, 2008 11:41 pm
by feral
TUTORIAL PART 1 - The video

PREFACE: I should point out here that most videos you find on the net are copyrighted - even if they say they are not. Videos are automatically copyrighted as soon as they are taken, and more often then not that copyright has been transferred to the owner of the website or other persons.


Now that that is out of the way.... thisis a very brief and simplified version of how to get video into GE, if you are really interested in this concept you should read up on video formats and compression, how and what streaming video is, and what a frame server is ( for more complex videos). In general tho, for our uses the following simple method should work.

first getting the video..

your best bet is to try to get an original AVI version or at least a downloadable version of the vid you want, becuase streaming videos are often heavily compressesed and as such will suffer in quality.

if you cannot get any version other then a streaming version you will need to use a "service" which captures the stream for you.. you can either use an online webservice, or there are downloadable applications that can do it for you, ....google for capture streaming video, or if you know where you are capturing from eg: youtube, then google for "capture youtube". or "save youtube";....... if you get stuck, pm me

next your best method of saving the video should be as a AVI - preferably a simple version not divx or such, but if you have to save it as a mpeg, or divx or flv etc etc you will then need to either

A: find a program that will convert your format to bitmaps, or
B: convert your video format to video AVI ( or some other acceptable format.)

For converting to bitmaps, usually you just need to google for your format plus "2bmp" eg: flv2bmp or divx2bmp or mpg2bmp etc etc
but the easiest solution is usually to convert the original to AVI because there are a LOT of AVI2BMP apps out there.

OK, so by now you should have a series of sequentially numbered bitmaps
(note: other formats are acceptable eg: sequentially numbered PNG files, or Jpeg files, but this will make no difference to the end size of your executable, because GE will convert them all to BMPs anyway. smaller files are only worth using if you plan on posting your GED files)

now with the sequenced Bitmaps, simply create a new actor, with multiple frames and direct it to load your bitmap sequence.

immediately ( you should see a "movie" ) you will notice 2 things

1. there may be unwanted "artifacts" or missing pixels in your movie (I will cover that shortly) or
2. your movie will run too fast or slow.. to fix this you must change the frame rate of the actor to match the original frame rate of the movie..
If the movie runs at a high frame rate you may have to change the frame rate of your entire game to one that is as high or higher then the original movie.

THE MISSING PIXELS...!! arrgg
One of the problems with using GE for movies, is that it assumes that every frame is like a normal sprite, and it will select the top left corner pixel of each frame and make all other pixels of the same color (in the same frame) transparent..

if the top left hand corner of the movies is nearly always the same or similar color, you can simply make a backdrop of the same ( or similar color) and place it behind the movie, this way any missing ( transparent) pixels will show the backdrop

for example: in my demo movie it showed the sky, so the transparent color was always some shade of light blue. if I were to place a light blue backdrop behind the video, all the missing pixels would appear light blue instead of black ( you can also do the same thing by changing the background color of the game..

however, if the top left pixels changes a lot in color, for example in scene changes or if action is occurring in that area of the vid.then you will need to modify every frame by hand and change that pixel to the same color in every frame ( and to a color that does not get used in your movie)

or, if there is enough interest I will write an application that will load up everyframe and add a single color 1 pixel border around each frame - using a method similar to my sprite designer..GE will then assume that is the transparent color and leave the rest of your video alone...

if enough people are interested ( please PM me) otherwise you may be able to write a script in photoshop or the gimp or some other tool to do the same thing

OK that should cover the basics of the video capture.. if not, or if i missed, something let me know..

In the next tutorial I will explain how to grab the sound, and how to synchronize it with your video..

and then if needed i will explain why you should use a canvas to display it ( saves space) and how to use the canvas - unless that is already obvious from previous posts..

oh and before you ask (and this is not an advert , simply one of the first tools i found, there are plenty more.. and you may already have some on your PC ( windows movie maker for example))

- I used
virtual dub
if you get errors you may need to also download the latest version of ffmpeg
http://ffdshow.faireal.net/mirror/ffmpeg/

and use virtual dub to export to bmps (file->export->image sequence)
if you need the audio ( file->save wav)

have fun :D
feral

PS: i typed this in a bit of a hurry, so if there are any glaring spelling mistakes, or grammer issues, or I wrote something wrong :? please PM me and i will fix it..

Re: Creatiing "VIDEOs" in GE

PostPosted: Wed Aug 27, 2008 12:22 am
by feral
TUTORIAL PART 2 - Sound

In the previous tutorial i explained briefly how to use virtual dub to extract the "wav" file from the movie.. most movie applications will allow you to do this, so i won't go into it in anymore depth, except to say if you have problems PM me and i will try to help.

alternatively, if you get really stuck, most movie players will allow you to record the sound simply using windows sound reorder :shock: so you can always try that.

So by now you should have a wav file of your movie, ( you can convert it to ogg format or whatever you find plays best in GE.)

The important thing to know is HOW LONG does it play for in seconds.

Synchronizing sound and video.

In general ( and this is not always the case, i have seen some games where the sound skips horribly), but in general the sound should play OK, without skipping, it is always the video that usually gets out of sync.

unfortunately if the sound gets out of sync there is NOTHING we can do about it in GE, GE simply does not have the functionality to track sound. BUT, as sound usually gets out of sync because the processor is overloaded with the graphic content ( showing the movie) the easiest way to fix most sound problems is to "skip frames" when needed .

ie: if the processor cannot keep up with the drawing of the frames , you need to be able to allow the processor to only draw as many frames per second as it is capable of doing without interrupting the sound. to do this it has to drop (skip) frames.

the method i used is not the best, so if anyone has a better idea lease advise - ideally you really need to be able to track the "real time" milliseconds as the movie shows ( i think you might be able to do this with timers ? but as i have never used them I don't know.. and the GE getime function only gets seconds..

So, my method uses the current "REAL_FPS" reading.. this reading tells you how many REAL frames per second are actually happening as opposed to what you want to happen..

for example if you want your game to run at 30 frames per second but it is a very complex game, it may only run at 15 frames per second.. or may run anywhere between 10 frames and 30 frames per second depending on what is happening at the time..

so how do we use this... ?

well, instead of letting our animation try to run at the specified frame rate ( usually 30 frames per second for video) we tell it to jump frames when needed.

to do this we first STOP the video animation.. this way it runs when we tell it to.

then we divide the required number of frames by the actual REAL frames per second to get the next frame to draw to screen
by using this formula

animpos=animpos+30/real_fps;

where 30 = the required number of frames

what this does is if the video is running normally and the game rate is set 30 FPS then the animation will skiup to the next frame each redraw ( like normal)

eg: animpos=animpos+ 30 (required frames) /30 (actual game frames)

which translates to

animpos-animpos+1 (30/30)

so on every draw we go to the next frame and all is good and normal...BUT, if the frame rate is slower it will automatically skip frames to keep up

eg; at a REAL frame rate of 10 the animations will skip

eg: animpos=animpos+30/10
OR
animpos=animpos+3

so it now runs at 10 frames per second but skips every second and third frame, so still keeps up with the sound..

if the REAL fps suddenly changes, or is variable.. it still does its best to keep up with the current rate

eg: animpos=animpos+30/5 real FPS = animpos=animpos+6 (skips 5 frames )

or animpos=animpos+30/20 real FPS = animpos=animpos+1.5 (skips 1.5 frames which evens out automatically so don't worry :D


and that is it ? i think... let me know if it does not make sense or if there are any glaring errors ( please PM me to keep this thread short, and i will edit existing posts)

oh: forgot to say... start your sound at animpos=0 - see my example posted above for more code.. as my example also shows how to "LOOP" the video.. if your sound for some reason takes one or two frames to start ( it shouldn't , but if it does, you can simply code in a delay before starting the movie..note: you will want to test any "delays" as an executable AND get others to beta test any delays, as it just may be your PC.

Re: Creatiing "VIDEOs" in GE

PostPosted: Wed Aug 27, 2008 12:26 am
by feral
TUTORIAL PART 3 - Video size issues

ONE LAST NOTE IF YOU ARE STILL READING: BEWARE OF USING VIDEOS THEY WILL MAKE YOUR EXE HUGE !

this is why it might be best to use a canvas to display your original videos at double size, and or bigger, to save space.. once again see my sample demo, where i can enlarge the video to full screen ( or larger)

GE cannot "spool videos" of the hard drive using this method, so all video content will be contained in the EXE and will be loaded into and take up PC memory space...

you could use this method and the methods described in other posts to load the video as a "level" ... but i am not too sure how this works so you will need to ask advice from coders who do levels..

if the canvas redraw/enlarge method does not make sense from the demo , please pm me....and i will do a better tutorial on that aspect.

cheers
feral

Re: Creatiing "VIDEOs" in GE

PostPosted: Wed Aug 27, 2008 6:06 am
by summer_goth
Awesome work feral! :D Thanks very much, this is very informative.