veger / TLBE

TLBE - Time Lapse Base Edition
MIT License
9 stars 6 forks source link

Taking screenshots causes FPS/UPS to halve per screenshot #26

Closed bloxanne123 closed 2 years ago

bloxanne123 commented 2 years ago

I tried using this mod to create a timelapse of my base, but every time the mod takes a screenshot (default settings), the game freezes and I see the FPS/UPS halve.

I can launch nukes without the game lagging..so I don't understand why the performance drops. I have an SSD and a dedicated GPU with 2GB of VRAM which should be enough for 1080p screenshots

veger commented 2 years ago

For each screenshot the game has to render the image for the provided resolution you use. If the image is zoomed out a lot, it takes more effort to render (more objects/entities to process). During the render the game if paused, so the render is consistent.

So a big(ger) base + a high resolution takes more time... Which can be mitigated by faster CPU, GPU, RAM and (disk) storage.

You can try lowering resolution and/or taking screenshots with a smaller base/zoom factor to see if this helps speeding up.

bloxanne123 commented 2 years ago

A smaller zoom factor "zooms" out from the base slower, right? And what's a base factor?

bloxanne123 commented 2 years ago

Alright I narrowed down the issue - it's to do with the "Image resolution too small" warning that triggers when I zoom in and stay like that for a while. After that message pops up, my game starts freezing like I said above. It says the solution is to either increase resolution or decrease size of base. I truthfully don't care about how much storage it takes. (mod runs very well when this isn't happening lol...)

What should I do? I'd rather increase resolution to be honest...but are there other ways to prevent this without sacrificing quality? I can deal with not being super zoomed in all the time, maybe the mods I have affect its recording capabilities? (Renai transportation, large spidertron grid)

bloxanne123 commented 2 years ago

Uhhh I've got bad news..I set the res to 2560x1440 and the issue happened AGAIN. image that is the size of my fun map....and the large screenshots are harder to take but it's better than freezing up..

Any ideas on how to stop this? I want my whole base to be recorded. My normal world isn't nearly as large but I do not want to constantly increase image resolution once my world is large enough to warrant it because the lag will increase a lot (and it's already past the 1080p point) My survival base is way smaller, but the issue still stands since it's surpassed 1080p

veger commented 2 years ago

The image resolution error occurs when the zoom factor is smaller than the game supports, you'd basically reached maximum zoom (in order to fit the base). To mitigate this you'd need to increase to resolution (a bigger canvas can contain more details), so zooming out would (still) fit the base (again).

This (of course) would take even longer to take screenshots. So it won't solve you original problem.

I honestly don't know how to solve this. I guess big bases needs more (a lot) of CPU, RAM, GPU to keep running smooth. I guess same (+ fast disk/storage speeds) goes for taking screenshots of it...?

bloxanne123 commented 2 years ago

Is it possible to just use different "cameras" to split up the base so that more resolution isn't needed? Then maybe auto add new ones as needed and when you're done, stitch all the photos from different cameras together to create a timelapse?

veger commented 2 years ago

Technically it would be possible: When the mod detects that the zoom factor is out of bounds, it could take multiple screenshots and you'd have to seam them together afterwards. Obviously this is not going to speed up taking screenshots, as still a lot/too much entities needs to be processed and rendered by the game into the screenshot. (Most likely it will slow them down as now multiple screenshot would need to be (pre)processed)

So while this might be a nice feature for large bases, I highly doubt that this will resolve the FPS/UPS drops you encounter...

bloxanne123 commented 2 years ago

Makes sense to me...I suppose for now I can just increase the size of the screenshots, but the physical size (as in how many chunks are "explored" on your map is what counts towards it being too big and then requiring a larger resolution? Or is it something else?

veger commented 2 years ago

There are two different things in play here (and mixed a little):

  1. In order to fit a base, you typically zoom out. But, Factorio has a maximum zoom factor and it refuses to zoom out further. Most likely because things become too small. So in order to make sure your base fits, you need to increase the resolution of the screenshot. So it still fits (as zooming out further doesn't help fitting the base anymore)
  2. Taking screenshots takes time/effort, depending on a. zoom factor, resolution -> the more that fits the more that needs processed and rendered b. amount of entities (chunks, buildings and other objects) -> they all need to be processed (this is partially related to zoom/resolution as this determines how much is in te screenshot as well) c. resources (CPU, GPU, RAM, disk) -> the faster they are the faster a screenshot is processed and taken

The mod will handle point 1 by making sure the screenshots are zooms to fit the base (with the 'base tracker' at least). Up until the point where Factorio refuses to zoom out further. Then your only choice is to increase the resolution (and thus lowering the zoom managed by the mod)

Point 2 is about the FPS/UPS dropping when taking screenshots (initial question in this issue), of which there is not a whole lot to do except building smaller bases (point a), get rid of unnecessary entities ike trees, decorations, biters, etc (point b) or get (even) faster resources (point c)

I hope this explanation helps/clarifies more?

bloxanne123 commented 2 years ago

Yes, thank you! My base is pretty "naked" but it has a small factory and a lot of trees still around the map, this is probably why I get some lag with screenshots. Thanks for your help, I think I can live with lower FPS/UPS in exchange for a timelapse. if I have more questions, I can just ask here on GH right?

One more thing - how does the mod handle modded scenarios? I'm not talking heavily modded, just lightly modded (renai transportation, waterfill, etc.)

veger commented 2 years ago

if I have more questions, I can just ask here on GH right?

yes, no problem!

One more thing - how does the mod handle modded scenarios?

Should just work fine. The 'only' thing that the mod does is keep track of new buildings (to recalculate the base position) and take screenshots using the Factorio interface (APIs). The mod is even able to take screenshots of other surfaces (think Factorissimo2 or Space Exploration mods). Mods (usually) won't influence these 2 aspects (AFAIK), so TLBE will/should work fine with them.

bloxanne123 commented 2 years ago

Uhh it sorta ate my storage..100GB gone in a week How do I assemble images into a timelapse? It has screenshots from numerous saves also..didn't seem to differentiate between them when I look through the script-output folder.. Would it be possible to turn everything into a timelapse, delete the screenshots after, and then make a new timelapse and in video editing software put the two of them together seamlessly?

I played for like 7 minutes and used up 1.26GB in screenshots...they're 1440p only

veger commented 2 years ago

How do I assemble images into a timelapse?

There are numerous ways, I use the method described here: https://github.com/veger/TLBE/issues/7#issuecomment-678491951

It has screenshots from numerous saves also..didn't seem to differentiate between them when I look through the script-output folder..

A little too late now, but the mod settings allow you to specify a folder in script-output to store the screenshots (default is tlbe). So it is easy to have different folders for each save.

Would it be possible to turn everything into a timelapse, delete the screenshots after, and then make a new timelapse and in video editing software put the two of them together seamlessly?

Yes, this is what I also do, as converting screenshots into video reduces the size tremendously! (as you noticed it eats up your storage... :stuck_out_tongue: )

bloxanne123 commented 2 years ago

Ah, so it does do it seamlessly; awesome! Gonna turn it into a timelapse today I suppose, and delete the images and also set the mod to use different folders per save lol Additionally I've never used ffmpeg and I did change TLBE to use 30 FPS and I added some new trackers/cameras. How do I assemble it into a timelapse with ffmpeg?

bloxanne123 commented 2 years ago

Oh nooo Some of the screenshots are 0mb.... Shouldn't the mod warn you about this? Luckily it's not too much time lost before the first 0mb image appears, only about 46 screenshots (2 minutes of real world time or so) are 0mb....

veger commented 2 years ago

The mod doesn't write the screenshots, Factorio is doing that. I guess you could file a bug report/feature request on the forums asking to warn the player that saving a screenshot failed due to lack of storage space...?

Additionally I've never used ffmpeg and I did change TLBE to use 30 FPS

Me neither, except for the command I linked to...

added some new trackers/cameras. How do I assemble it into a timelapse with ffmpeg?

If you have multiple camera, you need to edit you video to switch camera streams, or show then next to eachother, or whatever your plan for the final video... :wink:

bloxanne123 commented 2 years ago

If you have multiple camera, you need to edit you video to switch camera streams, or show then next to eachother, or whatever your plan for the final video... 😉

How do I make sure ffmpeg assembles the images properly with multiple cameras/trackers? Are you sure it's completely seamless? (I say this referring to having multiple trackers/cameras and turning the first 90GB of screenshots into a proper timelapse, and then doing it again with another 90GB of screenshots and then editing the 2 separate timelapses together to look seamless)

veger commented 2 years ago

each camera stores the screenshots with a different filename/prefix. So using something like

ffmpeg -framerate 25 -pattern_type glob -i 'camera1*.png' -c:v libx264 -pix_fmt yuv420p camera1.mp4
ffmpeg -framerate 25 -pattern_type glob -i 'camera2*.png' -c:v libx264 -pix_fmt yuv420p camera2.mp4

Gives you 2 timelapses (one from each camera)

How to edit the 2 timelapses into a single video is up to you:

No idea if ffmpeg can do this (it is pretty powerful, so probably it can), or you'd need some proper video editing software... (I am by no means an expert (or even an amateur) in video editing... :disappointed:

bloxanne123 commented 2 years ago

How do I assemble images into a timelapse?

There are numerous ways, I use the method described here: #7 (comment)

It has screenshots from numerous saves also..didn't seem to differentiate between them when I look through the script-output folder..

A little too late now, but the mod settings allow you to specify a folder in script-output to store the screenshots (default is tlbe). So it is easy to have different folders for each save.

Would it be possible to turn everything into a timelapse, delete the screenshots after, and then make a new timelapse and in video editing software put the two of them together seamlessly?

Yes, this is what I also do, as converting screenshots into video reduces the size tremendously! (as you noticed it eats up your storage... 😛 )

There's no tlbe folder for me..and the mod isn't showing any options to select different folders.

image Where do I specify specific save locations for timelapses per save? I have script-output and inside it I have timelapse.

veger commented 2 years ago

Exactly, using the 'save location' you can keep the locations separate per save (less messy). And in your case the folder (for this save at least) is called 'timelapse'.

It is up to you how you name the folder, I usually use the name of my save/base, so it can find it back (more) easily.

bloxanne123 commented 2 years ago

The issue is screenshots from all saves are saving in the timelapse folder.

veger commented 2 years ago

Even when you change the 'Save location' and make sure to confirm the changed settings? It is (has been, I'll check when I am back home again) working fine on my side... :thinking:

bloxanne123 commented 2 years ago

That bit works fine but I can't set separate screenshot save locations for each save...

veger commented 2 years ago

True, the folder is used for all cameras/screenshots. On top of this, the camera name is used in the name of the screenshots (for that camera), so it is fairly easy to filter out the screenshots of each camera within the same save (folder).

See the ffmpeg example I wrote about (https://github.com/veger/TLBE/issues/26#issuecomment-945114506): -pattern_type glob -i 'camera1*.png' should filter all screenshots for camera1 when it makes the video.

bloxanne123 commented 2 years ago

Wait but none of my screenshots have a camera name and I play on a few saves...they're sorta mixed up. Every save uses one camera though so maybe that's why..?

Also, ffmpeg on windows is absolute hell...do you have a guide as this is not working for me..glob isn't valid on windows and wildcards seem to just not work...?

I don't know what the issue is honestly, I just cd into the dir with images (moved them to a separate one) and ran commands to create the video..no workies. If you know of a command that gives me a valid format for windows, please send it here cuz I'm at my wits' end with all this ffmpeg stuff. I just need 1440p and 30 FPS with high quality. ffmpeg doesn't think *-main.png is valid

Tried these commands: foreach ($i in Get-ChildItem .\*.png) {echo "file '$i'" >> mylist.txt} and then ffmpeg.exe -f concat -safe 0 -i mylist.txt -framerate 24 -c:v libx264 -crf 24 -pix_fmt yuv420p -maxrate 2.5M -bufsize 8M timelapse.mp4 I get a 504kb file that's less than a second and displays one image...

bloxanne123 commented 2 years ago

Ok so it turns out the file names are NOT sequential....that's why I ran into my wonky file issue What does sequential numbering look like compared to the tick one?

veger commented 2 years ago

If you know of a command that gives me a valid format for windows, please send it here cuz I'm at my wits' end with all this ffmpeg stuff

I am not on Windows, but there was a request before to add sequential numbering: https://github.com/veger/TLBE/issues/7 to make life a (little) easier on Windows.

Also, I use ffmpeg because it works (most) easy on Linux, on Windows there might be something else that works more easy to stitch screenshots together into a video?

Tick numbering uses the tick number in the filenames (easy to keep track on the in game time), sequential numbering starts at 1 (on a new game) and counts up for each screenshot.

The setting is called Sequential names and is in the mod setting, when you toggle it, it will start using sequential numbering (incrementing from the last saved file, or 1 for a new game, if I remember correctly)

bloxanne123 commented 2 years ago

Maybe sequential is just weird on already started games, but I got ffmpeg working Thanks for all your help, I really appreciate it :D (oh lord 98 GB of screenshots is gonna take forever lol)