Fix T49027: Sequence uses too much memory when rendering scene with lots of movie...
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 9 Aug 2016 12:33:00 +0000 (14:33 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 9 Aug 2016 12:33:00 +0000 (14:33 +0200)
Now we free sequencer cache and close all unneeded FFmpeg handles when rendering.
This is the same logic as image sequence memory freeding.

source/blender/blenkernel/BKE_sequencer.h
source/blender/blenkernel/intern/sequencer.c
source/blender/render/intern/source/pipeline.c

index 30bb695401964a297f0508bdf5cd67d7b03be09a..811e9136fc9d01a42065c96de438f9033fde413c 100644 (file)
@@ -477,4 +477,6 @@ struct ImBuf *BKE_sequencer_render_mask_input(
         int cfra, int fra_offset, bool make_float);
 void BKE_sequencer_color_balance_apply(struct StripColorBalance *cb, struct ImBuf *ibuf, float mul, bool make_float, struct ImBuf *mask_input);
 
+void BKE_sequencer_all_free_anim_ibufs(int cfra);
+
 #endif  /* __BKE_SEQUENCER_H__ */
index 6067a8b2d9bf66505c4e8b79c36530a0320c669c..b2a19c590843ab599cf3fd55e6d00318cca41c7f 100644 (file)
@@ -5595,3 +5595,31 @@ int BKE_sequencer_find_next_prev_edit(
 
        return best_frame;
 }
+
+static void sequencer_all_free_anim_ibufs(ListBase *seqbase, int cfra)
+{
+       for (Sequence *seq = seqbase->first; seq != NULL; seq = seq->next) {
+               if (seq->enddisp < cfra || seq->startdisp > cfra) {
+                       BKE_sequence_free_anim(seq);
+               }
+               if (seq->type == SEQ_TYPE_META) {
+                       sequencer_all_free_anim_ibufs(&seq->seqbase, cfra);
+               }
+       }
+}
+
+void BKE_sequencer_all_free_anim_ibufs(int cfra)
+{
+       BKE_sequencer_cache_cleanup();
+       for (Scene *scene = G.main->scene.first;
+            scene != NULL;
+            scene = scene->id.next)
+       {
+               Editing *ed = BKE_sequencer_editing_get(scene, false);
+               if (ed == NULL) {
+                       /* Ignore scenes without sequencer. */
+                       continue;
+               }
+               sequencer_all_free_anim_ibufs(&ed->seqbase, cfra);
+       }
+}
index 604693f486e57212acd3aa2b7bfd0ea3592a3716..ec629aa28636f92b9b3793bedad43ab82086b5ba 100644 (file)
@@ -2785,6 +2785,7 @@ static void do_render_all_options(Render *re)
 
        /* ensure no images are in memory from previous animated sequences */
        BKE_image_all_free_anim_ibufs(re->r.cfra);
+       BKE_sequencer_all_free_anim_ibufs(re->r.cfra);
 
        if (RE_engine_render(re, 1)) {
                /* in this case external render overrides all */