Page 1 of 1
export video from love2d
Posted: Mon Sep 07, 2020 4:08 am
by cizhenshi
I'm new to Love2D, and I want to generate a video via love2D's rendering engine. Is there a way to render code directly into a video instead of running it in a window? Thanks!!
Re: export video from love2d
Posted: Mon Sep 07, 2020 1:11 pm
by RNavega
Hi, I think the closest thing is the Canvas type, used for off-screen rendering. See these:
-
https://love2d.org/wiki/Canvas
-
https://love2d.org/wiki/Canvas:newImageData (a copy of the pixels in the canvas as an ImageData type)
-
https://love2d.org/wiki/ImageData:encode (saving that ImageData as a file)
This means you'd capture an image sequence to files and later on
encode them to a video using a different program.
A fallback in case this isn't working for you is to use OBS or some other screen recorder app to capture the main LÖVE window, like Youtube or Twitch streamers do.
Re: export video from love2d
Posted: Tue Sep 08, 2020 6:24 am
by zorg
Adding to the above answer, you could modify love.run to assure that update and draw get called at constant time intervals, so that the output frame rate won't fluctuate (that is to say, the visuals won't).
Re: export video from love2d
Posted: Tue Sep 08, 2020 6:57 am
by ivan
zorg wrote: ↑Tue Sep 08, 2020 6:24 am
so that the output frame rate won't fluctuate (that is to say, the visuals won't).
In theory you could render the frames in a loop - it doesn't have to be in real time.
Either way it's important to use a "fixed time step"
Re: export video from love2d
Posted: Tue Sep 08, 2020 8:53 pm
by ReFreezed
Expanding on the ImageData idea, a simple solution is to use
love.graphics.captureScreenshot to capture each frame. No canvas required. Of course, none of these methods capture any sound. Your best bet is probably to use an external recording program as LÖVE indeed does not provide a way to encode video files.
Re: export video from love2d
Posted: Thu Sep 10, 2020 3:42 pm
by AuahDark
Gotta promote my internal-use library: use
ls2x.
Code: Select all
local ls2x = require("ls2x")
local ffi = require("ffi")
local function supply(imageData)
ls2x.libav.supplyEncoder(ffi.cast("uint8_t*", imageData:getFFIPointer()))
end
function love.load()
ls2x.libav.startEncodingSession("output_File.mkv", love.graphics.getWidth(), love.graphics.getHeight(), 60) -- 60 = 60 FPS
end
function love.update(dt)
-- set dt to constant
game_update(constant_dt)
love.graphics.captureScreenshot(supply)
end
-- your love.draw goes below
function love.quit()
ls2x.libav.endEncodingSession()
end
Or you can pipe FFmpeg, but pipe bandwidth in Windows is not that great.
Re: export video from love2d
Posted: Thu Sep 10, 2020 10:01 pm
by RNavega
That looks dope AuahDark. I consider myself good at googling and couldn't find any Lua video encoding libraries, I wonder how I missed your ls2x. Very useful.
Re: export video from love2d
Posted: Fri Oct 23, 2020 11:50 am
by Lolitas
I want to create a game with this platform. The idea of my game is a girl locked in a house and she has to follow the instructions of the users who see her live through the webcam and I need an external program to make screen recordings, it doesn't matter that it doesn't capture the sound, but I can't find one that is simple, could you recommend one?