SFML community forums

Help => Window => Topic started by: VerchaBercha on September 08, 2023, 11:40:29 am

Title: Issues saving images when recording window
Post by: VerchaBercha on September 08, 2023, 11:40:29 am
Hello there.

I am using SFML to visualise and record a simulation for my thesis.

I have written a code for recording the window to use for visual analysis. Leaning on this blogpost https://en.sfml-dev.org/forums/index.php?topic=25254.0 (https://en.sfml-dev.org/forums/index.php?topic=25254.0) I have the following:

if (recording) {
        sf::Texture texture;
        texture.create(window->getSize().x, window->getSize().y);
        texture.update(*window);
        std::string filename = "recordings/frame_" + counterToString(recordingCounter, 5) +".png";
        texture.copyToImage().saveToFile(filename);
        recordingCounter++;
        if (recordingCounter % 100 == 0) {
          std::cout << "Frames made: " << recordingCounter << std::endl;
        }
      }
 

where recording is a boolean that can be set to True via pressing the R key on the keyboard.

Unfortunately, it doesn't seem to be working, and I get an error message when trying to record:

Code: [Select]
Start recording...
Failed to save image "recordings/frame_00000.png"
Failed to save image "recordings/frame_00001.png"
Failed to save image "recordings/frame_00002.png"
Failed to save image "recordings/frame_00003.png"
Failed to save image "recordings/frame_00004.png"
Failed to save image "recordings/frame_00005.png"
Failed to save image "recordings/frame_00006.png"
Failed to save image "recordings/frame_00007.png"
Failed to save image "recordings/frame_00008.png"
Failed to save image "recordings/frame_00009.png"
Failed to save image "recordings/frame_00010.png"
Recording stopped.

Would somebody have an idea what the issue could be? In case it's necessary, I will attach the whole header file below. I've been sitting on this for a while now but my troubleshooting skills aren't necessary the best :(
Title: Re: Issues saving images when recording window
Post by: eXpl0it3r on September 08, 2023, 12:42:58 pm
Make sure the executable has the correct permission to write to the destination folder. Also make sure the directory recordings exists.

Depending on what you use it for, you might also be interested to just use OBS (https://obsproject.com/) to record your window.