So in the end I did it. I turned LÖVE.. in a video maker/editor!

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
thestarknight
Prole
Posts: 10
Joined: Sun Nov 12, 2023 1:19 pm
Contact:

So in the end I did it. I turned LÖVE.. in a video maker/editor!

Post by thestarknight »

I posted some time ago about creating cutscenes for videos with love and there I was saying.. may be one day I will repurpose my game in a video maker..

Well I did it. I ended up turning LÖVE.. in a video maker engine because.. because yes!

You know you can make videos with other engines, like Unity for example, but LÖVE is a framework, not a full game engine and so... you need to teach with love to LÖVE how to do it.

I took the easy path, since I didn't wanted to go crazy with theora or to modify too much the source code.

What I have done is to simply integrate libopenglrecorder to the source code, add few wrappers to make it work and now each time LÖVE calls "present" the little library saves my frame in the video. mhuhauhuhuaa

This is the little gem
https://github.com/Benau/libopenglrecorder

But I didn't wanted just to record , I needed more.. I needed power!

When recording with an external program there is usually a frame rate loss, especially if your PC is not up to date, and mine is not. So I modified libopenglrecorder itself adding just few lines of code. A simple bool that when toggled tells it to record any frame I pass to It, ignoring its own dt for frame count.

Why you might ask ? Simple, because this way I can record at any fps I want.. on a toaster!

The magic of Delta Time
Thanks to DT, when you set it on love.run at the speed you like, you change the speed of the game. So let's say you set it at fixed value of 1/100, now you are updating and drawing at 100 fps ! Cool right ? So while I normally can play at 30 fps but if play+record they tend to drop to 28, now, instead, I record and encode at 60 fps, or should I fancy at 100, 1000 ? why not! mhuhahuahuha

The magic happens because I am creating a video, so I don't care of how long an update+draw cycle takes, I just need to present that frame to openglrecorder.

The modified openglrecorder now saves each frame I pass it ignoring his own timer. So first I initialize it telling it at what frame per second the video will be, then I just pass the complete frame from love.present in love.run and voilà, is done. A video recorder at 100 fps xD.

But what about the audio you might ask ? And you are right, because this way the audio will be all a mess since that is played in "real time".

Let me say that, if you just need to record some gameplay of your game at your normal fps you could just integrate libopenglrecorder, and record the game sesson with video and audio and it will come out perfect. It is a very simple and good library and it compiles within love like a breeze.

But in my case I needed a different approach.

Didn't I said I turned love in a video maker/editor ? So this is what i did.

While recording the video, having my audio manager, I just take note of what sound and when it is played. I write down a little simplified EDL file, with the sound, any effect like fade in or fade out and the precise time it happens at a speed of 1/fps. And voilà.

At This point I have my video , and an edl file. So I just load that little edl and record a new video with a black background (I don't need to draw anything just to record the sound) and simply play all the sounds, music, with all the nice effects at the right time.

Now I have my video, and second one all black with the audio.

Time to patch them together. Initially I loaded them into Openshot, put them in two tracks and re-encoded a new video.. but.. but.. that was slow.. Re-encoding everything .. takes time. And I am programmer right ? So why do that ?

You must know that the little library openglrecord, creates two temp files when recording, one for the video and one for the audio, then it merges them together in the final mkv. Why not profit of that ? And I did. Again with few lines of code I told the nice library to don't delete the temporary files after merging them. Then I taught it to merge together any arbitrary file I wish. And voilà again.

First I record my video at 60 fps, note the time of the sounds, run a audio recording session, take the first video.temp and merge it to the second audio.temp. Clever, pratical. And Libopenglrecord does this process at the speed it takes for you to close your jacket's zip. Is superfast. The Alternative is to use soundata to create a wave file with the audio but.. if so I must re-encode it with Openshot or ffmpeg.. and that takes time, while libopenglrecord handling its own temp files is superfast.. So while not perfect this is the faster solution.

Finally no more long re-encoding. Victory!

If you have ever edited videos you know that there is a lot of stuff to do. Put together all the takes, add sound and music, transitions, titles.. and so on.

Editing takes time, and I did that at the beginning, sometimes I was just recording the video+sound and adding the music and some effect in edit but again.. why.. why ? Who am I ? I am a Love developer! And the video must obey me!

After months, now I don't edit any more outside of love. The HQ video, titles, effects, sounds, music, transitions all comes out directly from Love in a sweet complete video.. and is a frigging satisfaction!

I can focus only on making the scenes, and the rest.. is just Voilà!

But this is a long post, like any victorious post shall be. And while you are still hyped for the achievement I ask you. Do you think it is enough ?

Sadly it was not because.. I started doing 2d over 3d videos stuff!
Basically is recording a video of a game in 3d and add all the rest on top. Is just like a normal scene, just the background is not a tiled scene or an image but a video playing. Cool right ?

Aaand here came a new problem because everything in love in sync with DT but .. audio and videos.. are not! They are live. If your game lags the sound must be perfect, It has not to stutter or let's say slow down, right ? If you suddenly have a frame rate drop your sound should not woooooobble down. But I needed that! I needed the video to play in "slow motion" at my custom DT, otherwise when recording the video and the scene they will be out of sync.

So "I went back into love" just writing that is emotional xD And.. :D I started looking for a way to slow down the video. Damn LÖVE programmers.. you fooled me with that framesync xD ! Because I was thinking that the video had its own Dt but.. it turned out that it has not! LÖVE plays the audio source of the video and then sysncs the video at the audio time position. Brilliant, flawless, probably is the way it has to be done but I didn't knew. This way the audio is always prefect and the video catches up.

In my case since I don't need the audio from the background video, when I record, I told love to... screw that and sync the video with my custom DT. LÖVE kindly did it. Now at each update love considers my Dt

--note the evil sourcesync that fooled me. Source, not deltasync or framesync xD Is all on the source! You LÖVE coders will understand this :D
double VideoStream::SourceSync::getPosition() const
{
return customdt;//source->tell(love::audio::Source::UNIT_SECONDS);
}

//frameSync->update(0);//dt);
double position = frameSync->getPosition();

It took me longer to understand this than to implement all the rest of the stuff xD

Anyway, drum roll... Final result: I have now a complete video editor.

Imagine my power, when creating the scene I can go back and forward to any point I want to play and replay it and to see if the scene is good. When I am satisfied I just launch a record session. Music and sounds are added from my code. I make from love any transition and I add any title. Since I can pause the recording and start it again, I can load a new set, place all the characters, and then shout "action" and start recording again. The final video will come out perfect, ready for the upload.

Is just fantastic.

So, If you ever wonder how many cool things you can make with LÖVE.. Now. There is one more ! Mhuahahha xD

Epic Conclusion: Since you spent all this time reading my awesome post, now go watch the video I made with all this techniques and put a great like on that xD

https://youtu.be/mb0hD9zAzDg

Epic Conclusion part 2: Also, if you need help to just integrate the openglrecord on love, because you fancy have it, or you have some questions, just ask, I'll see to help :D hopefully I can find some time becaaaause "My life DT is a mess." xD

Denis
Post Reply

Who is online

Users browsing this forum: No registered users and 57 guests