JordanSantiagoYT / FNF-JS-Engine

JS Engine is basically Psych Engine but with (almost) no botplay lag and NEW features!
Apache License 2.0
48 stars 33 forks source link

Why does render mode capture every frame by reading the application's pixels just to encode it and save it onto the folder inside "assets/gameRenders" named the song name? #214

Closed SomeGuyWhoLovesCoding closed 7 months ago

SomeGuyWhoLovesCoding commented 9 months ago

What is your question?

It literally destroys lower end PCs' processors because of memory leaks that happen by reading the applications game's pixels (which is super expensive because of blitting) and settings the lime.graphics.Image variable in the class to it. At least there could be another way to record lagless game footage that won't destroy a computer processor.

I'm not exaggerating btw, this is important.

JordanSantiagoYT commented 9 months ago

well idk, HRK. EXEX made it and he has a good pc, this feature isnt exactly made for lower-end pcs

JordanSantiagoYT commented 9 months ago

What is your question?

At least there could be another way to record lagless game footage that won't destroy a computer processor.

well until we actually FIND that way (if there is one,) then this is the only way we can go.

moxie-coder commented 9 months ago

@JordanSantiagoYT there’s this, it’s old and discontinued but it should still work, in theory https://github.com/EliteMasterEric/extension-ffmpeg

SomeGuyWhoLovesCoding commented 9 months ago

@JordanSantiagoYT there’s this, it’s old and discontinued but it should still work, in theory https://github.com/EliteMasterEric/extension-ffmpeg

That's perfect. It works on windows, macos, linux, and android

JordanSantiagoYT commented 9 months ago

@JordanSantiagoYT there’s this, it’s old and discontinued but it should still work, in theory https://github.com/EliteMasterEric/extension-ffmpeg

I've looked. I don't think that has an encoder, only a decoder

moxie-coder commented 9 months ago

@JordanSantiagoYT there’s this, it’s old and discontinued but it should still work, in theory https://github.com/EliteMasterEric/extension-ffmpeg

I've looked. I don't think that has an encoder, only a decoder

pretty sure it has encoding support, haven’t tested it but it might

EyeDaleHim commented 9 months ago

well idk, HRK. EXEX made it and he has a good pc, this feature isnt exactly made for lower-end pcs

Keyword: "memory leaks", I don't think you should be ignoring that kind of stuff either, even if it's not meant for lower-end computers. Memory leaks shouldn't even happen to begin with.

HRK-EXEX commented 9 months ago

hello, that memory leak happened on my build too. but there is only one solution, just edit "original" library code. i edited that on my build but idk how to fix this serious problem. i'm also trying on pipe real ffmpeg on fnf (ofc native c++ code), but i'll be busy now cuz job hunting.

SomeGuyWhoLovesCoding commented 9 months ago

hello, that memory leak happened on my build too. but there is only one solution, just edit "original" library code. i edited that on my build but idk how to fix this serious problem. i'm also trying on pipe real ffmpeg on fnf (ofc native c++ code), but i'll be busy now cuz job hunting.

Oh wow, that's great

SomeGuyWhoLovesCoding commented 9 months ago

well idk, HRK. EXEX made it and he has a good pc, this feature isnt exactly made for lower-end pcs

Keyword: "memory leaks", I don't think you should be ignoring that kind of stuff either, even if it's not meant for lower-end computers. Memory leaks shouldn't even happen to begin with.

That's true

SomeGuyWhoLovesCoding commented 9 months ago

@JordanSantiagoYT there’s this, it’s old and discontinued but it should still work, in theory https://github.com/EliteMasterEric/extension-ffmpeg

I've looked. I don't think that has an encoder, only a decoder

Will you please add an option for asynchronous chart parsing and implement that feature itself onto your engine? Also make it manage memory

moxie-coder commented 9 months ago

@JordanSantiagoYT there’s this, it’s old and discontinued but it should still work, in theory https://github.com/EliteMasterEric/extension-ffmpeg

I've looked. I don't think that has an encoder, only a decoder

Will you please add an option for asynchronous chart parsing and implement that feature itself onto your engine? Also make it manage memory

Okay

JordanSantiagoYT commented 9 months ago

@JordanSantiagoYT there’s this, it’s old and discontinued but it should still work, in theory https://github.com/EliteMasterEric/extension-ffmpeg

I've looked. I don't think that has an encoder, only a decoder

Will you please add an option for asynchronous chart parsing and implement that feature itself onto your engine? Also make it manage memory

Asynchronous chart loading and memory management are both impossible to implement in a HaxeFlixel game.

JordanSantiagoYT commented 9 months ago

But moxie said ok so we might be able to figure smth out.

JordanSantiagoYT commented 8 months ago

image i.. don't know if this should close the commit

cabfile commented 8 months ago

now that the new rendering mode was implemented i think its safe to close this

SomeGuyWhoLovesCoding commented 8 months ago

now that the new rendering mode was implemented i think its safe to close this

Wait, we have to switch from obtaining the pixels to creating a pixel buffer object using gl context.

JordanSantiagoYT commented 8 months ago

Well I tried and there's minimal lag from my end, so I'm gonna mark this as "Technically Complete*" until that's implemented

SomeGuyWhoLovesCoding commented 8 months ago

Well I tried and there's minimal lag from my end, so I'm gonna mark this as "Technically Complete*" until that's implemented

Show me code for it. Also, on my end, it lags.

JordanSantiagoYT commented 8 months ago

Well I tried and there's minimal lag from my end, so I'm gonna mark this as "Technically Complete*" until that's implemented

Show me code for it. Also, on my end, it lags.

// Render mode stuff.. If SGWLC/cabfile isn't ok with this I will remove it :thumbsup:

private var process:sys.io.Process;
var ffmpegExists:Bool = false;

private function initRender():Void
{
    if (!ffmpegMode)
        return;

    if (!sys.FileSystem.exists('ffmpeg.exe'))
    {
        trace("\"ffmpeg.exe\" not found! (Is it in the same folder as the JS Engine exe?");
        return;
    }

    ffmpegExists = true;

    process = new sys.io.Process('ffmpeg', ['-v', 'quiet', '-y', '-f', 'rawvideo', '-pix_fmt', 'rgba', '-s', lime.app.Application.current.window.width + 'x' + lime.app.Application.current.window.height, '-r', Std.string(targetFPS), '-i', '-', '-b', Std.string(ClientPrefs.renderBitrate * 1000000),  'assets/gameRenders/' + Paths.formatToSongPath(SONG.song) + '.mp4']);
    FlxG.autoPause = false;
}

private function pipeFrame():Void
{
    if (!ffmpegExists)
    return;

    var img = lime.app.Application.current.window.readPixels(new lime.math.Rectangle(FlxG.scaleMode.offset.x, FlxG.scaleMode.offset.y, FlxG.scaleMode.gameSize.x, FlxG.scaleMode.gameSize.y));
    var bytes = img.getPixels(new lime.math.Rectangle(0, 0, img.width, img.height));
    process.stdin.writeBytes(bytes, 0, bytes.length);
}

public function stopRender():Void
{
    if (!ClientPrefs.ffmpegMode)
        return;

    process.stdin.close();
    process.close();
    process.kill();

    FlxG.autoPause = true;
}
SomeGuyWhoLovesCoding commented 8 months ago

Well I tried and there's minimal lag from my end, so I'm gonna mark this as "Technically Complete*" until that's implemented

Show me code for it. Also, on my end, it lags.

// Render mode stuff.. If SGWLC/cabfile isn't ok with this I will remove it :thumbsup:

private var process:sys.io.Process;
var ffmpegExists:Bool = false;

private function initRender():Void
{
  if (!ffmpegMode)
      return;

  if (!sys.FileSystem.exists('ffmpeg.exe'))
  {
      trace("\"ffmpeg.exe\" not found! (Is it in the same folder as the JS Engine exe?");
      return;
  }

  ffmpegExists = true;

  process = new sys.io.Process('ffmpeg', ['-v', 'quiet', '-y', '-f', 'rawvideo', '-pix_fmt', 'rgba', '-s', lime.app.Application.current.window.width + 'x' + lime.app.Application.current.window.height, '-r', Std.string(targetFPS), '-i', '-', '-b', Std.string(ClientPrefs.renderBitrate * 1000000),  'assets/gameRenders/' + Paths.formatToSongPath(SONG.song) + '.mp4']);
  FlxG.autoPause = false;
}

private function pipeFrame():Void
{
  if (!ffmpegExists)
  return;

  var img = lime.app.Application.current.window.readPixels(new lime.math.Rectangle(FlxG.scaleMode.offset.x, FlxG.scaleMode.offset.y, FlxG.scaleMode.gameSize.x, FlxG.scaleMode.gameSize.y));
  var bytes = img.getPixels(new lime.math.Rectangle(0, 0, img.width, img.height));
  process.stdin.writeBytes(bytes, 0, bytes.length);
}

public function stopRender():Void
{
  if (!ClientPrefs.ffmpegMode)
      return;

  process.stdin.close();
  process.close();
  process.kill();

  FlxG.autoPause = true;
}

Okay that isn't using the new method of getting the screen pixels

moxie-coder commented 7 months ago

closing due to inactivity and it’s been a long while since this was last made