tick/fps difference in render animation; touched up

This commit is contained in:
shweet committed 2026-07-10 21:21:25 -04:00
1 parent c5a9ab8119
commit c28ea8eb6f
8 files changed
+208 -145

No files matched your search

+127 -85
View File
@@ -49,8 +49,10 @@ namespace anm2ed::imgui
return directory; return directory;
} }
std::filesystem::path render_frame_filename(const std::filesystem::path& format, int index) std::filesystem::path render_frame_filename(const std::filesystem::path& format, int index, int type)
{ {
if (type != render::PNGS) return path::from_utf8(std::format("frame_{:06}.png", index));
auto formatString = path::to_utf8(format); auto formatString = path::to_utf8(format);
try try
{ {
@@ -108,6 +110,26 @@ namespace anm2ed::imgui
pixels[index + 2] = (uint8_t)glm::clamp((float)std::round((float)pixels[index + 2] / alphaUnit), 0.0f, 255.0f); pixels[index + 2] = (uint8_t)glm::clamp((float)std::round((float)pixels[index + 2] / alphaUnit), 0.0f, 255.0f);
} }
} }
int trigger_sound_id_get(Document& document, Element* animation, float time, int deterministicIndex = -1)
{
if (!animation) return -1;
auto triggers = animation_item_get(*animation, ItemType::TRIGGER);
if (!triggers || !triggers->isVisible) return -1;
auto trigger = frame_generate(*triggers, time);
if (!trigger.isVisible || trigger.soundIds.empty()) return -1;
size_t soundIndex{};
if (trigger.soundIds.size() > 1)
soundIndex = deterministicIndex >= 0 ? (size_t)deterministicIndex % trigger.soundIds.size()
: (size_t)math::random_in_range(0.0f, (float)trigger.soundIds.size());
soundIndex = std::min(soundIndex, trigger.soundIds.size() - 1);
auto soundID = trigger.soundIds[soundIndex];
return document.sound_get(soundID) ? soundID : -1;
}
bool render_audio_stream_generate(AudioStream& audioStream, std::map<int, Audio>& sounds, bool render_audio_stream_generate(AudioStream& audioStream, std::map<int, Audio>& sounds,
const std::vector<int>& frameSoundIDs, int fps) const std::vector<int>& frameSoundIDs, int fps)
{ {
@@ -164,7 +186,6 @@ namespace anm2ed::imgui
auto& anm2 = document.anm2; auto& anm2 = document.anm2;
auto& playback = document.playback; auto& playback = document.playback;
auto& frameTime = document.frameTime; auto& frameTime = document.frameTime;
auto& end = manager.recordingEnd;
auto& zoom = document.previewZoom; auto& zoom = document.previewZoom;
auto& overlayIndex = document.overlayIndex; auto& overlayIndex = document.overlayIndex;
auto& pan = document.previewPan; auto& pan = document.previewPan;
@@ -175,29 +196,12 @@ namespace anm2ed::imgui
sound.stop(mixer); sound.stop(mixer);
}; };
auto trigger_sound_id_get = [&](Element* animation, float time)
{
if (!animation) return -1;
auto triggers = animation_item_get(*animation, ItemType::TRIGGER);
if (!triggers || !triggers->isVisible) return -1;
auto trigger = frame_generate(*triggers, time);
if (!trigger.isVisible || trigger.soundIds.empty()) return -1;
auto soundIndex =
trigger.soundIds.size() > 1 ? (size_t)math::random_in_range(0.0f, (float)trigger.soundIds.size()) : (size_t)0;
soundIndex = std::min(soundIndex, trigger.soundIds.size() - 1);
auto soundID = trigger.soundIds[soundIndex];
return document.sound_get(soundID) ? soundID : -1;
};
if (manager.isRecording) if (manager.isRecording)
{ {
auto& ffmpegPath = settings.renderFFmpegPath; auto& ffmpegPath = settings.renderFFmpegPath;
auto& path = settings.renderPath; auto& path = settings.renderPath;
auto pathString = path::to_utf8(path); auto pathString = path::to_utf8(path);
auto& type = settings.renderType; auto& type = settings.renderType;
auto renderFrameRate = std::max(settings.playbackTickRate, 1);
auto isRenderPreviewOverridden = settings.renderIsUseAnimationBounds || settings.renderIsUseIsolatedAnimation; auto isRenderPreviewOverridden = settings.renderIsUseAnimationBounds || settings.renderIsUseIsolatedAnimation;
auto render_preview_restore = [&]() auto render_preview_restore = [&]()
{ {
@@ -212,10 +216,8 @@ namespace anm2ed::imgui
isCheckerPanInitialized = false; isCheckerPanInitialized = false;
}; };
if (playback.time >= (float)end + 1.0f || playback.isFinished) if (renderFrameIndex >= renderFrameCount)
{ {
if (settings.timelineIsSound) audioStream.capture_end(mixer);
if (type == render::PNGS) if (type == render::PNGS)
{ {
if (!renderTempFrames.empty()) if (!renderTempFrames.empty())
@@ -310,8 +312,7 @@ namespace anm2ed::imgui
else else
audioStream.stream.clear(); audioStream.stream.clear();
if (animation_render(ffmpegPath, path, renderTempFrames, renderTempFrameDurations, audioStream, if (animation_render(ffmpegPath, path, renderTempFrames, audioStream, (render::Type)type, renderFrameRate))
(render::Type)type, renderFrameRate))
{ {
toasts.push(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION), std::make_format_args(pathString))); toasts.push(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION), std::make_format_args(pathString)));
logger.info(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION, anm2ed::ENGLISH), logger.info(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION, anm2ed::ENGLISH),
@@ -330,13 +331,11 @@ namespace anm2ed::imgui
{ {
renderTempDirectory.clear(); renderTempDirectory.clear();
renderTempFrames.clear(); renderTempFrames.clear();
renderTempFrameDurations.clear();
renderFrameSoundIDs.clear(); renderFrameSoundIDs.clear();
} }
else else
{ {
render_temp_cleanup(renderTempDirectory, renderTempFrames); render_temp_cleanup(renderTempDirectory, renderTempFrames);
renderTempFrameDurations.clear();
renderFrameSoundIDs.clear(); renderFrameSoundIDs.clear();
} }
@@ -345,49 +344,14 @@ namespace anm2ed::imgui
playback.isPlaying = false; playback.isPlaying = false;
playback.isFinished = false; playback.isFinished = false;
manager.isRecording = false; manager.isRecording = false;
manager.isRecordingStart = false;
renderFrameIndex = 0;
renderFrameCount = 0;
manager.progressPopup.close(); manager.progressPopup.close();
} }
else stop_all_sounds();
{ wasPlaybackPlaying = false;
if (settings.timelineIsSound && renderTempFrames.empty()) audioStream.capture_begin(mixer); return;
auto frameSoundID = -1;
if (settings.timelineIsSound && !document.sounds.empty())
{
auto soundTime = (int)std::floor(playback.time);
auto animation = anm2.element_get(ElementType::ANIMATION, document.reference.animationIndex);
if (soundTime != renderFrameSoundTimePrev && animation)
frameSoundID = trigger_sound_id_get(animation, playback.time);
renderFrameSoundTimePrev = soundTime;
}
renderFrameSoundIDs.push_back(frameSoundID);
bind();
auto pixels = pixels_get();
if (isRenderPreviewOverridden) pixels_unpremultiply_alpha(pixels);
auto frameIndex = (int)renderTempFrames.size();
auto framePath = renderTempDirectory / render_frame_filename(settings.renderFormat, frameIndex);
if (Texture::write_pixels_png(framePath, size, pixels.data()))
{
renderTempFrames.push_back(framePath);
auto fallbackDuration = 1.0 / (double)renderFrameRate;
renderTempFrameDurations.push_back(fallbackDuration);
}
else
{
toasts.push(
std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED), std::make_format_args(pathString)));
logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED, anm2ed::ENGLISH),
std::make_format_args(pathString)));
if (type != render::PNGS) render_temp_cleanup(renderTempDirectory, renderTempFrames);
renderTempFrameDurations.clear();
renderFrameSoundIDs.clear();
render_preview_restore();
playback.isPlaying = false;
playback.isFinished = false;
manager.isRecording = false;
manager.progressPopup.close();
}
}
} }
if (playback.isPlaying) if (playback.isPlaying)
@@ -405,7 +369,7 @@ namespace anm2ed::imgui
{ {
if (!manager.isRecording && !document.sounds.empty() && isSound) if (!manager.isRecording && !document.sounds.empty() && isSound)
{ {
if (auto soundID = trigger_sound_id_get(animation, playback.time); soundID != -1) if (auto soundID = trigger_sound_id_get(document, animation, playback.time); soundID != -1)
if (auto sound = document.sound_get(soundID)) sound->play(false, mixer); if (auto sound = document.sound_get(soundID)) sound->play(false, mixer);
} }
@@ -667,8 +631,13 @@ namespace anm2ed::imgui
manager.isRecordingStart = false; manager.isRecordingStart = false;
manager.isRecording = true; manager.isRecording = true;
renderFrameIndex = 0;
auto info = element_first_get(anm2.root, ElementType::INFO);
renderAnimationFps = std::max(info ? info->fps : 30, 1);
renderFrameRate = render::fps_get(settings.renderFpsMode, renderAnimationFps, settings.playbackTickRate);
renderFrameCount =
render::frame_count_get(manager.recordingStart, manager.recordingEnd, renderAnimationFps, renderFrameRate);
renderTempFrames.clear(); renderTempFrames.clear();
renderTempFrameDurations.clear();
renderFrameSoundIDs.clear(); renderFrameSoundIDs.clear();
renderFrameSoundTimePrev = -1; renderFrameSoundTimePrev = -1;
if (settings.renderType == render::PNGS) if (settings.renderType == render::PNGS)
@@ -703,6 +672,9 @@ namespace anm2ed::imgui
logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED, anm2ed::ENGLISH), logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED, anm2ed::ENGLISH),
std::make_format_args(pathString))); std::make_format_args(pathString)));
manager.isRecording = false; manager.isRecording = false;
manager.isRecordingStart = false;
renderFrameIndex = 0;
renderFrameCount = 0;
manager.progressPopup.close(); manager.progressPopup.close();
playback.isPlaying = false; playback.isPlaying = false;
playback.isFinished = false; playback.isFinished = false;
@@ -710,7 +682,18 @@ namespace anm2ed::imgui
} }
playback.isPlaying = true; playback.isPlaying = true;
playback.timing_reset(); playback.timing_reset();
playback.time = manager.recordingStart; playback.time =
render::frame_time_get(manager.recordingStart, renderFrameIndex, renderAnimationFps, renderFrameRate);
document.frameTime = playback.time;
}
if (manager.isRecording && renderFrameIndex < renderFrameCount)
{
playback.isPlaying = true;
playback.isFinished = false;
playback.time =
render::frame_time_get(manager.recordingStart, renderFrameIndex, renderAnimationFps, renderFrameRate);
document.frameTime = playback.time;
} }
if (isSizeTrySet) if (isSizeTrySet)
@@ -1126,6 +1109,61 @@ namespace anm2ed::imgui
settings.onionskinMode == (int)OnionskinMode::INDEX); settings.onionskinMode == (int)OnionskinMode::INDEX);
} }
if (manager.isRecording && renderFrameIndex < renderFrameCount)
{
auto renderType = settings.renderType;
auto isRenderPreviewOverridden = settings.renderIsUseAnimationBounds || settings.renderIsUseIsolatedAnimation;
auto render_capture_fail = [&]()
{
auto pathString = path::to_utf8(settings.renderPath);
toasts.push(
std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED), std::make_format_args(pathString)));
logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED, anm2ed::ENGLISH),
std::make_format_args(pathString)));
if (renderType != render::PNGS) render_temp_cleanup(renderTempDirectory, renderTempFrames);
renderFrameSoundIDs.clear();
if (isRenderPreviewOverridden)
{
settings = savedSettings;
pan = savedPan;
zoom = savedZoom;
overlayIndex = savedOverlayIndex;
isSizeTrySet = true;
hasPendingZoomPanAdjust = false;
isCheckerPanInitialized = false;
}
playback.isPlaying = false;
playback.isFinished = false;
manager.isRecording = false;
manager.isRecordingStart = false;
renderFrameIndex = 0;
renderFrameCount = 0;
manager.progressPopup.close();
};
auto frameSoundID = -1;
if (settings.timelineIsSound && !document.sounds.empty())
{
auto soundTime = (int)std::floor(frameTime);
if (soundTime != renderFrameSoundTimePrev && animation)
frameSoundID = trigger_sound_id_get(document, animation, frameTime, renderFrameIndex);
renderFrameSoundTimePrev = soundTime;
}
renderFrameSoundIDs.push_back(frameSoundID);
auto pixels = pixels_get();
if (isRenderPreviewOverridden) pixels_unpremultiply_alpha(pixels);
auto framePath =
renderTempDirectory / render_frame_filename(settings.renderFormat, renderFrameIndex, settings.renderType);
if (Texture::write_pixels_png(framePath, size, pixels.data()))
{
renderTempFrames.push_back(framePath);
++renderFrameIndex;
}
else
render_capture_fail();
}
unbind(); unbind();
if (isTransparent) if (isTransparent)
@@ -1494,9 +1532,7 @@ namespace anm2ed::imgui
if (ImGui::BeginPopupModal(manager.progressPopup.label(), &manager.progressPopup.isOpen, ImGuiWindowFlags_NoResize)) if (ImGui::BeginPopupModal(manager.progressPopup.label(), &manager.progressPopup.isOpen, ImGuiWindowFlags_NoResize))
{ {
auto& start = manager.recordingStart; auto progress = renderFrameCount > 0 ? (float)renderFrameIndex / (float)renderFrameCount : 0.0f;
auto& end = manager.recordingEnd;
auto progress = (playback.time - start) / (end - start);
ImGui::ProgressBar(progress); ImGui::ProgressBar(progress);
@@ -1505,31 +1541,37 @@ namespace anm2ed::imgui
shortcut(manager.chords[SHORTCUT_CANCEL]); shortcut(manager.chords[SHORTCUT_CANCEL]);
if (ImGui::Button(localize.get(BASIC_CANCEL), ImVec2(ImGui::GetContentRegionAvail().x, 0))) if (ImGui::Button(localize.get(BASIC_CANCEL), ImVec2(ImGui::GetContentRegionAvail().x, 0)))
{ {
if (settings.renderType == render::PNGS) auto renderType = settings.renderType;
auto isRenderPreviewOverridden = settings.renderIsUseAnimationBounds || settings.renderIsUseIsolatedAnimation;
if (renderType == render::PNGS)
{ {
renderTempDirectory.clear(); renderTempDirectory.clear();
renderTempFrames.clear(); renderTempFrames.clear();
renderTempFrameDurations.clear(); renderFrameSoundIDs.clear();
} }
else else
{ {
render_temp_cleanup(renderTempDirectory, renderTempFrames); render_temp_cleanup(renderTempDirectory, renderTempFrames);
renderTempFrameDurations.clear(); renderFrameSoundIDs.clear();
} }
pan = savedPan; if (isRenderPreviewOverridden)
zoom = savedZoom; {
settings = savedSettings; pan = savedPan;
overlayIndex = savedOverlayIndex; zoom = savedZoom;
isSizeTrySet = true; settings = savedSettings;
hasPendingZoomPanAdjust = false; overlayIndex = savedOverlayIndex;
isCheckerPanInitialized = false; isSizeTrySet = true;
hasPendingZoomPanAdjust = false;
if (settings.timelineIsSound) audioStream.capture_end(mixer); isCheckerPanInitialized = false;
}
playback.isPlaying = false; playback.isPlaying = false;
playback.isFinished = false; playback.isFinished = false;
manager.isRecording = false; manager.isRecording = false;
manager.isRecordingStart = false;
renderFrameIndex = 0;
renderFrameCount = 0;
manager.progressPopup.close(); manager.progressPopup.close();
} }
+4 -1
View File
@@ -33,8 +33,11 @@ namespace anm2ed::imgui
glm::vec2 nullRectScaleAnchor{}; glm::vec2 nullRectScaleAnchor{};
std::filesystem::path renderTempDirectory{}; std::filesystem::path renderTempDirectory{};
std::vector<std::filesystem::path> renderTempFrames{}; std::vector<std::filesystem::path> renderTempFrames{};
std::vector<double> renderTempFrameDurations{};
std::vector<int> renderFrameSoundIDs{}; std::vector<int> renderFrameSoundIDs{};
int renderFrameIndex{};
int renderFrameCount{};
int renderFrameRate{1};
int renderAnimationFps{1};
int renderFrameSoundTimePrev{-1}; int renderFrameSoundTimePrev{-1};
public: public:
+29 -2
View File
@@ -8,6 +8,7 @@
#include "log.hpp" #include "log.hpp"
#include "path.hpp" #include "path.hpp"
#include "process.hpp" #include "process.hpp"
#include "render.hpp"
#include "toast.hpp" #include "toast.hpp"
#include "util/imgui/input.hpp" #include "util/imgui/input.hpp"
#include "util/imgui/layout.hpp" #include "util/imgui/layout.hpp"
@@ -77,6 +78,7 @@ namespace anm2ed::imgui::wizard
auto& path = settings.renderPath; auto& path = settings.renderPath;
auto& format = settings.renderFormat; auto& format = settings.renderFormat;
auto& scale = settings.renderScale; auto& scale = settings.renderScale;
auto& renderFpsMode = settings.renderFpsMode;
auto& isUseAnimationBounds = settings.renderIsUseAnimationBounds; auto& isUseAnimationBounds = settings.renderIsUseAnimationBounds;
auto& isUseIsolatedAnimation = settings.renderIsUseIsolatedAnimation; auto& isUseIsolatedAnimation = settings.renderIsUseIsolatedAnimation;
auto& type = settings.renderType; auto& type = settings.renderType;
@@ -91,7 +93,17 @@ namespace anm2ed::imgui::wizard
auto frameMax = animationFrameNum - 1; auto frameMax = animationFrameNum - 1;
start = std::clamp(start, 0, frameMax); start = std::clamp(start, 0, frameMax);
end = std::clamp(end, start, frameMax); end = std::clamp(end, start, frameMax);
auto renderFrameNum = isRange ? render::frame_count_get(start, end) : animationFrameNum; auto info = element_first_get(document.anm2.root, ElementType::INFO);
auto animationFps = std::max(info ? info->fps : 30, 1);
if (renderFpsMode < render::FPS_ANIMATION || renderFpsMode >= render::FPS_COUNT)
renderFpsMode = render::FPS_ANIMATION;
auto renderFps = render::fps_get(renderFpsMode, animationFps, settings.playbackTickRate);
auto render_frame_count_get = [&]()
{
if (isRange) return render::frame_count_get(start, end, animationFps, renderFps);
return render::frame_count_get(0, frameMax, animationFps, renderFps);
};
auto renderFrameNum = render_frame_count_get();
auto widgetSize = widget_size_with_row_get(2); auto widgetSize = widget_size_with_row_get(2);
@@ -196,7 +208,7 @@ namespace anm2ed::imgui::wizard
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_END)); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_END));
} }
ImGui::EndDisabled(); ImGui::EndDisabled();
renderFrameNum = isRange ? render::frame_count_get(start, end) : animationFrameNum; renderFrameNum = render_frame_count_get();
if (type == render::SPRITESHEET) if (type == render::SPRITESHEET)
{ {
@@ -224,6 +236,21 @@ namespace anm2ed::imgui::wizard
ImGui::Separator(); ImGui::Separator();
const char* renderFpsOptions[] = {localize.get(LABEL_ANIMATION_FPS), localize.get(LABEL_PLAYBACK_RATE)};
ImGui::Combo(localize.get(LABEL_RENDER_FPS), &renderFpsMode, renderFpsOptions, IM_ARRAYSIZE(renderFpsOptions));
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_RENDER_FPS));
renderFps = render::fps_get(renderFpsMode, animationFps, settings.playbackTickRate);
renderFrameNum = render_frame_count_get();
if (type == render::SPRITESHEET)
{
auto layout = render::spritesheet_layout_get(rows, columns, renderFrameNum);
rows = layout.rows;
columns = layout.columns;
}
ImGui::Separator();
ImGui::Checkbox(localize.get(LABEL_SOUND), &settings.timelineIsSound); ImGui::Checkbox(localize.get(LABEL_SOUND), &settings.timelineIsSound);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SOUND)); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SOUND));
+7 -54
View File
@@ -4,7 +4,6 @@
#include <cstring> #include <cstring>
#include <filesystem> #include <filesystem>
#include <format> #include <format>
#include <functional>
#include <fstream> #include <fstream>
#include <string> #include <string>
@@ -22,25 +21,9 @@ using namespace anm2ed::util;
namespace anm2ed namespace anm2ed
{ {
namespace
{
std::string ffmpeg_concat_escape(const std::string& value)
{
std::string escaped{};
escaped.reserve(value.size());
for (auto character : value)
{
if (character == '\'') escaped += "'\\''";
else
escaped += character;
}
return escaped;
}
}
bool animation_render(const std::filesystem::path& ffmpegPath, const std::filesystem::path& path, bool animation_render(const std::filesystem::path& ffmpegPath, const std::filesystem::path& path,
const std::vector<std::filesystem::path>& framePaths, const std::vector<std::filesystem::path>& framePaths, AudioStream& audioStream,
const std::vector<double>& frameDurations, AudioStream& audioStream, render::Type type, int fps) render::Type type, int fps)
{ {
if (framePaths.empty() || ffmpegPath.empty() || path.empty()) return false; if (framePaths.empty() || ffmpegPath.empty() || path.empty()) return false;
fps = std::max(fps, 1); fps = std::max(fps, 1);
@@ -120,39 +103,17 @@ namespace anm2ed
} }
} }
auto framesListPath = temporaryDirectory / path::from_utf8(std::format( auto framePattern = temporaryDirectory / path::from_utf8("frame_%06d.png");
"anm2ed_frames_{}_{}.txt", std::hash<std::string>{}(pathString), SDL_GetTicks())) ; auto framePatternString = path::to_utf8(framePattern);
std::ofstream framesListFile(framesListPath); command = std::format("\"{0}\" -y -framerate {1} -start_number 0 -i \"{2}\"", ffmpegPathString, fps,
if (!framesListFile) framePatternString);
{
audio_remove();
return false;
}
auto defaultFrameDuration = 1.0 / (double)fps;
for (std::size_t index = 0; index < framePaths.size(); ++index)
{
auto framePath = framePaths[index];
auto framePathString = path::to_utf8(framePath);
auto frameDuration = defaultFrameDuration;
if (index < frameDurations.size() && frameDurations[index] > 0.0) frameDuration = frameDurations[index];
framesListFile << "file '" << ffmpeg_concat_escape(framePathString) << "'\n";
framesListFile << "duration " << std::format("{:.9f}", frameDuration) << "\n";
}
auto lastFramePathString = path::to_utf8(framePaths.back());
framesListFile << "file '" << ffmpeg_concat_escape(lastFramePathString) << "'\n";
framesListFile.close();
auto framesListPathString = path::to_utf8(framesListPath);
command = std::format("\"{0}\" -y -f concat -safe 0 -i \"{1}\"", ffmpegPathString, framesListPathString);
if (!audioInputArguments.empty()) command += " " + audioInputArguments; if (!audioInputArguments.empty()) command += " " + audioInputArguments;
if (type != render::GIF) command += std::format(" -fps_mode cfr -r {}", fps); command += std::format(" -fps_mode cfr -r {}", fps);
switch (type) switch (type)
{ {
case render::GIF: case render::GIF:
command += " -fps_mode vfr";
command += command +=
" -lavfi \"split[s0][s1];[s0]palettegen=stats_mode=full:reserve_transparent=1[p];" " -lavfi \"split[s0][s1];[s0]palettegen=stats_mode=full:reserve_transparent=1[p];"
"[s1][p]paletteuse=dither=floyd_steinberg:alpha_threshold=128\"" "[s1][p]paletteuse=dither=floyd_steinberg:alpha_threshold=128\""
@@ -172,8 +133,6 @@ namespace anm2ed
break; break;
default: default:
{ {
std::error_code ec;
std::filesystem::remove(framesListPath, ec);
return false; return false;
} }
} }
@@ -192,8 +151,6 @@ namespace anm2ed
if (!process.get()) if (!process.get())
{ {
std::error_code ec;
std::filesystem::remove(framesListPath, ec);
audio_remove(); audio_remove();
return false; return false;
} }
@@ -202,14 +159,10 @@ namespace anm2ed
if (ffmpegExitCode != 0) if (ffmpegExitCode != 0)
{ {
logger.error(std::format("FFmpeg exited with code {} while exporting {}", ffmpegExitCode, pathString)); logger.error(std::format("FFmpeg exited with code {} while exporting {}", ffmpegExitCode, pathString));
std::error_code ec;
std::filesystem::remove(framesListPath, ec);
audio_remove(); audio_remove();
return false; return false;
} }
std::error_code ec;
std::filesystem::remove(framesListPath, ec);
audio_remove(); audio_remove();
return true; return true;
} }
+35 -2
View File
@@ -23,6 +23,13 @@ namespace anm2ed::render
COUNT COUNT
}; };
enum FpsMode
{
FPS_ANIMATION,
FPS_PLAYBACK_RATE,
FPS_COUNT
};
constexpr const char* STRINGS[] = { constexpr const char* STRINGS[] = {
#define X(symbol, string, extension) string, #define X(symbol, string, extension) string,
RENDER_LIST RENDER_LIST
@@ -43,6 +50,33 @@ namespace anm2ed::render
inline int frame_count_get(int start, int end) { return std::max(end - start + 1, 1); } inline int frame_count_get(int start, int end) { return std::max(end - start + 1, 1); }
inline int frame_count_get(int start, int end, int animationFps, int renderFps)
{
animationFps = std::max(animationFps, 1);
renderFps = std::max(renderFps, 1);
auto duration = (double)frame_count_get(start, end) / (double)animationFps;
return std::max((int)std::ceil(duration * (double)renderFps), 1);
}
inline float frame_time_get(int start, int frameIndex, int animationFps, int renderFps)
{
animationFps = std::max(animationFps, 1);
renderFps = std::max(renderFps, 1);
return (float)start + ((float)frameIndex * ((float)animationFps / (float)renderFps));
}
inline int fps_get(int mode, int animationFps, int playbackRate)
{
switch (mode)
{
case FPS_PLAYBACK_RATE:
return std::max(playbackRate, 1);
case FPS_ANIMATION:
default:
return std::max(animationFps, 1);
}
}
inline SpritesheetLayout spritesheet_layout_get(int rows, int columns, int frameCount) inline SpritesheetLayout spritesheet_layout_get(int rows, int columns, int frameCount)
{ {
frameCount = std::max(frameCount, 1); frameCount = std::max(frameCount, 1);
@@ -74,6 +108,5 @@ namespace anm2ed
{ {
std::filesystem::path ffmpeg_log_path(); std::filesystem::path ffmpeg_log_path();
bool animation_render(const std::filesystem::path&, const std::filesystem::path&, bool animation_render(const std::filesystem::path&, const std::filesystem::path&,
const std::vector<std::filesystem::path>&, const std::vector<double>&, AudioStream&, const std::vector<std::filesystem::path>&, AudioStream&, render::Type, int);
render::Type, int);
} }
+4
View File
@@ -304,6 +304,7 @@ namespace anm2ed
X(LABEL_FORMAT, "Format", "Formato", "Формат", "格式", "파일 포맷") \ X(LABEL_FORMAT, "Format", "Formato", "Формат", "格式", "파일 포맷") \
X(LABEL_FRAGMENT, "Fragment", "Fragment", "Fragment", "Fragment", "Fragment") \ X(LABEL_FRAGMENT, "Fragment", "Fragment", "Fragment", "Fragment", "Fragment") \
X(LABEL_FPS, "FPS", "FPS", "FPS", "FPS", "FPS") \ X(LABEL_FPS, "FPS", "FPS", "FPS", "FPS", "FPS") \
X(LABEL_ANIMATION_FPS, "Animation FPS", "Animation FPS", "Animation FPS", "Animation FPS", "Animation FPS") \
X(LABEL_FRAME_PROPERTIES_WINDOW, "Frame Properties###Frame Properties", "Propiedades de Frame###Frame Properties", "Свойства кадра###Frame Properties", "帧属性###Frame Properties", "프레임 속성###Frame Properties") \ X(LABEL_FRAME_PROPERTIES_WINDOW, "Frame Properties###Frame Properties", "Propiedades de Frame###Frame Properties", "Свойства кадра###Frame Properties", "帧属性###Frame Properties", "프레임 속성###Frame Properties") \
X(LABEL_GENERATE, "Generate", "Generar", "Сгенерировать", "生成", "생성") \ X(LABEL_GENERATE, "Generate", "Generar", "Сгенерировать", "生成", "생성") \
X(LABEL_GENERATE_COLUMNS, "Columns", "Columnas", "Колонны", "列", "열") \ X(LABEL_GENERATE_COLUMNS, "Columns", "Columnas", "Колонны", "列", "열") \
@@ -375,9 +376,11 @@ namespace anm2ed
X(LABEL_PLAY, "Play", "Reproducir", "Возпроизвести", "播放", "재생") \ X(LABEL_PLAY, "Play", "Reproducir", "Возпроизвести", "播放", "재생") \
X(LABEL_PLAYBACK_ALWAYS_LOOP, "Always Loop", "Siempre Loopear", "Всегда воспроизводить циклично", "持续循环", "항상 반복") \ X(LABEL_PLAYBACK_ALWAYS_LOOP, "Always Loop", "Siempre Loopear", "Всегда воспроизводить циклично", "持续循环", "항상 반복") \
X(LABEL_PLAYBACK_MENU, "Playback", "Reproduccion", "Возпроизведение", "回放", "재생") \ X(LABEL_PLAYBACK_MENU, "Playback", "Reproduccion", "Возпроизведение", "回放", "재생") \
X(LABEL_PLAYBACK_RATE, "Playback Rate", "Playback Rate", "Playback Rate", "Playback Rate", "Playback Rate") \
X(LABEL_PREPEND_FRAMES, "Prepend Frames", "Anteponer Frames", "Добавить кадры", "在前面插入帧", "뒷프레임에 추가") \ X(LABEL_PREPEND_FRAMES, "Prepend Frames", "Anteponer Frames", "Добавить кадры", "在前面插入帧", "뒷프레임에 추가") \
X(LABEL_RECT, "Rect", "Rect", "Прямоугольник", "矩形", "사각형") \ X(LABEL_RECT, "Rect", "Rect", "Прямоугольник", "矩形", "사각형") \
X(LABEL_RENDER, "Render", "Renderizar", "Рендер", "渲染", "렌더링") \ X(LABEL_RENDER, "Render", "Renderizar", "Рендер", "渲染", "렌더링") \
X(LABEL_RENDER_FPS, "Render FPS", "Render FPS", "Render FPS", "Render FPS", "Render FPS") \
X(LABEL_REPEAT_DELAY, "Repeat Delay (seconds)", "Repetir Delay (segundos)", "Задержка повторения (секунды)", "键盘按键重复延迟 (秒)", "반복 입력 지연 시간 (초)") \ X(LABEL_REPEAT_DELAY, "Repeat Delay (seconds)", "Repetir Delay (segundos)", "Задержка повторения (секунды)", "键盘按键重复延迟 (秒)", "반복 입력 지연 시간 (초)") \
X(LABEL_REPEAT_RATE, "Repeat Rate (seconds)", "Repetir Tasa (segundos)", "Скорость повторения (секунды)", "键盘按键重复速率 (秒)", "반복 입력 속도 (초)") \ X(LABEL_REPEAT_RATE, "Repeat Rate (seconds)", "Repetir Tasa (segundos)", "Скорость повторения (секунды)", "键盘按键重复速率 (秒)", "반복 입력 속도 (초)") \
X(LABEL_REPLACE_FRAMES, "Replace Frames", "Reemplazar Frames", "Заменить кадры", "替换帧", "프레임 교체") \ X(LABEL_REPLACE_FRAMES, "Replace Frames", "Reemplazar Frames", "Заменить кадры", "替换帧", "프레임 교체") \
@@ -684,6 +687,7 @@ namespace anm2ed
X(TOOLTIP_PREVIEW_TRANSPARENT, "Toggle the animation preview background being transparent.", "Alterna la transparencia del fondo de la vista previa de animacion.", "Переключить прозрачность фона предпросмотра анимации.", "切换动画预览背景是否透明.", "애니메이션 미리보기 배경을 투명하게 전환합니다.") \ X(TOOLTIP_PREVIEW_TRANSPARENT, "Toggle the animation preview background being transparent.", "Alterna la transparencia del fondo de la vista previa de animacion.", "Переключить прозрачность фона предпросмотра анимации.", "切换动画预览背景是否透明.", "애니메이션 미리보기 배경을 투명하게 전환합니다.") \
X(TOOLTIP_USE_ANIMATION_BOUNDS, "Render using the animation's bounds instead of the preview viewport.", "Render using the animation's bounds instead of the preview viewport.", "Render using the animation's bounds instead of the preview viewport.", "Render using the animation's bounds instead of the preview viewport.", "Render using the animation's bounds instead of the preview viewport.") \ X(TOOLTIP_USE_ANIMATION_BOUNDS, "Render using the animation's bounds instead of the preview viewport.", "Render using the animation's bounds instead of the preview viewport.", "Render using the animation's bounds instead of the preview viewport.", "Render using the animation's bounds instead of the preview viewport.", "Render using the animation's bounds instead of the preview viewport.") \
X(TOOLTIP_USE_ISOLATED_ANIMATION, "Render only animation layers with a transparent background and preview helpers hidden.", "Render only animation layers with a transparent background and preview helpers hidden.", "Render only animation layers with a transparent background and preview helpers hidden.", "Render only animation layers with a transparent background and preview helpers hidden.", "Render only animation layers with a transparent background and preview helpers hidden.") \ X(TOOLTIP_USE_ISOLATED_ANIMATION, "Render only animation layers with a transparent background and preview helpers hidden.", "Render only animation layers with a transparent background and preview helpers hidden.", "Render only animation layers with a transparent background and preview helpers hidden.", "Render only animation layers with a transparent background and preview helpers hidden.", "Render only animation layers with a transparent background and preview helpers hidden.") \
X(TOOLTIP_RENDER_FPS, "Set the exported animation frame rate.", "Set the exported animation frame rate.", "Set the exported animation frame rate.", "Set the exported animation frame rate.", "Set the exported animation frame rate.") \
X(TOOLTIP_RELOAD_OVERLAYS, "Reloads the selected overlays.", "Reloads the selected overlays.", "Reloads the selected overlays.", "Reloads the selected overlays.", "Reloads the selected overlays.") \ X(TOOLTIP_RELOAD_OVERLAYS, "Reloads the selected overlays.", "Reloads the selected overlays.", "Reloads the selected overlays.", "Reloads the selected overlays.", "Reloads the selected overlays.") \
X(TOOLTIP_RELOAD_SPRITESHEETS, "Reloads the selected spritesheets.", "Recarga la spritesheet seleccionada.", "Перезагружает выбранные спрайт-листы.", "重新加载所选图集.", "선택한 스프라이트 시트를 다시 불러옵니다.") \ X(TOOLTIP_RELOAD_SPRITESHEETS, "Reloads the selected spritesheets.", "Recarga la spritesheet seleccionada.", "Перезагружает выбранные спрайт-листы.", "重新加载所选图集.", "선택한 스프라이트 시트를 다시 불러옵니다.") \
X(TOOLTIP_RELOAD_SOUNDS, "Reloads the selected sounds.", "Recarga los sonidos seleccionados.", "Перезагружает выбранные звуки.", "重新加载所选声音.", "선택한 사운드를 다시 불러옵니다.") \ X(TOOLTIP_RELOAD_SOUNDS, "Reloads the selected sounds.", "Recarga los sonidos seleccionados.", "Перезагружает выбранные звуки.", "重新加载所选声音.", "선택한 사운드를 다시 불러옵니다.") \
+1
View File
@@ -202,6 +202,7 @@ namespace anm2ed
X(RENDER_IS_USE_ANIMATION_BOUNDS, renderIsUseAnimationBounds, STRING_UNDEFINED, BOOL, true) \ X(RENDER_IS_USE_ANIMATION_BOUNDS, renderIsUseAnimationBounds, STRING_UNDEFINED, BOOL, true) \
X(RENDER_IS_USE_ISOLATED_ANIMATION, renderIsUseIsolatedAnimation, STRING_UNDEFINED, BOOL, false) \ X(RENDER_IS_USE_ISOLATED_ANIMATION, renderIsUseIsolatedAnimation, STRING_UNDEFINED, BOOL, false) \
X(RENDER_SCALE, renderScale, STRING_UNDEFINED, FLOAT, 1.0f) \ X(RENDER_SCALE, renderScale, STRING_UNDEFINED, FLOAT, 1.0f) \
X(RENDER_FPS_MODE, renderFpsMode, STRING_UNDEFINED, INT, render::FPS_ANIMATION) \
X(RENDER_FFMPEG_PATH, renderFFmpegPath, STRING_UNDEFINED, PATH, FFMPEG_PATH_DEFAULT) X(RENDER_FFMPEG_PATH, renderFFmpegPath, STRING_UNDEFINED, PATH, FFMPEG_PATH_DEFAULT)
#define SETTINGS_SHORTCUTS \ #define SETTINGS_SHORTCUTS \
+1 -1
View File
@@ -51,6 +51,6 @@ Alternatively, if you have subscribed to the mod, you can find the latest releas
[h3]Happy animating![/h3] [h3]Happy animating![/h3]
[img]https://files.catbox.moe/4auc1c.gif[/img] [img]https://files.catbox.moe/4auc1c.gif[/img]
</description> </description>
<version>2.26</version> <version>2.27</version>
<visibility>Public</visibility> <visibility>Public</visibility>
</metadata> </metadata>