write video frames in separate thread
This commit is contained in:
parent
10cc649f45
commit
9210b3fcf4
|
@ -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
|
||||
|
|
|
@ -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<void(fs::path)> 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()
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <functional>
|
||||
|
||||
#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"; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue