-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
606fcde
commit eddd618
Showing
13 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
## [Unreleased] | ||
### Added | ||
|
||
* Screenshot | ||
|
||
### Changed | ||
### Fixed | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright 2015-2023 Clément Gallet <[email protected]> | ||
This file is part of libTAS. | ||
libTAS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
libTAS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with libTAS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "Screenshot.h" | ||
|
||
#include "../logging.h" | ||
#include "../ScreenCapture.h" | ||
#include "NutMuxer.h" | ||
#include "../global.h" // Global::shared_config | ||
#include "../GlobalState.h" | ||
|
||
#include <cstdint> | ||
#include <sstream> | ||
|
||
namespace libtas { | ||
|
||
int Screenshot::save(const std::string& screenshotfile, bool draw) { | ||
|
||
if (!ScreenCapture::isInited()) { | ||
debuglogstdio(LCF_DUMP | LCF_ERROR, "Screen was not inited"); | ||
return ESCREENSHOT_NOSCREEN; | ||
} | ||
|
||
std::ostringstream commandline; | ||
commandline << "ffmpeg -loglevel warning -hide_banner -y -guess_layout_max 0 -f nut -i - -frames:v 1 -update 1 \""; | ||
commandline << screenshotfile; | ||
commandline << "\""; | ||
|
||
FILE *ffmpeg_pipe = nullptr; | ||
NATIVECALL(ffmpeg_pipe = popen(commandline.str().c_str(), "w")); | ||
|
||
if (! ffmpeg_pipe) { | ||
debuglogstdio(LCF_DUMP | LCF_ERROR, "Could not create a pipe to ffmpeg"); | ||
return ESCREENSHOT_NOPIPE; | ||
} | ||
|
||
int width, height; | ||
ScreenCapture::getDimensions(width, height); | ||
|
||
const char* pixfmt = ScreenCapture::getPixelFormat(); | ||
|
||
/* Initialize the muxer. Audio parameters don't matter here for screenshot */ | ||
NutMuxer* nutMuxer = new NutMuxer(width, height, Global::shared_config.framerate_num, Global::shared_config.framerate_den, pixfmt, 44100, 1, 1, ffmpeg_pipe); | ||
|
||
/* Access to the screen pixels, or last screen pixels if not a draw frame */ | ||
uint8_t* pixels = nullptr; | ||
int size = ScreenCapture::getPixelsFromSurface(&pixels, draw); | ||
|
||
debuglogstdio(LCF_DUMP, "Perform the screenshot"); | ||
nutMuxer->writeVideoFrame(pixels, size); | ||
|
||
if (ffmpeg_pipe) { | ||
int ret; | ||
NATIVECALL(ret = pclose(ffmpeg_pipe)); | ||
if (ret < 0) { | ||
debuglogstdio(LCF_DUMP | LCF_ERROR, "Could not close the pipe to ffmpeg"); | ||
return ESCREENSHOT_NOPIPE; | ||
} | ||
} | ||
|
||
return ESCREENSHOT_OK; | ||
} | ||
|
||
} | ||
|
||
// #endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright 2015-2023 Clément Gallet <[email protected]> | ||
This file is part of libTAS. | ||
libTAS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
libTAS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with libTAS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef LIBTAS_SCREENSHOT_H_INCL | ||
#define LIBTAS_SCREENSHOT_H_INCL | ||
|
||
#include <string> | ||
|
||
namespace libtas { | ||
namespace Screenshot { | ||
|
||
/* List of error codes */ | ||
enum Error { | ||
ESCREENSHOT_OK = 0, | ||
ESCREENSHOT_NOSCREEN = -1, // Screen Capture was not inited | ||
ESCREENSHOT_NOPIPE = -2, // Could not create a pipe to ffmpeg | ||
}; | ||
|
||
/* Save the screenshot to file, `draw` indicates if the current frame is | ||
* a draw frame. */ | ||
int save(const std::string& screenshotfile, bool draw); | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters