Game Development Community

guiAviBitmapCtrl Windows ONLY fix

by Richard O · in Torque Game Engine · 07/03/2002 (6:43 pm) · 78 replies

A little disclaimer before I get into the code. This is a quick and dirty fix to the guiAviBitmapCtrl module to get it to play AVI's under Windows only (i.e. it will not compile/work on Linux or Mac). All of the below code changes are based upon the current HEAD version:

[b]In engine\gui\guiAviBitmapCtrl.h[/b]

Change the below line (11) from:

	#if !ENABLE_AVI_GUI || !ENABLE_MPG_GUI

to

	#if !ENABLE_AVI_GUI && !ENABLE_MPG_GUI
[b]In engine\gui\guiAviBitmapCtrl.cc[/b]

Change the below line (23) from:

	#define  ENABLE_AVI_GUI    0

to

	#define  ENABLE_AVI_GUI    1

Change the below line (46) from:

	#if !ENABLE_AVI_GUI || !ENABLE_MPG_GUI

to

	#if !ENABLE_AVI_GUI && !ENABLE_MPG_GUI

Replace the entire function GuiAviBitmapCtrl::sndOpen() (lines 101-117) with the below code:

bool GuiAviBitmapCtrl::sndOpen()
{
   char               fileBuffer[1024];
   Audio::Description desc;

   // Build the audio description
   desc.mVolume    = 1.0f;
   desc.mIsLooping = false;
   desc.mIs3D      = false;
   desc.mType      = 0;

   // Create the audio source
   dSprintf(fileBuffer, sizeof(fileBuffer), "%s", mWavFilename);
   mWavHandle = alxCreateSource(&desc, fileBuffer, 0);

   return (mWavHandle != NULL_AUDIOHANDLE);
}
In order to test the above changes I created a directory under fps called AVI. I then created the below script (avitest.cs) in that directory. Here is the source code to the script:
// Issue the below command at the console:
   //
   //    exec("fps/AVI/avitest.cs");
   //

   new GuiControlProfile (IntroProfile)
      {
      opaque      = false;
      fillColor   = "0 0 0";
      fillColorHL = "0 0 0";
      fillColorNA = "0 0 0";
      tab         = true;
      canKeyFocus = true;
      };

   // Create the GuiAviBitmapCtrl
   new GuiAviBitmapCtrl(IntroGui)
      {
      profile = "IntroProfile";
      horizSizing = "width";
      vertSizing = "height";
      position = "0 0";
      extent = "640 480";
      minExtent = "8 8";
      visible = "1";
      variable = "";
      helpTag = "0";
      useVariable = "1";
      aviFileName = "fps/AVI/test.avi";
      wavFileName = "fps/AVI/test.wav";
      setFirstResponder = "1";
      letterBox = true;
//      letterBox = false;
      swapRB = true;
      };

   Canvas.pushDialog(IntroGui);
   Canvas.hideCursor();
   IntroGui.play();
   schedule(100, 0, checkIntroDone);

//-----------------------------------------------------------------------------
function checkIntroDone()
{
   if (IntroGui.done)
      {
      Canvas.popDialog(IntroGui);
      Canvas.showCursor();
      IntroGui.delete();
      IntroProfile.delete();
      }
   else
      schedule(100, 0, checkIntroDone);
}
You will need to create a test AVI (test.avi) and WAV (test.wav) file and place them in the fps/AVI directory prior to executing the above script. To test the AVI control, open the console from the main menu and issue the command:

exec("fps/AVI/avitest.cs");

As far as a Linux and Mac solution, it is on my to do list (no estimate of availability at this time). The above coding changes where done to validate that the existing Windows code was functional.

Rich
#41
06/29/2005 (7:50 am)
There is a consolemethod line 81 in guiAviBitmapCtrl.cc called play .
#43
07/11/2006 (10:09 am)
I'm getting a compile error for this

S32 GuiAviBitmapCtrl::fileOpen()
{
S32 rval;
if (!dStrcmp(mAviFilename,""))
return MOVERR_NOVIDEOSTREAM;

rval = AVIFileOpen(&mPFile, mAviFilename, OF_SHARE_DENY_WRITE, 0);
if (rval)
{
fileClose();
return rval;
}

This is the error....any help would be appreciated... thanks.

Error 132 error C2664: 'AVIFileOpenW' : cannot convert parameter 2 from 'StringTableEntry' to 'LPCWSTR' c:\Torque\SDK\SDK\engine\gui\game\guiAviBitmapCtrl.cc 189
#44
07/11/2006 (10:18 am)
I'm getting a compile error for this

S32 GuiAviBitmapCtrl::fileOpen()
{
S32 rval;
if (!dStrcmp(mAviFilename,""))
return MOVERR_NOVIDEOSTREAM;

rval = AVIFileOpen(&mPFile, mAviFilename, OF_SHARE_DENY_WRITE, 0);
if (rval)
{
fileClose();
return rval;
}

This is the error....any help would be appreciated... thanks.

Error 132 error C2664: 'AVIFileOpenW' : cannot convert parameter 2 from 'StringTableEntry' to 'LPCWSTR' c:\Torque\SDK\SDK\engine\gui\game\guiAviBitmapCtrl.cc 189
#45
07/11/2006 (1:41 pm)
It might be worth your time to convert your AVI to Theora rather than working with an older, unsupported resource. Theora is up and working cross-platform.
#46
07/11/2006 (1:45 pm)
Thanks... do you know of a good conversion tool ?
#48
07/12/2006 (5:21 am)
Thanks ..... I downloaded ffmpeg2theora for windows but there really aren't any instructions on how to use it. I placed the .exe in the same folder as my movie and typed.... ffmpeg2theora testclip.avi but it came up as an unrecognized command. Is there something specific I should do ?
#49
07/12/2006 (6:17 am)
Hi Robert,

In Windows, the simple way is to just drag your .AVI or .MPEG videos onto the ffmpeg2theora.exe file. That will begin converting your video with default settings only.

However, more detailed instructions are built into the executable file and give you more control over the output. Since ffmpeg2theora is primarily a command-line tool, you will want to either work with it from a command prompt or by creating batch files to do it for you.

Here are the built in instructions for the program . . .

ffmpeg2theora 0.15

 usage: ffmpeg2theora [options] input

Output options:
	 --output,-o		alternative output
	 --width, -x		scale to given size
	 --height,-y		scale to given size
	 --aspect		define frame aspect ratio: i.e. 4:3 or 16:9
	 --crop[top|bottom|left|right]	crop input before resizing
	 --videoquality,-v	[0 to 10]    encoding quality for video
	 --videobitrate,-V	[45 to 2000] encoding bitrate for video
	 --sharpness,-S  	[0 to 2]     sharpness of images(default 2)
	                 	   { lower values make the video sharper. }
	 --keyint,-K      	[8 to 65536] keyframe interval (default: 64)
	 --audioquality,-a	[-1 to 10]   encoding quality for audio
	 --audiobitrate,-A	[45 to 2000] encoding bitrate for audio
	 --samplerate,-H	set output samplerate in Hz
	 --channels,-c		set number of output sound channels
	 --nosound		disable the sound from input
	 --endtime,-e		end encoding at this time (in sec)
	 --starttime,-s		start encoding at this time (in sec)
	 --v2v-preset,-p	encode file with v2v preset, 
				 right now there is preview and pro,
				 'ffmpeg2theora -p info' for more informations

Input options:
	 --deinterlace 	force deinterlace
				 otherwise only material marked as interlaced 
				 will be deinterlaced
	 --format,-f		specify input format
	 --v4l   /dev/video0	read data from v4l device /dev/video0
	            		you have to specifiy an output file with -o
	 --inputfps [fps]	override input fps
	 --audiostream streamid	by default the last audiostream is selected,
	                 	use this to select another audio stream
	 --sync			Use A/V Sync from input container.
	       		since this does not work with all input format
	       		you have to manualy enable it if you have issues
	       		with A/V sync.

Metadata options:
	 --artist	Name of artist (director)
	 --title	Title
	 --date		Date
	 --location	Location
	 --organization	Name of organization (studio)
	 --copyright	Copyright
	 --license	Licence

Other options:
	 --help,-h		this message

 Examples:
	ffmpeg2theora videoclip.avi (will write output to videoclip.ogg)

	cat something.dv | ffmpeg2theora -f dv -o output.ogg -

	Live streaming from V4L Device:
	 ffmpeg2theora --v4l /dev/video0 --inputfps 15 -x 160 -y 128 -o - \ 
		 | oggfwd iccast2server 8000 password /theora.ogg

	Live encoding from a DV camcorder (needs a fast machine):
	 dvgrab - | ffmpeg2theora -f dv -x 352 -y 288 -o output.ogg -

	Live encoding and streaming to icecast server:
	 dvgrab --format raw - | \
	  ffmpeg2theora -f dv -x 160 -y 128 -o /dev/stdout - | \
	  oggfwd iccast2server 8000 password /theora.ogg

Again, to get the full use out of all of this, you will need to use the Windows command prompt. Click Start, Run, and type CMD to start up the prompt. From there, just navigate to your project folder (using CD commands to get there). Once you're in the directory with ffmpeg2theora and your videos, you can use the instructions listed above.

If you're not into command-line or DOS stuff, you might want to spend a little time learning it, since it can really come in handy. If you need help with any of it, feel free to ask.

Have fun,

Aaron E.
#50
07/12/2006 (6:58 am)
Thanks Aaron.... I'm actually stoked about the command line stuff because I can just call it from in game. I probably missed some setup stuff so I'll take another look and let you know. Thanks for all your help though.
#51
07/12/2006 (7:31 am)
So I created a folder called "TheoraStuff" on my C:\ drive. I extracted the ffmpeg2theora folder into the "TheoraStuff" folder. I then placed testclip.avi into the "TheoraStuff folder as well. I went to my command prompt and navigated to the "TheoraStuff" folder and typed in "C:\ TheoraStuff \ ffmpeg2theora testclip.avi ". I'm getting that it doesn't recognize ffmpeg2theora as a valid program or batch file. Basically, I'm thinking that I haven't set up my directory well or haven't placed something in the right place somewhere. Am I making any sense ? If I can just get ffmpeg2theora to kick off I'll be great.
#52
07/12/2006 (9:02 am)
Hi Robert,

First guess is that it's just a path or command typo. Your command line statement is longer than it needs to be and that provides more opportunities for typos. If you've already navigated to the folder such that your pwd or prompt looks like this . . .

C:\TheoraStuff>

And if ffmpeg2theora.exe is located in that working directory, then you don't need to type any path info in your command statement. Relative pathmaking in DOS means that it automatically looks for external commands and apps within the current directory first, followed by PATH listing locations if it's not found). So if you're in the right place, you can just type . . .

ffmpeg2theora testclip.avi

Speaking of which, ffmpeg2theora is way too easy to misspell (causing errors). So, to save myself some headaches, I just renamed the executable to theora.exe. That made my life much easier. :)

And if you are converting lots of files using the same settings, you might want to type a working command line statement into notepad, duplicate it a bunch of times and just change the file names for your source vids. Once you've got it set up right, save it all as convertall.bat (or something similar). Batch files are the bomb.

:)

Aaron E.
#53
07/12/2006 (10:43 am)
It Worked !!! Thanks so much for the help Aaron.
#54
07/12/2006 (10:54 am)
Glad to help out.
#55
07/14/2006 (7:37 am)
Now I have another issue. When I create an avi with Fraps ffmpeg1theora only uses the audio and seems to have a problem with Fraps encoded avi. Have you had this or similar problems ?
#56
07/14/2006 (7:39 am)
What codec does Fraps use? That is most likely the culprit. It often is with any video wrapper such as AVI/WMV/MOV.
#57
07/14/2006 (8:55 am)
Robert,

Wierd. Fraps records in raw AVI format. I usually compress my videos with virtual Dub before sending them out to ffmpeg2Theora, though.
#58
07/14/2006 (10:09 am)
Funny you say that Aaron, thats what I just did and that worked fine. They both use command line as well, which is great. Now I'm just wondering if how their liscencing works. I mean if I sell a game to someone and want to create an after action review, I would need to give them Fraps and VirtualDub. Any idea how that would work ?
#59
07/14/2006 (10:19 am)
Quote:
Wierd. Fraps records in raw AVI format.

No it doesn't.

Fraps uses it's own custom decoder.

For someone to be able to watch a raw fraps video they must also have fraps installed.

People overcome this obstacle by re-encoding a raw fraps avi recording with a suitable external program. If you can't afford one you can use Windows Movie Maker. It's free and means anyone can watch your video without needing any specialized codecs, default Windows one will do fine.

- Tim
#60
07/14/2006 (10:48 am)
It compresses the images somewhat (which is it's own codec) but is otherwise a raw video file. The Fraps site suggests using VirtualDub to compress them into another format.