X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fexport.cpp;h=fe713b4d7bcc23bc64f875fcaa7c6dab20af0c5c;hb=0a3ea4312599886108fbd12e389ed3504c4dae60;hp=3371404d15e0d7a176f62197821758739a593bdf;hpb=eaba7288c4fb39ca195c9355970293bcaf088dbc;p=nageru diff --git a/futatabi/export.cpp b/futatabi/export.cpp index 3371404..fe713b4 100644 --- a/futatabi/export.cpp +++ b/futatabi/export.cpp @@ -197,7 +197,7 @@ void export_multitrack_clip(const string &filename, const Clip &clip) progress.setValue(frames_written); } -void export_interpolated_clip(const string &filename, const Clip &clip) +void export_interpolated_clip(const string &filename, const vector &clips) { AVFormatContext *avctx = nullptr; avformat_alloc_output_context2(&avctx, NULL, NULL, filename.c_str()); @@ -224,25 +224,35 @@ void export_interpolated_clip(const string &filename, const Clip &clip) progress.setMaximum(100000); progress.setValue(0); + double total_length = compute_time_left(clips, {{0, 0.0}}); + promise done_promise; future done = done_promise.get_future(); std::atomic current_value{0.0}; + size_t clip_idx = 0; - unique_ptr player(new Player(/*destination=*/nullptr, Player::FILE_STREAM_OUTPUT, closer.release())); - player->set_done_callback([&done_promise] { - done_promise.set_value(); + Player player(/*destination=*/nullptr, Player::FILE_STREAM_OUTPUT, closer.release()); + player.set_done_callback([&done_promise, &clip_idx, &clips] { + if (clip_idx >= clips.size()) { + done_promise.set_value(); + } }); - player->set_progress_callback([¤t_value] (const std::map &player_progress) { - assert(player_progress.size() == 1); - current_value = player_progress.begin()->second; + player.set_next_clip_callback([&clip_idx, &clips]() -> pair { + if (++clip_idx >= clips.size()) { + return make_pair(Clip(), -1); + } else { + return make_pair(clips[clip_idx], clip_idx); + } }); - player->play_clip(clip, /*clip_idx=*/0, clip.stream_idx); + player.set_progress_callback([¤t_value, &clips, total_length] (const std::map &player_progress) { + current_value = 1.0 - compute_time_left(clips, player_progress) / total_length; + }); + player.play_clip(clips[0], clip_idx, clips[0].stream_idx); while (done.wait_for(std::chrono::milliseconds(100)) != future_status::ready && !progress.wasCanceled()) { progress.setValue(lrint(100000.0 * current_value)); } if (progress.wasCanceled()) { unlink(filename.c_str()); - player.reset(); - return; + // Destroying player on scope exit will abort the render job. } }