ACMX 2.136.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,
11 std::string_view suffix) {
12 const fs::path output_path(filename);
13 const fs::path parent = output_path.has_parent_path()
14 ? output_path.parent_path()
15 : fs::path(".");
16 const std::string name = output_path.filename().empty()
17 ? std::string("output")
18 : output_path.filename().string();
19 return parent /
20 ("video_file-" + name + "-" + std::string(suffix));
21 }
22
23 void create_output_directory(const fs::path &directory) {
24 std::error_code error;
25 fs::create_directories(directory, error);
26 if (error || !fs::is_directory(directory)) {
27 throw std::runtime_error(
28 "unable to create PNG output directory: " +
29 directory.string());
30 }
31 }
32
33 fs::path frame_path(const fs::path &directory, std::uint64_t index) {
34 std::ostringstream filename;
35 filename << "frame-" << std::setfill('0') << std::setw(8) << index
36 << ".png";
37 return directory / filename.str();
38 }
39
40 std::string_view snapshot_extension(SnapshotFormat format) noexcept {
41 switch (format) {
43 return ".webp";
45 return ".tiff";
47 return ".raw";
49 return ".png";
50 }
51 return ".snapshot";
52 }
53
54 fs::path snapshot_path(
55 const fs::path &directory, std::uint32_t width, std::uint32_t height,
56 std::uint64_t &counter, SnapshotFormat format,
57 std::chrono::system_clock::time_point timestamp) {
58 const std::time_t timestamp_time =
59 std::chrono::system_clock::to_time_t(timestamp);
60 std::tm local_time{};
61#ifdef _WIN32
62 localtime_s(&local_time, &timestamp_time);
63#else
64 localtime_r(&timestamp_time, &local_time);
65#endif
66 while (true) {
67 std::ostringstream filename;
68 filename << "ACMXVK.Snapshot-"
69 << std::put_time(&local_time, "%Y.%m.%d-%H.%M.%S") << '-'
70 << width << 'x' << height << '-' << counter
71 << snapshot_extension(format);
72 const fs::path candidate = directory / filename.str();
73 if (!fs::exists(candidate)) {
74 return candidate;
75 }
76 ++counter;
77 }
78 }
79} // 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