Use ctrl+c instead of closing window to stop recording

This commit is contained in:
dec05eba 2020-07-01 23:53:06 +02:00
parent 0ec013395f
commit ed52692324
2 changed files with 18 additions and 9 deletions

View File

@ -13,8 +13,9 @@ the fps remains at 30.
# Installation # Installation
gpu screen recorder can be built using [sibs](https://github.com/DEC05EBA/sibs) or if you are running Arch Linux, then you can find it on aur under the name gpu-screen-recorder-git (`yay -S gpu-screen-recorder-git`). gpu screen recorder can be built using [sibs](https://github.com/DEC05EBA/sibs) or if you are running Arch Linux, then you can find it on aur under the name gpu-screen-recorder-git (`yay -S gpu-screen-recorder-git`).
# Example # How to use
Run `interactive.sh` or run `gpu-screen-recorder -w 0x1c00001 -c mp4 -f 60 -a bluez_sink.00_18_09_8A_07_93.a2dp_sink.monitor > test_video.mp4` Run `interactive.sh` or run gpu-screen-recorder directly, for example: `gpu-screen-recorder -w 0x1c00001 -c mp4 -f 60 -a bluez_sink.00_18_09_8A_07_93.a2dp_sink.monitor > test_video.mp4`\
Then stop the screen recorder with Ctrl+C.
# Demo # Demo
[![Click here to watch a demo video on youtube](https://img.youtube.com/vi/n5tm0g01n6A/0.jpg)](https://www.youtube.com/watch?v=n5tm0g01n6A) [![Click here to watch a demo video on youtube](https://img.youtube.com/vi/n5tm0g01n6A/0.jpg)](https://www.youtube.com/watch?v=n5tm0g01n6A)

View File

@ -23,6 +23,7 @@
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <map> #include <map>
#include <signal.h>
#include <unistd.h> #include <unistd.h>
@ -529,7 +530,15 @@ static void usage() {
exit(1); exit(1);
} }
static sig_atomic_t running = 1;
static void int_handler(int dummy) {
running = 0;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
signal(SIGINT, int_handler);
std::map<std::string, std::string> args = { std::map<std::string, std::string> args = {
{ "-w", "" }, { "-w", "" },
{ "-c", "" }, { "-c", "" },
@ -606,8 +615,7 @@ int main(int argc, char **argv) {
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
GLFWwindow *window = GLFWwindow *window = glfwCreateWindow(32, 32, "gpu-screen-recorder", nullptr, nullptr);
glfwCreateWindow(1280, 720, "Hello world", nullptr, nullptr);
if (!window) { if (!window) {
fprintf(stderr, "Error: Failed to create glfw window\n"); fprintf(stderr, "Error: Failed to create glfw window\n");
glfwTerminate(); glfwTerminate();
@ -616,6 +624,7 @@ int main(int argc, char **argv) {
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
glfwSwapInterval(0); glfwSwapInterval(0);
glfwHideWindow(window);
#if defined(DEBUG) #if defined(DEBUG)
XSetErrorHandler(x11_error_handler); XSetErrorHandler(x11_error_handler);
@ -784,8 +793,7 @@ int main(int argc, char **argv) {
std::mutex write_output_mutex; std::mutex write_output_mutex;
bool running = true; std::thread audio_thread([](AVFormatContext *av_format_context, AVStream *audio_stream, AVPacket *audio_packet, uint8_t *audio_frame_buf, SoundDevice *sound_device, AVFrame *audio_frame, std::mutex *write_output_mutex) mutable {
std::thread audio_thread([&running](AVFormatContext *av_format_context, AVStream *audio_stream, AVPacket *audio_packet, uint8_t *audio_frame_buf, SoundDevice *sound_device, AVFrame *audio_frame, std::mutex *write_output_mutex) mutable {
SwrContext *swr = swr_alloc(); SwrContext *swr = swr_alloc();
if(!swr) { if(!swr) {
fprintf(stderr, "Failed to create SwrContext\n"); fprintf(stderr, "Failed to create SwrContext\n");
@ -834,7 +842,7 @@ int main(int argc, char **argv) {
bool redraw = true; bool redraw = true;
XEvent e; XEvent e;
while (!glfwWindowShouldClose(window)) { while (running) {
double frame_start = glfwGetTime(); double frame_start = glfwGetTime();
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -962,7 +970,7 @@ int main(int argc, char **argv) {
usleep(sleep_time * 1000.0 * 1000.0); usleep(sleep_time * 1000.0 * 1000.0);
} }
running = false; running = 0;
audio_thread.join(); audio_thread.join();
sound_device_close(&sound_device); sound_device_close(&sound_device);