export video from love2d

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
cizhenshi
Prole
Posts: 1
Joined: Mon Sep 07, 2020 4:05 am

export video from love2d

Post 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!!
RNavega
Party member
Posts: 355
Joined: Sun Aug 16, 2020 1:28 pm

Re: export video from love2d

Post 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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: export video from love2d

Post 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).
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: export video from love2d

Post 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"
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: export video from love2d

Post 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.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
AuahDark
Party member
Posts: 107
Joined: Mon Oct 23, 2017 2:34 pm
Location: Indonesia
Contact:

Re: export video from love2d

Post 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.
Profile. Do you encounter crashes in LÖVE Android and wanna send me logcats? Please hit me up in LÖVE Discord and send the full logcat file!
RNavega
Party member
Posts: 355
Joined: Sun Aug 16, 2020 1:28 pm

Re: export video from love2d

Post 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.
Lolitas
Prole
Posts: 1
Joined: Fri Oct 23, 2020 11:34 am

Re: export video from love2d

Post 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?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests