| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Message
| It's not really designed for that, however I once played a short video clip using the technique here:
-- --------------------------------------------------------------------
-- PlayMovie (info)
-- info.filename (eg. "/frames/my_movie_%03i.png" )
-- info.frames (eg. 10, if the movie consists of 10 files)
-- info.x - X position on screen
-- info.y - Y position on screen
-- Suggested conversion:
-- ffmpeg -ss "00:30" -i INPUTFILE.mp4 -t 1 -r 10 -s 720x404 frames/my_movie_%03i.png
-- ^^^^ ^^^ ^^^^ ^^^^^ ^^^^^^^ ^^^^^^^^^^
-- Start time input file how long FPS size output files
-- --------------------------------------------------------------------
function PlayMovie (info)
movieInfo = info
if not info then
return
end -- if
assert (type (movieInfo) == "table",
"Argument to PlayMovie should be a table")
local gotErrors = false
-- load each movie frame into memory, if not already done
for i = 1, movieInfo.frames do
local filename = string.format (movieInfo.filename, i)
if not WindowImageInfo(win, filename, 2) then
local result = WindowLoadImage(win, filename, filename)
if result ~= error_code.eOK then
ColourNote ("Red", "", "Could not open move frame file:")
ColourNote ("Red", "", " -> " .. filename)
ColourNote ("Red", "", " Reason: " .. error_desc [result])
gotErrors = true
end -- if
end -- if
end -- for each frame
-- if couldn't do it, discard the movie info
if gotErrors then
movieInfo = nil
return
end -- if
-- otherwise, start at frame 1
movieInfo.currentFrame = 1
end -- PlayMovie
-- --------------------------------------------------------------------
-- PlayMovieFrame - called by a timer every 1/10 second - show current frame, advance count
-- --------------------------------------------------------------------
function PlayMovieFrame (timerName)
-- if no current movie, do nothing
if not movieInfo then
return
end -- if
-- timing stuff
timeTaken = timeTaken or 0
frameCount = frameCount or 0
local startTime = utils.timer ()
local filename = string.format (movieInfo.filename, movieInfo.currentFrame)
if WindowDrawImage (win, filename, movieInfo.x, movieInfo.y, 0, 0,
miniwin.image_copy) ~= error_code.eOK then
ColourNote ("Orange", "", "Could not draw image: " .. imageName)
end -- if
Redraw () -- force screen update
-- next frame
movieInfo.currentFrame = movieInfo.currentFrame + 1
-- wrap
if movieInfo.currentFrame > movieInfo.frames then
movieInfo.currentFrame = 1
end -- if
-- add up how long we took doing this
timeTaken = timeTaken + utils.timer () - startTime
-- and how many times
frameCount = frameCount + 1
end -- PlayMovieFrame
Timer:
<timers>
<timer
script="PlayMovieFrame"
enabled="y"
second="0.1"
active_closed="y"
>
</timer>
</timers>
Calling the above functions:
PlayMovie {
filename = "frames\\my_movie_%03i.png",
frames = 30,
x = 10,
y = 10,
}
First you take a (short) movie and convert it into PNG files (see the suggested ffmpeg command above) with a frame rate of 10 FPS.
Then we set up a timer that is called every 1/10th of a second to play the next frame.
The function PlayMovie is called which scans the supplied directory for all of the files matching the supplied file name. It loads them all into miniwindow "images". Then the timer is called which replaces the current frame with the next one.
This is hardly going to play a full-length video, but it worked OK for me to play a short animation. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|