diff --git a/src/COMMON.h b/src/COMMON.h index 6a598bf..b59741e 100644 --- a/src/COMMON.h +++ b/src/COMMON.h @@ -61,10 +61,12 @@ using namespace glm; #define POPEN _popen #define PCLOSE _pclose #define PWRITE_MODE "wb" + #define PREAD_MODE "r" #else #define POPEN popen #define PCLOSE pclose #define PWRITE_MODE "w" + #define PREAD_MODE "r" #endif #define UV_VERTICES(uvMin, uvMax) \ diff --git a/src/ffmpeg.cpp b/src/ffmpeg.cpp index 5a7486f..97a6cac 100644 --- a/src/ffmpeg.cpp +++ b/src/ffmpeg.cpp @@ -30,20 +30,33 @@ ffmpeg_render break; } + // ffmpeg output will be piped into the log + std::string logOutput = " 2>> \"" + log_path_get() + "\""; + #if _WIN32 - command = string_quote(command); + command = string_quote(command) + logOutput; +#else + command += logOutput; #endif + log_command(command); + FILE* fp = POPEN(command.c_str(), PWRITE_MODE); if (!fp) { - log_info(std::format(FFMPEG_POPEN_ERROR, strerror(errno))); + log_error(std::format(FFMPEG_POPEN_ERROR, strerror(errno))); return false; } + size_t frameBytes = size.x * size.y * TEXTURE_CHANNELS; +// supposedly, might help with video corruption issues on windows? +#if _WIN32 + _setmode(_fileno(stdout), _O_BINARY); +#endif + for (const auto& frame : frames) { std::vector rgba = texture_download(&frame); diff --git a/src/ffmpeg.h b/src/ffmpeg.h index 2747a57..f96e3c1 100644 --- a/src/ffmpeg.h +++ b/src/ffmpeg.h @@ -4,6 +4,7 @@ #include "texture.h" #define FFMPEG_POPEN_ERROR "popen() (for FFmpeg) failed!\n{}" +#define FFMPEG_LOG_BUFFER_SIZE 256 static constexpr const char* FFMPEG_GIF_FORMAT = "\"{0}\" -y " diff --git a/src/log.cpp b/src/log.cpp index 761c681..537d166 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -2,7 +2,12 @@ inline std::ofstream logFile; -static void _log_write(const std::string& string) +std::string log_path_get(void) +{ + return preferences_path_get() + LOG_PATH; +} + +void log_write(const std::string& string) { std::println("{}", string); @@ -13,30 +18,36 @@ static void _log_write(const std::string& string) } } -void log_init(const std::string& file) +void log_init(void) { - logFile.open(file, std::ios::out | std::ios::trunc); - if (!logFile) std::println("{}", std::format(LOG_INIT_ERROR, file)); + std::string logFilepath = log_path_get(); + logFile.open(logFilepath, std::ios::out | std::ios::trunc); + if (!logFile) std::println("{}", std::format(LOG_INIT_ERROR, logFilepath)); } void log_error(const std::string& error) { - _log_write(LOG_ERROR_FORMAT + error); + log_write(LOG_ERROR_FORMAT + error); } void log_info(const std::string& info) { - _log_write(LOG_INFO_FORMAT + info); + log_write(LOG_INFO_FORMAT + info); } void log_warning(const std::string& warning) { - _log_write(LOG_WARNING_FORMAT + warning); + log_write(LOG_WARNING_FORMAT + warning); } void log_imgui(const std::string& imgui) { - _log_write(LOG_IMGUI_FORMAT + imgui); + log_write(LOG_IMGUI_FORMAT + imgui); +} + +void log_command(const std::string& command) +{ + log_write(LOG_COMMAND_FORMAT + command); } void log_free(void) diff --git a/src/log.h b/src/log.h index 3ef0fc6..3ac20d9 100644 --- a/src/log.h +++ b/src/log.h @@ -7,11 +7,15 @@ #define LOG_INFO_FORMAT "[INFO] " #define LOG_IMGUI_FORMAT "[IMGUI] " #define LOG_INIT_ERROR "[ERROR] Failed to open log file: {}" +#define LOG_COMMAND_FORMAT "[COMMAND] " #define LOG_PATH "log.txt" -void log_init(const std::string& file); +std::string log_path_get(void); +void log_init(void); +void log_write(const std::string& file); void log_error(const std::string& error); void log_info(const std::string& info); void log_warning(const std::string& warning); void log_imgui(const std::string& imgui); +void log_command(const std::string& command); void log_free(void); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index faf69f9..124247a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,7 @@ main(s32 argc, char* argv[]) { State state; - log_init(preferences_path_get() + LOG_PATH); + log_init(); if (argc > 0 && argv[1]) {