]> git.sesse.net Git - nageru/commitdiff
Support exporting multiple clips of a playlist, with fades and all.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 14 Dec 2018 23:39:05 +0000 (00:39 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 14 Dec 2018 23:39:05 +0000 (00:39 +0100)
futatabi/export.cpp
futatabi/export.h
futatabi/mainwindow.cpp
futatabi/mainwindow.ui

index a653f01324775cfeee9a9eff0904315e391b4058..fe713b4d7bcc23bc64f875fcaa7c6dab20af0c5c 100644 (file)
@@ -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<Clip> &clips)
 {
        AVFormatContext *avctx = nullptr;
        avformat_alloc_output_context2(&avctx, NULL, NULL, filename.c_str());
@@ -224,19 +224,30 @@ 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<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] {
-               done_promise.set_value();
+       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<Clip, int> {
+               if (++clip_idx >= clips.size()) {
+                       return make_pair(Clip(), -1);
+               } else {
+                       return make_pair(clips[clip_idx], clip_idx);
+               }
        });
-       player.set_progress_callback([&current_value] (const std::map<size_t, double> &player_progress) {
-               assert(player_progress.size() == 1);
-               current_value = player_progress.begin()->second;
+       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.play_clip(clip, /*clip_idx=*/0, clip.stream_idx);
+       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));
        }
index 934937c72017f8effd11c437a0792a65a2648c78..0397749b8b04299b888e89cfcbabd1bf75b8dadf 100644 (file)
@@ -2,8 +2,9 @@
 #define _EXPORT_H 1
 
 #include <string>
+#include <vector>
 
 void export_multitrack_clip(const std::string &filename, const Clip &clip);
-void export_interpolated_clip(const std::string &filename, const Clip &clip);
+void export_interpolated_clip(const std::string &filename, const std::vector<Clip> &clips);
 
 #endif
index 7455cacb31233bbe81b0bcfed50967092e23f5d0..7cc27b4840f90d250d52fd1d804495fe92850a82 100644 (file)
@@ -796,8 +796,6 @@ void MainWindow::export_playlist_clip_interpolated_triggered()
                return;
        }
 
-       QModelIndex index = selected->currentIndex();
-       Clip clip = *playlist_clips->clip(index.row());
        QString filename = QFileDialog::getSaveFileName(this,
                "Export interpolated clip", QString(), tr("Matroska video files (*.mkv)"));
        if (filename.isNull()) {
@@ -807,7 +805,13 @@ void MainWindow::export_playlist_clip_interpolated_triggered()
        if (!filename.endsWith(".mkv")) {
                filename += ".mkv";
        }
-       export_interpolated_clip(filename.toStdString(), clip);
+
+       vector<Clip> clips;
+       QModelIndexList rows = selected->selectedRows();
+       for (QModelIndex index : rows) {
+               clips.push_back(*playlist_clips->clip(index.row()));
+       }
+       export_interpolated_clip(filename.toStdString(), clips);
 }
 
 void MainWindow::manual_triggered()
index 81167d8e8cf6ffcdf8d9ee9676eb7d6b41df2dee..2950e67d27cabe116a809ca1292e0c1893b387b4 100644 (file)
   </action>
   <action name="export_playlist_clip_interpolated_action">
    <property name="text">
-    <string>Selected playlist clip as &amp;interpolated single track…</string>
+    <string>Selected playlist clip(s) as &amp;interpolated single track…</string>
    </property>
   </action>
  </widget>