]> git.sesse.net Git - nageru/blobdiff - futatabi/export.cpp
On errors, abort() instead of exit(1); exit() in a multithreaded program just gives...
[nageru] / futatabi / export.cpp
index dce83c34a34b1503ef276800c31930b2602ea89b..5b8da136370a7dd8b649bce379e436daa7e8b176 100644 (file)
@@ -104,7 +104,7 @@ void export_multitrack_clip(const string &filename, const Clip &clip)
                AVStream *avstream_video = avformat_new_stream(avctx, nullptr);
                if (avstream_video == nullptr) {
                        fprintf(stderr, "avformat_new_stream() failed\n");
-                       exit(1);
+                       abort();
                }
                avstream_video->time_base = AVRational{ 1, TIMEBASE };
                avstream_video->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -223,23 +223,24 @@ void export_interpolated_clip(const string &filename, const vector<Clip> &clips)
        progress.setMaximum(100000);
        progress.setValue(0);
 
-       double total_length = compute_time_left(clips, { { 0, 0.0 } });
+       vector<ClipWithID> clips_with_id;
+       for (const Clip &clip : clips) {
+               clips_with_id.emplace_back(ClipWithID{ clip, 0 });
+       }
+       TimeRemaining total_length = compute_total_time(clips_with_id);
 
        promise<void> done_promise;
        future<void> done = done_promise.get_future();
        std::atomic<double> 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_done_callback([&done_promise] {
+               done_promise.set_value();
        });
-       player.set_progress_callback([&current_value, &clips, total_length](const std::map<size_t, double> &player_progress) {
-               current_value = 1.0 - compute_time_left(clips, player_progress) / total_length;
+       player.set_progress_callback([&current_value, total_length](const std::map<uint64_t, double> &player_progress, TimeRemaining time_remaining) {
+               current_value = 1.0 - time_remaining.t / total_length.t;  // Nothing to do about the infinite clips.
        });
-       player.play(clips);
+       player.play(clips_with_id);
        while (done.wait_for(std::chrono::milliseconds(100)) != future_status::ready && !progress.wasCanceled()) {
                progress.setValue(lrint(100000.0 * current_value));
        }