10-07-2024, 09:53 PM
(This post was last modified: 10-07-2024, 09:58 PM by DerVVulfman.)
I hate... I HATE.... I HATE... writing instructions for code. Prolly why I have delayed releasing what might be a really good damage application script. Testing and coding is more fun than documentation. ARRRGH, I'M TYPING AGAIN!
Well, I decided to do a little blast-from-the-past in revisiting Movie playback for RMXP, and did this:
You execute it from a simple Movie.play(filename) script call. Its a module, so it should be pretty dang compatible with most anything (that allows for the Win32API). Heck, it should be fine for users beyond XP, just needing to remove lines 95-100 that calls the Graphics.Update method every 10 or so frames.
I instituted a couple of calls before and after the graphics update that should seriously reduce any chance of flicker, this despite being able to use the ESC key to exit. AND... it can be used by a good number of video formats. I listed the formats I've confirmed and wrote up what video and audio codexes to look out for.
EXAMPLES:
Movie.play"FOS01.mp4") good
Movie.play"FOS01.webm") bad
Still, it does not stretch to fit, nor does it like Fullscreen mode. And it cannot cache the video files.
Well, I decided to do a little blast-from-the-past in revisiting Movie playback for RMXP, and did this:
Code:
#==============================================================================
# ** RMXP Movie player (title subject to change ^_^
#------------------------------------------------------------------------------
# DerVV: 10/07/2024 (MM/DD/YYYY)
#==============================================================================
#
# Movies gotta be in the Movies subfolder in your project's root folder.
#
# HOW TO USE:
# * The one script call: Movie.play(filename)
# * Example with filename: Movie.play("FOS01.mp4")
#
#------------------------------------------------------------------------------
#
# I spent time testing what formats worked for my system, and what did not.
# This list is not extensive, but should be a good guideline.
#
# Tested and works with the following formats
# * 3gp
# * asf
# * avi - no audio regardless of audio codex
# * m4v
# * mov
# * mp4
# * wmv - tends to be grainy
#
# Does not play the following formats
# * flv
# * mkv
# * ogv
# * webm
#
# The following video codexes work: h263, x264, wmv2 (wmv2 grainy)
# The following video codexes do not work: libtheora, xvid, flv, swf
# The following video codexes have issues: xvid (grainy, and needs mp3 audio)
# The following audio codexes do not work: vorbis
#
#------------------------------------------------------------------------------
# DOES NOT STRETCH TO FIT. Movie will be top-left oriented regardless of size.
# DOES NOT LIKE FULLSCREEN MODE (Sorry... no xp code yet fixes that...)
# DOES NOT CACHE. They're like the default audio folder that way.
#==============================================================================
#==============================================================================
# ** Movie
#------------------------------------------------------------------------------
# This module allows playback of video content by use of the Win32API.
#==============================================================================
module Movie
#--------------------------------------------------------------------------
# * Play movie
# movie : movie filename
#--------------------------------------------------------------------------
def self.play(movie)
#
# Reset frame counter
gucount = 0
#
# Get path for movie in project
movie_name = Dir.getwd()+"\\Movies\\"+movie
#
# Basic Win32API calls for window and MCI playback
readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
wnd = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L')
message = Win32API.new('user32','SendMessage','%w(l,l,l,l)','V')
mplayer = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V')
#
# DEPRECIATED: win_metrics delivers x/y screen size values
win_metrics = Win32API.new('user32','GetSystemMetrics','%w(l)','L')
#
# Re-establish game name in window
game_name = "\0" * 256
readini.call('Game','Title','',game_name,255,".\\Game.ini")
game_name.delete!("\0")
hwnd = wnd.call(0,0,nil,game_name).to_s
#
# Open movie for playback
mplayer.call("open #{movie_name} alias FILE style child parent " + hwnd.to_s,0,0,0)
#
# Clear status and play movie
status = " " * 255
mplayer.call("play FILE",0,0,0)
#
# Perform loop while playing movie
loop do
# Suspend thread activity every 1/10th of a second
sleep(0.1)
#
# Ready refresh before graphics update (Flicker prevention)
message.call(hwnd.to_i,11,0,0)
#
# Frame update every 1/2 second based on frame rate
gucount += 1
if gucount > Graphics.frame_rate / 2
Graphics.update
gucount = 0
end
#
# Refresh after graphics update (Flicker prevention)
message.call(hwnd.to_i,11,1,0)
#
# Update Input
Input.update
#
# Test playback status
mplayer.call("status FILE mode",status,255,0)
status_check = status.unpack("aaaa")
#
# Exit from loop if pressed ESC or playback is over
break if Input.trigger?(Input::B) or status_check.to_s != "play"
#
end
#
# Close movie and clear input with minor delay
mplayer.call("close FILE",0,0,0)
sleep(0.1)
Input.update
sleep(0.1)
#
end
#
end
You execute it from a simple Movie.play(filename) script call. Its a module, so it should be pretty dang compatible with most anything (that allows for the Win32API). Heck, it should be fine for users beyond XP, just needing to remove lines 95-100 that calls the Graphics.Update method every 10 or so frames.
I instituted a couple of calls before and after the graphics update that should seriously reduce any chance of flicker, this despite being able to use the ESC key to exit. AND... it can be used by a good number of video formats. I listed the formats I've confirmed and wrote up what video and audio codexes to look out for.
EXAMPLES:
Movie.play"FOS01.mp4") good
Movie.play"FOS01.webm") bad
Still, it does not stretch to fit, nor does it like Fullscreen mode. And it cannot cache the video files.