[Bf-blender-cvs] [b45e71e22cc] master: VSE: Build proxies only for slow movies

Richard Antalik noreply at git.blender.org
Tue Jan 25 22:07:40 CET 2022


Commit: b45e71e22cc704a9169abe0b74dabc8be668b00b
Author: Richard Antalik
Date:   Tue Jan 25 21:39:56 2022 +0100
Branches: master
https://developer.blender.org/rBb45e71e22cc704a9169abe0b74dabc8be668b00b

VSE: Build proxies only for slow movies

This change applies only for automatic proxy building, when strip
is added to timeline. Manual building process is not affected.

Don't build proxy file if movie is already fast enough to seek.
To determine seek performance, check if whole GOP can be decoded
in 100 milliseconds.

To consider some variation in GOP size, large number of packets are
read, assuming that each packet will produce 1 frame. While this is not
technically correct, it does give quite accurate estimate of maximum GOP
size.

This test will ensure consistent performance on wide array of machines.
Check should be done in order of few milliseconds.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D11671

===================================================================

M	source/blender/editors/space_clip/clip_ops.c
M	source/blender/editors/space_sequencer/sequencer_add.c
M	source/blender/editors/space_sequencer/sequencer_proxy.c
M	source/blender/imbuf/IMB_imbuf.h
M	source/blender/imbuf/intern/indexer.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/sequencer/SEQ_proxy.h
M	source/blender/sequencer/intern/proxy.c

===================================================================

diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index ef522e57d02..03b6d8c7381 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -1560,7 +1560,8 @@ static int clip_rebuild_proxy_exec(bContext *C, wmOperator *UNUSED(op))
                                                        clip->proxy.build_size_flag,
                                                        clip->proxy.quality,
                                                        true,
-                                                       NULL);
+                                                       NULL,
+                                                       false);
   }
 
   WM_jobs_customdata_set(wm_job, pj, proxy_freejob);
diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c
index 9f31e55439d..72c39839739 100644
--- a/source/blender/editors/space_sequencer/sequencer_add.c
+++ b/source/blender/editors/space_sequencer/sequencer_add.c
@@ -59,6 +59,7 @@
 
 #include "SEQ_add.h"
 #include "SEQ_effects.h"
+#include "SEQ_iterator.h"
 #include "SEQ_proxy.h"
 #include "SEQ_relations.h"
 #include "SEQ_render.h"
@@ -601,29 +602,28 @@ static IMB_Proxy_Size seq_get_proxy_size_flags(bContext *C)
   return proxy_sizes;
 }
 
-static void seq_build_proxy(bContext *C, Sequence *seq)
+static void seq_build_proxy(bContext *C, SeqCollection *movie_strips)
 {
   if (U.sequencer_proxy_setup != USER_SEQ_PROXY_SETUP_AUTOMATIC) {
     return;
   }
 
-  /* Enable and set proxy size. */
-  SEQ_proxy_set(seq, true);
-  seq->strip->proxy->build_size_flags = seq_get_proxy_size_flags(C);
-  seq->strip->proxy->build_flags |= SEQ_PROXY_SKIP_EXISTING;
-
-  /* Build proxy. */
-  GSet *file_list = BLI_gset_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, "file list");
   wmJob *wm_job = ED_seq_proxy_wm_job_get(C);
   ProxyJob *pj = ED_seq_proxy_job_get(C, wm_job);
-  SEQ_proxy_rebuild_context(pj->main, pj->depsgraph, pj->scene, seq, file_list, &pj->queue);
-  BLI_gset_free(file_list, MEM_freeN);
+
+  Sequence *seq;
+  SEQ_ITERATOR_FOREACH (seq, movie_strips) {
+    /* Enable and set proxy size. */
+    SEQ_proxy_set(seq, true);
+    seq->strip->proxy->build_size_flags = seq_get_proxy_size_flags(C);
+    seq->strip->proxy->build_flags |= SEQ_PROXY_SKIP_EXISTING;
+    SEQ_proxy_rebuild_context(pj->main, pj->depsgraph, pj->scene, seq, NULL, &pj->queue, true);
+  }
 
   if (!WM_jobs_is_running(wm_job)) {
     G.is_break = false;
     WM_jobs_start(CTX_wm_manager(C), wm_job);
   }
-
   ED_area_tag_redraw(CTX_wm_area(C));
 }
 
@@ -642,7 +642,8 @@ static void sequencer_add_movie_clamp_sound_strip_length(Scene *scene,
 
 static void sequencer_add_movie_multiple_strips(bContext *C,
                                                 wmOperator *op,
-                                                SeqLoadData *load_data)
+                                                SeqLoadData *load_data,
+                                                SeqCollection *r_movie_strips)
 {
   Main *bmain = CTX_data_main(C);
   Scene *scene = CTX_data_scene(C);
@@ -705,13 +706,16 @@ static void sequencer_add_movie_multiple_strips(bContext *C,
       sequencer_add_movie_clamp_sound_strip_length(scene, ed->seqbasep, seq_movie, seq_sound);
       seq_load_apply_generic_options(C, op, seq_sound);
       seq_load_apply_generic_options(C, op, seq_movie);
-      seq_build_proxy(C, seq_movie);
+      SEQ_collection_append_strip(seq_movie, r_movie_strips);
     }
   }
   RNA_END;
 }
 
-static bool sequencer_add_movie_single_strip(bContext *C, wmOperator *op, SeqLoadData *load_data)
+static bool sequencer_add_movie_single_strip(bContext *C,
+                                             wmOperator *op,
+                                             SeqLoadData *load_data,
+                                             SeqCollection *r_movie_strips)
 {
   Main *bmain = CTX_data_main(C);
   Scene *scene = CTX_data_scene(C);
@@ -757,7 +761,7 @@ static bool sequencer_add_movie_single_strip(bContext *C, wmOperator *op, SeqLoa
   sequencer_add_movie_clamp_sound_strip_length(scene, ed->seqbasep, seq_movie, seq_sound);
   seq_load_apply_generic_options(C, op, seq_sound);
   seq_load_apply_generic_options(C, op, seq_movie);
-  seq_build_proxy(C, seq_movie);
+  SEQ_collection_append_strip(seq_movie, r_movie_strips);
 
   return true;
 }
@@ -774,21 +778,25 @@ static int sequencer_add_movie_strip_exec(bContext *C, wmOperator *op)
     ED_sequencer_deselect_all(scene);
   }
 
+  SeqCollection *movie_strips = SEQ_collection_create(__func__);
   const int tot_files = RNA_property_collection_length(op->ptr,
                                                        RNA_struct_find_property(op->ptr, "files"));
   if (tot_files > 1) {
-    sequencer_add_movie_multiple_strips(C, op, &load_data);
+    sequencer_add_movie_multiple_strips(C, op, &load_data, movie_strips);
   }
   else {
-    if (!sequencer_add_movie_single_strip(C, op, &load_data)) {
-      sequencer_add_cancel(C, op);
-      return OPERATOR_CANCELLED;
-    }
+    sequencer_add_movie_single_strip(C, op, &load_data, movie_strips);
+  }
+
+  if (SEQ_collection_len(movie_strips) == 0) {
+    SEQ_collection_free(movie_strips);
+    return OPERATOR_CANCELLED;
   }
 
   /* Free custom data. */
   sequencer_add_cancel(C, op);
 
+  seq_build_proxy(C, movie_strips);
   DEG_relations_tag_update(bmain);
   DEG_id_tag_update(&scene->id, ID_RECALC_SEQUENCER_STRIPS);
   WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
diff --git a/source/blender/editors/space_sequencer/sequencer_proxy.c b/source/blender/editors/space_sequencer/sequencer_proxy.c
index 0a8eb7cb88f..fb561025da2 100644
--- a/source/blender/editors/space_sequencer/sequencer_proxy.c
+++ b/source/blender/editors/space_sequencer/sequencer_proxy.c
@@ -85,7 +85,7 @@ static void seq_proxy_build_job(const bContext *C, ReportList *reports)
     }
 
     bool success = SEQ_proxy_rebuild_context(
-        pj->main, pj->depsgraph, pj->scene, seq, file_list, &pj->queue);
+        pj->main, pj->depsgraph, pj->scene, seq, file_list, &pj->queue, false);
 
     if (!success && (seq->strip->proxy->build_flags & SEQ_PROXY_SKIP_EXISTING) != 0) {
       BKE_reportf(reports, RPT_WARNING, "Overwrite is not checked for %s, skipping", seq->name);
@@ -137,7 +137,7 @@ static int sequencer_rebuild_proxy_exec(bContext *C, wmOperator *UNUSED(op))
       short stop = 0, do_update;
       float progress;
 
-      SEQ_proxy_rebuild_context(bmain, depsgraph, scene, seq, file_list, &queue);
+      SEQ_proxy_rebuild_context(bmain, depsgraph, scene, seq, file_list, &queue, false);
 
       for (link = queue.first; link; link = link->next) {
         struct SeqIndexBuildContext *context = link->data;
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index 65d7631445d..a557d7dc6d1 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -378,8 +378,9 @@ struct IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim,
                                                          IMB_Timecode_Type tcs_in_use,
                                                          IMB_Proxy_Size proxy_sizes_in_use,
                                                          int quality,
-                                                         bool overwrite,
-                                                         struct GSet *file_list);
+                                                         const bool overwrite,
+                                                         struct GSet *file_list,
+                                                         bool build_only_on_bad_performance);
 
 /**
  * Will rebuild all used indices and proxies at once.
@@ -431,6 +432,7 @@ bool IMB_anim_can_produce_frames(const struct anim *anim);
 int ismovie(const char *filepath);
 int IMB_anim_get_image_width(struct anim *anim);
 int IMB_anim_get_image_height(struct anim *anim);
+bool IMB_get_gop_decode_time(struct anim *anim);
 
 /**
  *
diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c
index 7aeee2740c0..67724a3bd3b 100644
--- a/source/blender/imbuf/intern/indexer.c
+++ b/source/blender/imbuf/intern/indexer.c
@@ -37,6 +37,8 @@
 #  include "BLI_winstuff.h"
 #endif
 
+#include "PIL_time.h"
+
 #include "IMB_anim.h"
 #include "IMB_indexer.h"
 #include "imbuf.h"
@@ -814,12 +816,16 @@ typedef struct FFmpegIndexBuilderContext {
   double pts_time_base;
   int frameno, frameno_gapless;
   int start_pts_set;
+
+  bool build_only_on_bad_performance;
+  bool building_cancelled;
 } FFmpegIndexBuilderContext;
 
 static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim,
                                                       IMB_Timecode_Type tcs_in_use,
                                                       IMB_Proxy_Size proxy_sizes_in_use,
-                                                      int quality)
+                                                      int quality,
+                                                      bool build_only_on_bad_performance)
 {
   FFmpegIndexBuilderContext *context = MEM_callocN(sizeof(FFmpegIndexBuilderContext),
                                                    "FFmpeg index builder context");
@@ -831,6 +837,7 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim,
   context->proxy_sizes_in_use = proxy_sizes_in_use;
   context->num_proxy_sizes = IMB_PROXY_MAX_SLOT;
   context->num_indexers = IMB_TC_MAX_SLOT;
+  context->build_only_on_bad_performance = build_only_on_bad_performance;
 
   memset(context->proxy_ctx, 0, sizeof(context->proxy_ctx));
   memset(context->indexer, 0, sizeof(context->indexer));
@@ -936,15 +943,17 @@ static void index_rebuild_ffmpeg_finish(FFmpegIndexBuilderContext *context, int
 {
   int i;
 
+  const bool do_rollback = stop || context->building_cancelled;
+
   for (i = 0; i < context->num_indexers; i++) {
     if (context->tcs_in_use & tc_types[i]) {
-      IMB_index_builder_finish(context->indexer[i], stop);
+      IMB_index_builder_finish(cont

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list