Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Play (AVI) Video files into RMXP
#1
Play (AVI) Video files into RMXP
3 versions - Scripts By Soundspawn
Jun 19 2005

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


The creator of this script told me, i could post this script everywhere i want whit out credits.

but here it goes.

Play (AVI) Video files into RMXP.
Version 1
By Soundspawn


The Use :
Call this ccommand
Code:
$scene = Scene_Movie.new("CASTLE2",5)


Change this line
Code:
@temp = @wnd.call(0,0,nil,"Scripts").to_s

The (Scripts) for the name of your project).

Installation :
Make a (Scene_Movie) under (Main) and put this inside.

Code:
class Scene_Movie

def initialize(movie,length)
   @movie_name = Dir.getwd()+"\\Movies\\"+movie+".avi"
   @counter = length
end

def main
  
   Graphics.transition
   @wnd = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L')
   @temp = @wnd.call(0,0,nil,"Scripts").to_s
   @movie = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V')
   @movie.call("open \""+@movie_name+"\" alias FILE style 1073741824 parent " + @temp.to_s,0,0,0)
   @movie.call("play FILE",0,0,0)
   loop do
     Graphics.update
     sleep(1)
     Input.update
     if Input.trigger?(Input::B)
       break
     end
     @counter = @counter - 1
     if @counter == 0
       break
     end
   end
   @movie.call("close FILE",0,0,0)
   $scene = Scene_Map.new
   Graphics.freeze
end
end


Instructions
Quote:Copy this into a new section of your game. To play a file, move the avi file into a "movies" subdirectory (yourgame\data, yourgame\graphics, yourgame\movies). Then call "$scene = Scene_Movie.new(filename,length)" where filename is your movies actual filename (minus the .avi) and length is the playtime in seconds.

Example: My games path is "C:\game". I create a folder in "C:\game" called movies. I then move my movie, called "intro.avi" into "C:\game\movies". Now I open my game, paste the above into a new section of the scrîpt editor (ABOVE MAIN), and close the scrîpt editor. Then I make a new event on my map, give it a graphic of a guy, and click to add command. I go to the third page and pick the bottom right one labeled "call scrîpt". Then I type "$scene = Scene_Movie.new("intro",8)" (the 8 because my intro is 7.5 seconds long and I know to round up if I must round). Now I run my game, and whenever I talk to this guy, it plays my movie.


Now not all avi files will work, but I really hope your making your own movies, so it should be no problem to try different codecs. Make your movies 640x480 in resolution. This scrîpt will be buggy as hell if you are running your computer at 640x480, and the editor is probably impossible to work with. If this is the case, increase your resolution to at least 800x600 and not only will it work, but people might believe you when you say you know more than nothing about computers

Anyway, this should be working flawlessly, and my small following will hopefully help me troubleshoot any issues people have, so feel free to post issues here and someone (I pray not always myself) will get back to you.

EDIT: I'm going to list some relavent stuff from the other topic here to answer a few questions before they're asked.

First off, this is not perfect, it cannot play videos while in fullscreen mode, but it can check your screens resolution to make a good guess if you're running fullscreen or not (hence the whole buggy 640x480 resolution thing I mentioned). If you game is running windowed, then your resolution shouldn't be 640x480 (with todays technology it's probably more like 1024x786 or higher, mines @ 1280x1024). When you go into fullscreen mode (alt+enter) your screen resolution changes to 640x480. So if it's about to play a video and the resolution is 640x480 it guesses that you don't actually use 640x480 resolution, you're just in fullscreen mode, so it jumps to windowed mode, plays the video, and re-enters fullscreen mode afterwards. If you were in windowed mode, it just plays the video. I've also noticed that playing the game in windowed mode with a resolution of 640x480 actually won't work right anyway because the games area is 640x480 PLUS the titlebar AND the taskbar... so you'd probably notice if your running 640x480, and you should definately change it to a higher setting anyway.

Second, as I mentioned not all Codecs work. The word "Codec" seems to scare a lot of people around here, so let me explain. A video file has three things (that are relevant to this thread): a video codec, and audio codec, and a file extension. Any extension can have any video/audio codec combinations, the codecs are basically just instructions on how to use the data in the file. "Compression" is used in most codecs, which makes the files more portable. You should find codecs that work well for what you need (usually less filesize means less quality with little workaround room), and stick with it. If you use common codecs, then others can watch your movies too... If you use "Hax0r's leaked Playstation codec" (don't think this is real, but an example) then most people won't have it, so you either need to provide the codec with your game, or somehow get them to a place where they can download/install it. I would just say to use "Windows Media Player 9" for video, and any common MP3 codec for audio. If you don't know what codecs are, then you probably haven't downloaded any additional ones to your comp, so just pick ones from the list that's there in your video editing program. You can use Divx (I guess) but make sure it's a new version, and be sure to mention the divx codec is needed to watch your games videos. Again, I recommend just using the "pre-installed" codecs for less headaches. Windows Media Player 9 is actually pretty good, only about 1 additional meg for every 14 megs of Divx.

What's with the "length" variable in your scrîpt? Well, the game needs a way to hold out until the video is done, and the best way is to probe for keypresses... but you don't want to force the user to press a key at the end of the video, so you include the files playtime and when the counter runs out it will continue the game. If you don't want this feature, just enter a huge number, put a "end of video" screen at the (you guessed it) end of your videos, and make sure people know to press a button at the end of the videos to continue. Oh, while I'm at it, you can press Esc. during the video to skip it, but since the engine only probes for the keypresses every so often, you may have to hold the "Esc" key for as long as one second for the engine to realize you pressed it (small error).


-----------------------------------------------------------------

Version 2
By Soundspawn
Demo Version #2 : Demo Update #2 BUG found sorry

Code:
class Scene_Movie

def initialize(movie,length,exit_to_game=true)
  @readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
  @movie_name = Dir.getwd()+"\\Movies\\"+movie+".avi"
  @counter = length
  @exit_to_game = exit_to_game
end

def main
  game_name = "\0" * 256
  @readini.call('Game','Title','',game_name,255,".\\Game.ini")
  game_name.delete!("\0")
  Graphics.transition
  @wnd = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L')
  @temp = @wnd.call(0,0,nil,game_name).to_s
  @movie = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V')
  @movie.call("open \""+@movie_name+"\" alias FILE style 1073741824 parent " + @temp.to_s,0,0,0)
  @message = Win32API.new('user32','SendMessage','%w(l,l,l,l)','V')

  @detector = Win32API.new('user32','GetSystemMetrics','%w(l)','L')
  @width = @detector.call(0)
  if @width == 640
    fullscreen
    Graphics.update
    sleep(1)
    Graphics.update
    sleep(1)
    Graphics.update
    sleep(1)
  end

  @movie.call("play FILE",0,0,0)
  loop do
    sleep(1)
    @message.call(@temp.to_i,11,0,0)
    Graphics.update
    @message.call(@temp.to_i,11,1,0)
    Input.update
    if Input.trigger?(Input::B)
      break
    end
    @counter = @counter - 1
    if @counter <= 0
      break
    end
  end
  @movie.call("close FILE",0,0,0)
  if @exit_to_game
    $scene = Scene_Map.new
  else
    $scene = Scene_Title.new
  end
  Graphics.freeze
  if @width == 640
    fullscreen
  end
end
end

def fullscreen()

$full.call(18,0,0,0)
$full.call(13,0,0,0)
$full.call(18,0,2,0)
$full.call(13,0,2,0)
end
$full = Win32API.new('user32','keybd_event','%w(l,l,l,l)','')



Code:
$scene = Scene_Movie.new(name,length,false)


Instructions
Quote:Copy this into a new section of your game. To play a file, move the avi file into a "movies" subdirectory (yourgame\data, yourgame\graphics, yourgame\movies). Then call "$scene = Scene_Movie.new(filename,length)" where filename is your movies actual filename (minus the .avi) and length is the playtime in seconds.

Example: My games path is "C:\game". I create a folder in "C:\game" called movies. I then move my movie, called "intro.avi" into "C:\game\movies". Now I open my game, paste the above into a new section of the scrîpt editor (ABOVE MAIN), and close the scrîpt editor. Then I make a new event on my map, give it a graphic of a guy, and click to add command. I go to the third page and pick the bottom right one labeled "call scrîpt". Then I type "$scene = Scene_Movie.new("intro",8)" (the 8 because my intro is 7.5 seconds long and I know to round up if I must round). Now I run my game, and whenever I talk to this guy, it plays my movie.


Now not all avi files will work, but I really hope your making your own movies, so it should be no problem to try different codecs. Make your movies 640x480 in resolution. This scrîpt will be buggy as hell if you are running your computer at 640x480, and the editor is probably impossible to work with. If this is the case, increase your resolution to at least 800x600 and not only will it work, but people might believe you when you say you know more than nothing about computers

Anyway, this should be working flawlessly, and my small following will hopefully help me troubleshoot any issues people have, so feel free to post issues here and someone (I pray not always myself) will get back to you.

EDIT: I'm going to list some relavent stuff from the other topic here to answer a few questions before they're asked.

First off, this is not perfect, it cannot play videos while in fullscreen mode, but it can check your screens resolution to make a good guess if you're running fullscreen or not (hence the whole buggy 640x480 resolution thing I mentioned). If you game is running windowed, then your resolution shouldn't be 640x480 (with todays technology it's probably more like 1024x786 or higher, mines @ 1280x1024). When you go into fullscreen mode (alt+enter) your screen resolution changes to 640x480. So if it's about to play a video and the resolution is 640x480 it guesses that you don't actually use 640x480 resolution, you're just in fullscreen mode, so it jumps to windowed mode, plays the video, and re-enters fullscreen mode afterwards. If you were in windowed mode, it just plays the video. I've also noticed that playing the game in windowed mode with a resolution of 640x480 actually won't work right anyway because the games area is 640x480 PLUS the titlebar AND the taskbar... so you'd probably notice if your running 640x480, and you should definately change it to a higher setting anyway.

Second, as I mentioned not all Codecs work. The word "Codec" seems to scare a lot of people around here, so let me explain. A video file has three things (that are relevant to this thread): a video codec, and audio codec, and a file extension. Any extension can have any video/audio codec combinations, the codecs are basically just instructions on how to use the data in the file. "Compression" is used in most codecs, which makes the files more portable. You should find codecs that work well for what you need (usually less filesize means less quality with little workaround room), and stick with it. If you use common codecs, then others can watch your movies too... If you use "Hax0r's leaked Playstation codec" (don't think this is real, but an example) then most people won't have it, so you either need to provide the codec with your game, or somehow get them to a place where they can download/install it. I would just say to use "Windows Media Player 9" for video, and any common MP3 codec for audio. If you don't know what codecs are, then you probably haven't downloaded any additional ones to your comp, so just pick ones from the list that's there in your video editing program. You can use Divx (I guess) but make sure it's a new version, and be sure to mention the divx codec is needed to watch your games videos. Again, I recommend just using the "pre-installed" codecs for less headaches. Windows Media Player 9 is actually pretty good, only about 1 additional meg for every 14 megs of Divx.

What's with the "length" variable in your scrîpt? Well, the game needs a way to hold out until the video is done, and the best way is to probe for keypresses... but you don't want to force the user to press a key at the end of the video, so you include the files playtime and when the counter runs out it will continue the game. If you don't want this feature, just enter a huge number, put a "end of video" screen at the (you guessed it) end of your videos, and make sure people know to press a button at the end of the videos to continue. Oh, while I'm at it, you can press Esc. during the video to skip it, but since the engine only probes for the keypresses every so often, you may have to hold the "Esc" key for as long as one second for the engine to realize you pressed it (small error).

Version 2 info - Added the ability to go from a movie into the title screen. Nothing has changed if using the scrîpt to play a movie during the game, but lets say you want a video to come up BEFORE the player chooses new game... Just call
CODE
$scene = Scene_Movie.new(name,length,false)
where name is the filename (in quotes) without the extension ("joe" if the filename is "joe.avi") and length is the playtime in seconds. The functions third variable defaults to true, so you don't need to change any other spots. This is useful for playing movies at the very beginning of your game, and for rolling ending credits.

-----------------------------------------------------------
Version 3
By Soundspawn


Code:
class Scene_Movie

def initialize(movie,length,exit_to_game=true)
  @readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
  @movie_name = Dir.getwd()+"\\Movies\\"+movie+".avi"
  @counter = length*10
  @exit_to_game = exit_to_game
  main
end

def main
  game_name = "\0" * 256
  @readini.call('Game','Title','',game_name,255,".\\Game.ini")
  game_name.delete!("\0")
  Graphics.transition
  @wnd = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L')
  @temp = @wnd.call(0,0,nil,game_name).to_s
  @movie = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V')
  @movie.call("open \""+@movie_name+"\" alias FILE style 1073741824 parent " + @temp.to_s,0,0,0)
  @message = Win32API.new('user32','SendMessage','%w(l,l,l,l)','V')

  @detector = Win32API.new('user32','GetSystemMetrics','%w(l)','L')
  @width = @detector.call(0)
  if @width == 640
    fullscreen
    Screen::update
    sleep(1)
    Screen::update
    sleep(1)
    Screen::update
    sleep(1)
  end

  @movie.call("play FILE",0,0,0)
  loop do
   sleep(0.1)
   @message.call(@temp.to_i,11,0,0)
   Graphics.update
   @message.call(@temp.to_i,11,1,0)
   Input.update
   if Input.trigger?(Input::B)
     Input.update
     break
   end
   @counter = @counter - 1
   if @counter <= 0
     break
    end
  end
  @movie.call("close FILE",0,0,0)
  if @exit_to_game
    $scene = Scene_Map.new
  else
    $scene = nil
  end
  Graphics.freeze
  if @width == 640
    fullscreen
  end
end
end

def fullscreen()

$full.call(18,0,0,0)
$full.call(13,0,0,0)
$full.call(18,0,2,0)
$full.call(13,0,2,0)
end
$full = Win32API.new('user32','keybd_event','%w(l,l,l,l)','')

Instructions:
Quote:Version 3 info - Fixed the sleep command to sleep more often for shorter periods of time, increasing the chances of you pressing the esc button when the engine checks for it (might still press the button at a bad time and the engine won't notice, but it's more rare now). Also added support to string movies together... the way this works is as follows:

If you use $scene = Scene_Movie.new("intro",10,false), the false at the end no longer sends you to menu... instead it just returns to where this line was put down... to explain

Code:
main -
$scene = Scene_Movie.new("intro",8,false)
end

would play the movie, and then instead of going to the title screen, it will end the game.

Code:
main -
$scene = Scene_Movie.new("intro",8,false)
$scene = Scene_Title.new
end

will play the movie and then go to the title screen

Code:
main -
$scene = Scene_Movie.new("intro1",8,false)
$scene = Scene_Movie.new("intro2",8,false)
$scene = Scene_Movie.new("intro3",8,false)
$scene = Scene_Movie.new("intro4",8,false)
$scene = Scene_Title.new
end

will play four intro movies in a row (jesus man, why do you need FOUR intro movies... kinda abusing the scrîpt :)... then go to the title.
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Play AVI Movies in RMXP Popper 0 2,922 09-22-2006, 01:00 PM
Last Post: Popper



Users browsing this thread: