Hard Light Productions Forums
Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: RandomTiger on August 15, 2002, 09:33:28 am
-
This is a bit premature but I have to tell you guys. I have managed to get a subsitute movie playing as an intro. Currently its a mpg but it should work with anything a user has a codec for, I've tryed it with a basic avi. In theory it should work for divx as well.
Just to make it clear to anyone who doesnt know what codecs are, mve files cannot be played with it.
I have to put scaling support in and give the user the ability to skip. My bigest problem is that it initiates a new window and minimises the rest of FS2 until its done. Not sure how to fix that one, will just have to work on it.
Even if I get that all working I will need some help to intergrate it into fs2_open because I had to remove and add some lib files which people might be conserned about.
-
:eek: :eek: :eek: :eek: :eek: :eek: :eek:
-
:eek2:
-
Originally posted by RandomTiger
This is a bit premature but I have to tell you guys. I have managed to get a subsitute movie playing as an intro. Currently its a mpg but it should work with anything a user has a codec for, I've tryed it with a basic avi. In theory it should work for divx as well.
Just to make it clear to anyone who doesnt know what codecs are, mve files cannot be played with it.
I have to put scaling support in and give the user the ability to skip. My bigest problem is that it initiates a new window and minimises the rest of FS2 until its done. Not sure how to fix that one, will just have to work on it.
Even if I get that all working I will need some help to intergrate it into fs2_open because I had to remove and add some lib files which people might be conserned about.
:shaking:
!!!!!!!!!!!!!!!KAZAN!!!!!!!!!!!!!!!!
This is something u should drop kazans way. it might be of some use.
-
Like I say, its not finished yet. Could be a fair bit of work to do still. Dont worry, when its done, i'll make sure everyone knows about it.
-
You the man. :yes: :eek2: :D
-
Let's have a meeting of the minds.
Need to know what you removed, etc, and what you used to play them.
-
umm even i can say COOOOOOOL
-
;7:eek::yes::eek2::yes:
-
Progress report:
Got user skipping in.
But still got trouble with the scaling and switching.
Got some ideas but might take some time to try and if they dont work out I might be a bit stuck.
Also I might be looking for testers soon. Need people with different OS's (mainly 98) and different graphics cards.
-
WOW :eek: :eek2: Well now, all we need is to patch this thing up and get some people who can actually make movies!! Yay! And of course, we can totally CRUSH the stupid movies that Interplay made. I mean, they didn't even follow the correct information provided in the games. haha I wonder if there's a simple way for all of us to make our own high-quality movies. lolz :rolleyes:
-
OK, calm down there. I have issues to resolve.
And there could be many intergration problems and unforseen bugs.
The mix of DX5 and 8 is a bit of a worry.
But this is clearly the best way to try because it works with multiple codecs and not just one.
Anyone who wants to help me get this done should send me an e-mail (with OS and Graphics card and memory details) and offer to test it for me.
-
testers eh
;7 ;7
-
What would be involved in testing?
-
Not much, say your firstborn computer?:eek:
Seriously all I have to say is YES! :D :D :D
Finally, now we can make intros to all the mods the way it should be! (Trembling with .... Antici...... pation!)
"and so it begins"...
-
I'm guessing you implemented DirectShow?
-
Yep, looks like the easiest way to do it.
EDIT: Has anyone else tryed it that way before?
Doh, divx works but wont go fullscreen!
-
To counter the opening in another window problem, it should be possible to bind the video window to the Freespace window.
-
How do you 'bind'?
Would you like to see a copy of the code?
-
Using directshow, eh?
Yes, lets see the code, we'll probably have to put some conditionals in there to preserve the (currently stalled) linux build.
Post the code, then lets go ahead and get it into CVS.
-
Originally posted by Inquisitor
we'll probably have to put some conditionals in there to preserve the (currently stalled) linux build.
Well yes, thats easy enough
Originally posted by Inquisitor
then lets go ahead and get it into CVS.
I thought I might try and get it fully working first.
Also its not coded into fs2_open as such its in my own source code project . So I'd need to transfer it across.
But first I need to defrag my harddisc. Its 20% fragmented and its slowing everything down. Does anyone know of a good defragger for XP? I tryed to install Norton but all the scarey messages put me off.
-
Maybe post a copy of your code to this thread?
EDIT:
On binding to another window:
The trick to it is to set the new window you create to be a child window of the FS2 window.
Assume pVW is a pointer to the video window and hWnd is the window handle of the main FS2 window in the below example:
// Set video windows owner (i.e. who is the parent window?)
pVW->put_Owner((OAHWND)hWnd);
// Get the size of the Parent window
RECT vwrect;
GetClientRect(hWnd, &vwrect);
// Set the child to this exact position
// This appears to be done relative to the parent
pVW->SetWindowPosition(0,0, vwrect.right, vwrect.bottom);
This code should work well since the FS2_window doesn't need to dynamically resize itself and such.
EDIT 2:
And a final note, I made a very simple app a while ago with directshow and it plays avi's encoded with DivX perfectly provided you have the codec installed. Just add in some error checking in building the filter graph and such to avoid bad crashes.
-
Cool, that looks quite promising. I'll give it a shot and then post the code.
How 'bad' is a 'bad crash'?
-
Originally posted by ##UnknownPlayer##
Assume pVW is a pointer to the video window and hWnd is the window handle of the main FS2 window in the below example:
// Set video windows owner (i.e. who is the parent window?)
pVW->put_Owner((OAHWND)hWnd);
[/B]
That was already there
Originally posted by ##UnknownPlayer##
// Get the size of the Parent window
RECT vwrect;
GetClientRect(hWnd, &vwrect);
// Set the child to this exact position
// This appears to be done relative to the parent
pVW->SetWindowPosition(0,0, vwrect.right, vwrect.bottom);
[/B]
That didnt seem to have any effect
OK, here comes the code (sorry about the mess)
#include
#include
#include "osapi.h"
#include "dx8show.h"
//
// Constants
//
#define KEYBOARD_SAMPLE_FREQ 1000 // Sample user input on an interval
//
// Globals
//
static IGraphBuilder *pGB = NULL;
static IMediaControl *pMC = NULL;
static IVideoWindow *pVW = NULL;
static IMediaEvent *pME = NULL;
static BOOL g_bContinue = TRUE;
static BOOL g_bUserInterruptedPlayback = FALSE;
//
// Function prototypes
//
static HRESULT PlayMedia(LPTSTR movie_filename);
static HRESULT GetInterfaces(void);
static HRESULT SetFullscreen(void);
static void CleanupInterfaces(void);
static void Msg(TCHAR *szFormat, ...);
//
// Helper Macros (Jump-If-Failed, Log-If-Failed)
//
#define RELEASE(i) {if (i) i->Release(); i = NULL;}
#define JIF(x) if (FAILED(hr=(x))) \
{Msg(TEXT("FAILED(hr=0x%x) in ") TEXT(#x) TEXT("\n"), hr); goto CLEANUP;}
#define LIF(x) if (FAILED(hr=(x))) \
{Msg(TEXT("FAILED(hr=0x%x) in ") TEXT(#x) TEXT("\n"), hr); return hr;}
bool dx8show_stop_cutscene()
{
pMC->Stop();
return true;
}
bool dx8show_play_cutscene(char *szMovie)
{
HRESULT hr;
// Initialize COM
if (FAILED(hr = CoInitialize(NULL)))
{
return false;
}
// Get DirectShow interfaces
if (FAILED(hr = GetInterfaces()))
{
CoUninitialize();
return false;
}
pVW->put_Owner((OAHWND) os_get_window());
// Play the movie / cutscene
hr = PlayMedia(szMovie);
// If the user interrupted playback and there was no other error,
bool result = true;
if ((hr == S_OK) && g_bUserInterruptedPlayback)
{
result = false;
}
pVW->put_Owner(NULL);
// Release DirectShow interfaces
CleanupInterfaces();
CoUninitialize();
return result;
}
HRESULT GetInterfaces(void)
{
HRESULT hr = S_OK;
// Instantiate filter graph interface
JIF(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void **)&pGB));
// Get interfaces to control playback & screensize
JIF(pGB->QueryInterface(IID_IMediaControl, (void **)&pMC));
JIF(pGB->QueryInterface(IID_IVideoWindow, (void **)&pVW));
// Get interface to allow the app to wait for completion of playback
JIF(pGB->QueryInterface(IID_IMediaEventEx, (void **)&pME));
return S_OK;
// In case of failure, the helper macro jumps here
CLEANUP:
CleanupInterfaces();
return(hr);
}
void CleanupInterfaces(void)
{
// Release the DirectShow interfaces
RELEASE(pGB);
RELEASE(pMC);
RELEASE(pVW);
RELEASE(pME);
}
HRESULT PlayMedia(LPTSTR movie_filename)
{
HRESULT hr = S_OK;
WCHAR wFileName[MAX_PATH];
BOOL bSleep=TRUE;
#ifndef UNICODE
MultiByteToWideChar(CP_ACP, 0, movie_filename, -1, wFileName, MAX_PATH);
#else
lstrcpy(wFile, szFile);
#endif
// Allow DirectShow to create the FilterGraph for this media file
hr = pGB->RenderFile(wFileName, NULL);
if (FAILED(hr)) {
Msg(TEXT("Failed(0x%08lx) in RenderFile(%s)!\r\n"), hr, movie_filename);
return hr;
}
// Set the message drain of the video window to point to our hidden
// application window. This allows keyboard input to be transferred
// to our main window for processing.
//
// If this is an audio-only or MIDI file, then put_MessageDrain will fail.
//
hr = pVW->put_MessageDrain((OAHWND) os_get_window());
if (FAILED(hr))
{
Msg(TEXT("Failed(0x%08lx) to set message drain for %s.\r\n\r\n"
"This sample is designed to play videos, but the file selected "
"has no video component."), hr, movie_filename);
return hr;
}
// Set fullscreen
hr = SetFullscreen();
MSG msg;
/*
while(PeekMessage(&msg, (HWND) os_get_window(), 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
*/
if (FAILED(hr)) {
Msg(TEXT("Failed(%08lx) to set fullscreen!\r\n"), hr);
return hr;
}
// Display first frame of the movie
hr = pMC->Pause();
if (FAILED(hr)) {
Msg(TEXT("Failed(%08lx) in Pause()!\r\n"), hr);
return hr;
}
// Start playback
hr = pMC->Run();
if (FAILED(hr)) {
Msg(TEXT("Failed(%08lx) in Run()!\r\n"), hr);
return hr;
}
// Update state variables
g_bContinue = TRUE;
// Enter a loop of checking for events and sampling keyboard input
while (g_bContinue)
{
LONGLONG pos=0;
long lEventCode, lParam1, lParam2;
// Reset sleep flag
bSleep = TRUE;
// Has there been a media event? Look for end of stream condition.
if(E_ABORT != pME->GetEvent(&lEventCode, &lParam1, &lParam2, 0))
{
// Free the media event resources.
hr = pME->FreeEventParams(lEventCode, lParam1, lParam2);
if (FAILED(hr))
{
Msg(TEXT("Failed(%08lx) to free event params (%s)!\r\n"),
hr, movie_filename);
}
// Is this the end of the movie?
if (lEventCode == EC_COMPLETE)
{
g_bContinue = FALSE;
bSleep = FALSE;
}
}
// Give system threads time to run (and don't sample user input madly)
if (bSleep)
{
Sleep(KEYBOARD_SAMPLE_FREQ);
}
// Quits movie if escape, space or return is pressed
while(PeekMessage(&msg, (HWND) os_get_window(), 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
if(msg.message != WM_KEYDOWN)
{
continue;
}
switch(msg.wParam )
{
case VK_ESCAPE:
case VK_SPACE:
case VK_RETURN:
{
g_bUserInterruptedPlayback = TRUE;
dx8show_stop_cutscene();
return S_OK;
}
}
}
}
return hr;
}
HRESULT SetFullscreen(void)
{
HRESULT hr=S_OK;
LONG lMode;
static HWND hDrain=0;
if (!pVW)
return S_FALSE;
// Read current state
LIF(pVW->get_FullScreenMode(&lMode));
if (lMode == OAFALSE)
{
// Save current message drain
LIF(pVW->get_MessageDrain((OAHWND *) &hDrain));
// Set message drain to application main window
LIF(pVW->put_MessageDrain((OAHWND) os_get_window()));
// Switch to full-screen mode
lMode = OATRUE;
LIF(pVW->put_FullScreenMode(lMode));
}
return hr;
}
void Msg(TCHAR *szFormat, ...)
{
TCHAR szBuffer[512]; // Large buffer for very long filenames (like with HTTP)
va_list pArgs;
va_start(pArgs, szFormat);
vsprintf(szBuffer, szFormat, pArgs);
va_end(pArgs);
// This sample uses a simple message box to convey warning and error
// messages. You may want to display a debug string or suppress messages
// altogether, depending on your application.
// MessageBox(NULL, szBuffer, "PlayCutscene Error", MB_OK);
}
-
You should perhaps use GetClientRect in place of the Fullscreen functions to make fullscreen work (because it'll also then size down to a window). This stuff will only have an effect if you can grab the window handle of the Freespace window (which Im not entirely sure if it's totally global or not since FS2 = multithreaded)
-
Uknown: If I remove the fullscreen code it simply doesnt go fullscreen at all.
I just tryed plugging the above code into a D3D8 sample.
When the movie was started from the app windowed the movie fills the screen. When the movie was started from the app in fullscreen the movie did not fill the screen but it didnt do any crazy switching either though.
Any thoughts?
-
Do you think you could put this into the CVS with a specialized build option so I could have a play around with it?
As far as I know it should work with that method since I've got a demo app which does exactly that.
-
OK, I think thats an idea since I've run out of ideas to fix my problems. Its got something to do with the type of window.
I will probably need someone to sort out the make file for me.
-
I've just had a big breakthough, its not perfect now but acceptable. Still a bit of a switching problem but everything else works. Turns out I had to deactivate direct3D to allow it to play properly.
What I need now is:
1. fs2_open admin to get me write access to cvs again.
Apparently I dont have it any more!
2. Could my testers please check their e-mail.
3. Someone from the modding community or any developers to talk to me about how we are going to make the new video code work for the modders.
-
Ahh, lemme check, somehow the writers file is getting over wrote :)
-
Thanks Inquisitor but I was just being stupid thats all.
OK, I have committed my changes. To activate my changes use the new tag '-dshowvid'. This will allow FS2 to pick up videos of the (exact including mve extension) same name as on the CD but in your root freespace 2 dir. It will play MPG, AVI and DIVX and in theory anything else that you have a codec for (ie anything that can play through media player).
It cannot play mve files.
The catch? It has to switch out to video window and back in which is a bit messy. So if you are a coder take a look, perhaps you can fix it!
I dont understand make files so thats probably broken, sorry.
Anyone have any problems feel free to contact me.
-
nice code
too bad it's completely useless for unix
-
That's what the defines are for, till we get someone to pony up for the divx player on Unix.
Unix has other problems first though ;)
-
like fs2_open linux working :P
-
Yup :)
-
I could really do with some testers, people. See MOD forum for full details.
-
what divx player for linux? I just saw a B5 ACTA -Divx in linux
mplayer is name of the game :D
-
xine is better than mplayer
-
Goody Good!!!!
Put it in FS2 OPEN!!!!!
It's the best way, you wouldn't have to be tied to a damned codec!!!!
And, if linux release has problems, then it will use another version or no video at all!!!!
For Windows there can be no other way...
Finally i will bring some DVD quality movies on FS2...
Sorry for the half flaming, but if Windows Media can be used, we will have superior quality with smaller size...
Could be a good way even for in-game audio...
Real CD quality a 192kbs...
-
WM_ACTIVATEAPP, WM_ACTIVATEAPP, WM_ACTIVATEAPP, messing with my code!
-
RT could you make it so ANI's can be made mappable to FS2 Ships this might be usefull for the Shaddow ships in TBP and open up a whole new way to make cool textures
-
sorry to bump that, but I wanted to know if the ... her... your code could read an avi from a vp file?
-
Fozzy. All high level graphical stuff like that is best done after the DX8 upgrade. I havent looked at the put it should be possible. And if its for making shadow ships then I will definately have a look, but after the DX8 upgrade.
Venom2506. I dont think it will work like that at the moment (not sure). But it could I imagine. Why would you need it to? To keep everything in the same vp file? Might be a bit of a pause to unload a big AVI from a file though.
-
Originally posted by RandomTiger
Fozzy. All high level graphical stuff like that is best done after the DX8 upgrade. I havent looked at the put it should be possible. And if its for making shadow ships then I will definately have a look, but after the DX8 upgrade.
Venom2506. I dont think it will work like that at the moment (not sure). But it could I imagine. Why would you need it to? To keep everything in the same vp file? Might be a bit of a pause to unload a big AVI from a file though.
also, people would tend less to look at the cutscenes before having actually played the campaign :p. o=f course, there's people that will open the vp etc, but when you see the divx there, in the explorer, well... you just double-click :p
-
One solution would be to give the movie a different file type.
I imagine (90% sure) my video code will pickup the movie type from data inside and not the external extension.
So obviously people would be able to rename it back but it might stop some people.
Although you of course have a strong point Im not willing at this time to spend time on a job like this. Its a waste of coding time on a problem thats really about people being weak willed. If they to spoil it for themselves fine.
I think with a bit of creative thought a non coding solution will present itself.
Im sorry I cant do everything everbody wants. Im trying to get through the big stuff at the moment.
-
np, I was just wondering if it was possible.
-
I thought the main purpose was to get the system to work reliably first? Most of us are waiting with baited breath for the op to make our interpretations.
-
as I posted above, it was just a question. I guess I'm allowed to ask questions right? :rolleyes:
plus I've said why already.
-
Heres the current state of things. Movie code works on most machines. Movies can be setup to play using Fred (between missions). The only problem we have is the end movie (if you want one, I imagine you will).
karajorma:
Okay I`ve playtested the last mission as much as I could and I think I`ve found the conditions that need to be present to trigger the final two movies.
1) The end-campaign SEXP must be present in the mission. This SEXP takes no arguements. In FRED 2's help window the SEXP is listed as follows
end-campaign
ends the buildin campaign. Should only be used by the main FreeSpace campaign
2) The filename of the campaign MUST be FreeSpace2.fc2 Even FreeSpace2a.fc2 didn`t work.
3) The filename of the mission is irrelavent.
That's as much as I`ve got so far. Obviously the campaign needing to be the main Freespace 2 campaign is the first thing that has to go. The fact that the end movie takes precidence over the debriefing probably should go too. At the moment there is no way to have a briefing and an end movie. Having both would be nice (but perhaps too hard to do).