diff --git a/demo/Makefile b/demo/Makefile index 818e5e1..151a1ff 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -9,7 +9,7 @@ SDLCONFIG = /home/frank/local/sdl/bin/sdl2-config CFLAGS = -Wall -O2 -c -I$(SFW_LIB_DIR) -I$(SFW_SRC_DIR) CPP_FLAGS = $(CFLAGS) --std=c++17 SDL_FLAGS = $(shell $(SDLCONFIG) --cflags) -LFLAGS = $(shell $(SDLCONFIG) --libs) +LFLAGS = $(shell $(SDLCONFIG) --libs) -lpthread export ANDROID_HOME = /home/frank/ext/software/android-sdk export ANDROID_NDK_HOME = /home/frank/ext/software/android-ndk-r8d BUILDDIR = build diff --git a/src/Recorder.cpp b/src/Recorder.cpp index 84a264a..e6becc1 100644 --- a/src/Recorder.cpp +++ b/src/Recorder.cpp @@ -56,13 +56,20 @@ void Recorder::end_recording() { std::cout << "Ending recording..." << std::endl; animation.reset(); - SDL_Surface* frame; nlohmann::json config = get_configuration(); fs::path root = config["path"]["video"]; fs::create_directories(root); fs::path directory = sfw::get_next_file_name(root, 5, "video-"); fs::create_directories(directory); + std::function f = std::bind(&Recorder::write_video_frames, this, std::placeholders::_1); + std::thread writing(f, directory); + writing.detach(); +} + +void Recorder::write_video_frames(fs::path directory) +{ std::cout << "Writing recording to " << directory << "..." << std::endl; + SDL_Surface* frame; for (int ii = 0; not frames.empty(); ii++) { frame = frames.front(); @@ -73,6 +80,7 @@ void Recorder::end_recording() frames.erase(frames.begin()); SDL_FreeSurface(frame); } + std::cout << "Wrote " << directory << std::endl; } void Recorder::update() diff --git a/src/Recorder.hpp b/src/Recorder.hpp index 8031ff4..1f94ca7 100644 --- a/src/Recorder.hpp +++ b/src/Recorder.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include "SDL.h" @@ -29,6 +31,7 @@ struct Recorder : Node void start_recording(); void add_frame_to_video(); void end_recording(); + void write_video_frames(fs::path); void update(); std::string get_class_name() { return "Recorder"; }