X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fexport.cpp;h=fe713b4d7bcc23bc64f875fcaa7c6dab20af0c5c;hb=51a4b5d7f6121fac9a7e1440018e196750c14088;hp=bed2643547a03335662bbda0f60dec36cd5fa981;hpb=5198acefd13b91a7953f1db1370ce7d434132472;p=nageru diff --git a/futatabi/export.cpp b/futatabi/export.cpp index bed2643..fe713b4 100644 --- a/futatabi/export.cpp +++ b/futatabi/export.cpp @@ -3,12 +3,14 @@ #include "export.h" #include "flags.h" #include "frame_on_disk.h" +#include "player.h" #include "shared/ffmpeg_raii.h" #include "shared/timebase.h" #include #include +#include #include #include @@ -194,3 +196,63 @@ void export_multitrack_clip(const string &filename, const Clip &clip) frames_written += buffered_jpegs.size(); progress.setValue(frames_written); } + +void export_interpolated_clip(const string &filename, const vector &clips) +{ + AVFormatContext *avctx = nullptr; + avformat_alloc_output_context2(&avctx, NULL, NULL, filename.c_str()); + if (avctx == nullptr) { + QMessageBox msgbox; + msgbox.setText("Could not allocate FFmpeg context"); + msgbox.exec(); + return; + } + AVFormatContextWithCloser closer(avctx); + + int ret = avio_open(&avctx->pb, filename.c_str(), AVIO_FLAG_WRITE); + if (ret < 0) { + QMessageBox msgbox; + msgbox.setText(QString::fromStdString("Could not open output file '" + filename + "'")); + msgbox.exec(); + return; + } + + QProgressDialog progress(QString::fromStdString("Exporting to " + filename + "..."), "Abort", 0, 1); + progress.setWindowTitle("Futatabi"); + progress.setWindowModality(Qt::WindowModal); + progress.setMinimumDuration(1000); + 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; + + 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_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.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()); + // Destroying player on scope exit will abort the render job. + } +}