fix export animation frames and add export mp4
This commit is contained in:
@@ -2023,6 +2023,71 @@ void Canvas::export_layers_thread(std::string path)
|
||||
pb->destroy();
|
||||
}
|
||||
|
||||
void Canvas::export_anim_frames(std::string path, std::function<void()> on_complete)
|
||||
{
|
||||
if (App::I->check_license())
|
||||
{
|
||||
std::thread t([=] {
|
||||
BT_SetTerminate();
|
||||
export_anim_frames_thread(path);
|
||||
if (on_complete)
|
||||
on_complete();
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::export_anim_frames_thread(std::string path)
|
||||
{
|
||||
auto pb = App::I->show_progress("Export Frames", anim_duration());
|
||||
for (int i = 0; i < anim_duration(); i++)
|
||||
{
|
||||
anim_goto_frame(i);
|
||||
export_equirectangular_thread(fmt::format("{}-{:02d}.png", path, i));
|
||||
pb->increment();
|
||||
}
|
||||
pb->destroy();
|
||||
}
|
||||
|
||||
void Canvas::export_anim_mp4(std::string path, std::function<void()> on_complete)
|
||||
{
|
||||
if (App::I->check_license())
|
||||
{
|
||||
std::thread t([=] {
|
||||
BT_SetTerminate();
|
||||
export_anim_mp4_thread(path);
|
||||
if (on_complete)
|
||||
on_complete();
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::export_anim_mp4_thread(std::string path)
|
||||
{
|
||||
auto pb = App::I->show_progress("Export Animation", anim_duration());
|
||||
int fps = App::I->animation->get_fps();
|
||||
MP4Encoder mp4;
|
||||
int res = std::min<int>(1024, m_width);
|
||||
mp4.init(res * 4, res * 2, 30, 2 << 20);
|
||||
for (int i = 0; i < anim_duration(); i++)
|
||||
{
|
||||
Image data;
|
||||
App::I->render_task([&]
|
||||
{
|
||||
anim_goto_frame(i);
|
||||
draw_merge(false);
|
||||
Texture2D equirect = m_layers_merge.gen_equirect({ res, res });
|
||||
data = equirect.get_image();
|
||||
});
|
||||
for (int j = 0; j < 30/fps; j++)
|
||||
mp4.encode(data);
|
||||
pb->increment();
|
||||
}
|
||||
mp4.write_mp4(path);
|
||||
pb->destroy();
|
||||
}
|
||||
|
||||
void Canvas::export_cube_faces(std::string file_name, std::function<void()> on_complete)
|
||||
{
|
||||
if (App::I->check_license())
|
||||
@@ -2032,7 +2097,7 @@ void Canvas::export_cube_faces(std::string file_name, std::function<void()> on_c
|
||||
export_cube_faces_thread(file_name);
|
||||
if (on_complete)
|
||||
on_complete();
|
||||
});
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user