ACMX 2.139.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
output_paths.cpp
Go to the documentation of this file.
1#include "output_paths.hpp"
2
3#include <ctime>
4#include <iomanip>
5#include <sstream>
6#include <stdexcept>
7#include <system_error>
8
9namespace acmxvk {
10 fs::path output_frame_directory(const std::string &filename, std::string_view suffix) {
11 const fs::path output_path(filename);
12 const fs::path parent = output_path.has_parent_path() ? output_path.parent_path() : fs::path(".");
13 const std::string name = output_path.filename().empty() ? std::string("output") : output_path.filename().string();
14 return parent / ("video_file-" + name + "-" + std::string(suffix));
15 }
16
17 void create_output_directory(const fs::path &directory) {
18 std::error_code error;
19 fs::create_directories(directory, error);
20 if (error || !fs::is_directory(directory)) {
21 throw std::runtime_error("unable to create PNG output directory: " + directory.string());
22 }
23 }
24
25 fs::path frame_path(const fs::path &directory, std::uint64_t index) {
26 std::ostringstream filename;
27 filename << "frame-" << std::setfill('0') << std::setw(8) << index << ".png";
28 return directory / filename.str();
29 }
30
31 std::string_view snapshot_extension(SnapshotFormat format) noexcept {
32 switch (format) {
34 return ".webp";
36 return ".tiff";
38 return ".raw";
40 return ".png";
41 }
42 return ".snapshot";
43 }
44
45 fs::path snapshot_path(const fs::path &directory, std::uint32_t width, std::uint32_t height, std::uint64_t &counter, SnapshotFormat format, std::chrono::system_clock::time_point timestamp) {
46 const std::time_t timestamp_time = std::chrono::system_clock::to_time_t(timestamp);
47 std::tm local_time{};
48#ifdef _WIN32
49 localtime_s(&local_time, &timestamp_time);
50#else
51 localtime_r(&timestamp_time, &local_time);
52#endif
53 while (true) {
54 std::ostringstream filename;
55 filename << "ACMXVK.Snapshot-" << std::put_time(&local_time, "%Y.%m.%d-%H.%M.%S") << '-' << width << 'x' << height << '-' << counter << snapshot_extension(format);
56 const fs::path candidate = directory / filename.str();
57 if (!fs::exists(candidate)) {
58 return candidate;
59 }
60 ++counter;
61 }
62 }
63} // namespace acmxvk
fs::path snapshot_path(const fs::path &directory, std::uint32_t width, std::uint32_t height, std::uint64_t &counter, SnapshotFormat format, std::chrono::system_clock::time_point timestamp)
fs::path output_frame_directory(const std::string &filename, std::string_view suffix)
fs::path frame_path(const fs::path &directory, std::uint64_t index)
void create_output_directory(const fs::path &directory)
std::string_view snapshot_extension(SnapshotFormat format) noexcept