[Bf-blender-cvs] [9623e2ed1c6] temp-vse-video-performance-detection: VSE: Build proxies only for slow movies

Richard Antalik noreply at git.blender.org
Mon Apr 19 09:29:31 CEST 2021


Commit: 9623e2ed1c6d4cb6d3dbaea534ee7b282b5e46ea
Author: Richard Antalik
Date:   Mon Apr 19 09:17:49 2021 +0200
Branches: temp-vse-video-performance-detection
https://developer.blender.org/rB9623e2ed1c6d4cb6d3dbaea534ee7b282b5e46ea

VSE: Build proxies only for slow movies

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

This test will ensure consistent performance on wide array of machines.

Downside is at most 50ms delay (per strip) when movie is added.
Ideally another test would be performed to detect whether next GOPs
do have same size or not as it may not be safe to assume that movies
will have consistent gop sizes. Even better would be to find biggest
one within small-ish range from start, and perform this test on it.
such test may add about 10ms of additional delay, but provide even more
consistency.

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

M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/editors/space_sequencer/sequencer_add.c
M	source/blender/imbuf/IMB_imbuf.h
M	source/blender/imbuf/intern/anim_movie.c
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/sequencer/intern/strip_add.c
M	source/blender/sequencer/intern/strip_relations.c

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

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 04b7a11bde1..0de053f99e0 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -658,6 +658,7 @@ class USERPREF_PT_system_video_sequencer(SystemPanel, CenterAlignMixIn, Panel):
         layout.separator()
 
         layout.prop(system, "sequencer_proxy_setup")
+        layout.prop(system, "sequencer_proxy_for_slow_movies")
 
 
 # -----------------------------------------------------------------------------
diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c
index 2df8dce0b3c..7447621f3c5 100644
--- a/source/blender/editors/space_sequencer/sequencer_add.c
+++ b/source/blender/editors/space_sequencer/sequencer_add.c
@@ -574,12 +574,35 @@ static IMB_Proxy_Size seq_get_proxy_size_flags(bContext *C)
   return proxy_sizes;
 }
 
+#include "PIL_time.h"
+
+static bool movie_decoding_is_slow(Sequence *seq)
+{
+  const int strip_length = seq->len;
+  const StripAnim *sanim = seq->anims.first;
+
+  if (strip_length <= 1 || sanim == NULL) {
+    return false;
+  }
+
+  return IMB_get_gop_decode_time(sanim->anim);
+}
+
 static void seq_build_proxy(bContext *C, Sequence *seq)
 {
   if (U.sequencer_proxy_setup != USER_SEQ_PROXY_SETUP_AUTOMATIC) {
     return;
   }
 
+  const bool is_slow = movie_decoding_is_slow(seq);
+  const char *str = is_slow ? "slow" : "fast";
+  printf("Automatic proxy building thinks, that added strip is %s.\n", str);
+
+
+  if ((U.sequencer_proxy_setup_flag & USER_SEQ_PROXY_FOR_SLOW_MOVIES) && !is_slow) {
+    return;
+  }
+
   /* Enable and set proxy size. */
   SEQ_proxy_set(seq, true);
   seq->strip->proxy->build_size_flags = seq_get_proxy_size_flags(C);
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index d131e4dacdc..ad3502b3d68 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -384,6 +384,7 @@ void IMB_anim_set_preseek(struct anim *anim, int preseek);
 int IMB_anim_get_preseek(struct anim *anim);
 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/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c
index 6c63c1a1b5b..ea348e8a999 100644
--- a/source/blender/imbuf/intern/anim_movie.c
+++ b/source/blender/imbuf/intern/anim_movie.c
@@ -1613,3 +1613,46 @@ int IMB_anim_get_image_height(struct anim *anim)
 {
   return anim->y;
 }
+
+#include "PIL_time.h"
+
+bool IMB_get_gop_decode_time(struct anim *anim)
+{
+
+  if (anim == NULL) {
+    return false;
+  }
+
+  /* Ensure, that file isn't cold read. */
+  ffmpeg_decode_video_frame(anim);
+  /* Seek back to beginning. */
+  av_seek_frame(anim->pFormatCtx, -1, 0, AVSEEK_FLAG_BACKWARD);
+  avcodec_flush_buffers(anim->pCodecCtx);
+  anim->curposition = -1;
+
+  const double start = PIL_check_seconds_timer();
+  const double time_to_decode_max = 0.05;
+  double time_to_decode = 0;
+
+  while (ffmpeg_decode_video_frame(anim)) {
+    const double end = PIL_check_seconds_timer();
+    time_to_decode = end - start;
+
+    if (anim->next_packet.flags & AV_PKT_FLAG_KEY) {
+      printf("GOP decoded completely within time constraints.\n");
+      break;
+    }
+
+    if (time_to_decode > time_to_decode_max) {
+      printf("Decode time analysis timeout.\n");
+      break;
+    }
+  }
+
+  av_seek_frame(anim->pFormatCtx, -1, 0, AVSEEK_FLAG_BACKWARD);
+  avcodec_flush_buffers(anim->pCodecCtx);
+  anim->curposition = -1;
+
+  printf("Time to decode: %f\n", time_to_decode);
+  return time_to_decode > time_to_decode_max;
+}
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index 1fed8e14bd6..0aa8954d08e 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -921,7 +921,9 @@ typedef struct UserDef {
   int sequencer_disk_cache_compression; /* eUserpref_DiskCacheCompression */
   int sequencer_disk_cache_size_limit;
   short sequencer_disk_cache_flag;
-  short sequencer_proxy_setup; /* eUserpref_SeqProxySetup */
+  short sequencer_proxy_setup;    /* eUserpref_SeqProxySetup */
+  int sequencer_proxy_setup_flag; /* eUserpref_SeqProxySetupFlag */
+  int _pad1111[3];
 
   float collection_instance_empty_size;
   char _pad10[3];
@@ -1389,8 +1391,13 @@ typedef enum eUserpref_DiskCacheCompression {
 typedef enum eUserpref_SeqProxySetup {
   USER_SEQ_PROXY_SETUP_MANUAL = 0,
   USER_SEQ_PROXY_SETUP_AUTOMATIC = 1,
+  /* Flags. */
 } eUserpref_SeqProxySetup;
 
+typedef enum eUserpref_SeqProxySetupFlag {
+  USER_SEQ_PROXY_FOR_SLOW_MOVIES = (1 << 0),
+} eUserpref_SeqProxySetupFlag;
+
 /* Locale Ids. Auto will try to get local from OS. Our default is English though. */
 /** #UserDef.language */
 enum {
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 26887b51f81..9501a93637a 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -5462,6 +5462,14 @@ static void rna_def_userdef_system(BlenderRNA *brna)
   RNA_def_property_enum_sdna(prop, NULL, "sequencer_proxy_setup");
   RNA_def_property_ui_text(prop, "Proxy Setup", "When and how proxies are created");
 
+  prop = RNA_def_property(srna, "sequencer_proxy_for_slow_movies", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(
+      prop, NULL, "sequencer_proxy_setup_flag", USER_SEQ_PROXY_FOR_SLOW_MOVIES);
+  RNA_def_property_ui_text(prop,
+                           "Build Proxy for Slow Movies",
+                           "Analyze worst-case scenario and build proxies only when movie is not "
+                           "optimal for scrubbing");
+
   prop = RNA_def_property(srna, "scrollback", PROP_INT, PROP_UNSIGNED);
   RNA_def_property_int_sdna(prop, NULL, "scrollback");
   RNA_def_property_range(prop, 32, 32768);
diff --git a/source/blender/sequencer/intern/strip_add.c b/source/blender/sequencer/intern/strip_add.c
index 55d92c1eb10..18d7f57a9b9 100644
--- a/source/blender/sequencer/intern/strip_add.c
+++ b/source/blender/sequencer/intern/strip_add.c
@@ -562,7 +562,7 @@ Sequence *SEQ_add_movie_strip(Main *bmain, Scene *scene, ListBase *seqbase, SeqL
   seq_add_set_name(seq, load_data);
   seq_add_generic_update(scene, seqbase, seq);
 
-  MEM_freeN(anim_arr);
+  //MEM_freeN(anim_arr);
   return seq;
 }
 
diff --git a/source/blender/sequencer/intern/strip_relations.c b/source/blender/sequencer/intern/strip_relations.c
index 1a2ff08bd08..7ab40400ba1 100644
--- a/source/blender/sequencer/intern/strip_relations.c
+++ b/source/blender/sequencer/intern/strip_relations.c
@@ -114,7 +114,7 @@ static void sequence_invalidate_cache(Scene *scene,
   Editing *ed = scene->ed;
 
   if (invalidate_self) {
-    SEQ_relations_sequence_free_anim(seq);
+    // SEQ_relations_sequence_free_anim(seq);
     seq_cache_cleanup_sequence(scene, seq, seq, invalidate_types, false);
   }



More information about the Bf-blender-cvs mailing list