Page MenuHome

T78768: Allow creation of VSE strips referencing a non-existent file
ClosedPublic

Authored by Sybren A. Stüvel (sybren) on Jul 9 2020, 4:09 PM.

Details

Summary

This commit implements two changes to the sequencer API:

  • Sequence.new_movie() gets a new, optional parameter file_must_exist=True. This default value will keep Blender's behaviour of disallowing the creation of the strip for non-existent files. Passing file_must_exist=False will allow the creation of the strip for non-existent files.
  • MovieSequence.has_source is a new read-only RNA property that evaluates to True when the movie sequence strip has a valid source, and False otherwise. It does not perform any disk access to see if the file can be loaded.

This allows for the following:

import bpy

scene = bpy.context.scene
vse = scene.sequence_editor_create()

filepath = bpy.path.abspath('//demo.mkv')
strip = vse.sequences.new_movie("movie", filepath,
    channel=2,
    frame_start=47,
    file_must_exist=False)
strip.frame_final_end = 327

This will create a new movie strip, even when demo.mkv does not exist. In that case, strip.has_source will be False.

Once demo.mkv has appeared at the expected location, strip.filepath = strip.filepath will load it.

Note that image and sound strips behave differently. Even though they also directly refer to files on disk, they do allow creating the strips when the files are missing. That's why this commit only addresses movie strips.

Here are the test files:

To test, do this (instructions are also available in a text block in the blend file):

  • Make sure that demo.mkv does not exist.
  • Run the Python code that's shown in the text editor.
  • Run in the Python console:
strip = C.scene.sequence_editor.sequences_all['movie']
strip.reload_if_needed()
  • Check that the last line returns False.
  • Make sure that demo.mkv exists.
  • Run in the Python console:
strip.reload_if_needed()
  • Check that now True is returned, and that the video file has been loaded.

Diff Detail

Repository
rB Blender
Branch
temp-T78768-nonexisting-vse-strips (branched from master)
Build Status
Buildable 8977
Build 8977: arc lint + arc unit

Event Timeline

Sybren A. Stüvel (sybren) requested review of this revision.Jul 9 2020, 4:09 PM
Sybren A. Stüvel (sybren) created this revision.
Sergey Sharybin (sergey) requested changes to this revision.Jul 9 2020, 4:52 PM

I would make it a default behavior (aka, no argument). Especially since this is how image and sound effectively behaved.

As for the has_source (and what we've discussed here). In python code one should write my_movie_strip.reload_if_needed() which then will do the check which is currently called IMB_anim_has_source() and reload the strip if needed.

This is more of Python API topic, so adding @Bastien Montagne (mont29) here.

Just to elaborate on usecases a bit more. There are more cases where new behavior will become very helpful. For example, create edit from Attract.

source/blender/imbuf/intern/anim_movie.c
309–318

Don't think this will always work the way we expect it to.

Consider following steps:

  • Go to Sequencer workspace, add some real existing movie strips
  • Switch to Viewport workspace
  • Save and reload .blend file
  • Switch viewport to python console and query has_source

I think you will have False because the sequencer has never opened the animation (anim) because it does it lazily on render.

Suggestion: make it strip.reload_if_needed() which will do these checks., You'll have behavior you're looking for (no functional changes compared to this version of the patch), but will be exposed in a more clear way. At least i think it will be more clear ;)

This revision now requires changes to proceed.Jul 9 2020, 4:52 PM
Sybren A. Stüvel (sybren) edited the summary of this revision. (Show Details)

Partial update after discussion with Sergey. This still needs more work (namely, removing the file_must_exist parameter and more testing), which I'll do tomorrow. This does implement the reload_if_needed() function, which became a bit hairier than I anticipated. It works though, but still needs to invalidate the cache for the VSE to properly redraw.

Sybren A. Stüvel (sybren) planned changes to this revision.Jul 9 2020, 5:59 PM
source/blender/makesrna/intern/rna_sequencer.c
762

Sometimes moviestrips without proper video file have an empty anims ListBase, sometimes they do have an anim in there with IMB_anim_can_produce_frames() returning false. Maybe this functionality here should be moved into a function like BKE_sequence_movie_can_produce_frames()?

source/blender/makesrna/intern/rna_sequencer.c
762

It could be, and it could be part of BKE_sequence_is_valid_check() to give visual indication in timeline

  • Final updates after Sergey's comments. The Sequences.new_movie() function now always accepts missing files (just like new_image() and new_sound()). I've added an openanim_attempt_load() function that does basically the same as openanim(), but also returns the anim * to the caller when the video file couldn't be opened. I'll update the patch description with some test files & a description on how to use them.
  • Removed debug prints, turned most into a comment to give a quick way to understand what is happening where without carefully reading the code.
  • Fixed invalidating cache
Sybren A. Stüvel (sybren) edited the summary of this revision. (Show Details)
  • Moved functionality from RNA to BKE
Richard Antalik (ISS) requested changes to this revision.Jul 10 2020, 11:19 AM

When adding "blank" strip it has length of 0. It is not selectable, but panel seems to disregard it and length can't be changed. This isn't very good for general usage.

source/blender/makesrna/intern/rna_sequencer_api.c
223–227

I don't think using openanim_attempt_load is best approach. You really need it only to set preseek and length. Instead you should do this in rna_MovieSequence_reload_if_needed and skip this part of initialization if anim is NULL.

This revision now requires changes to proceed.Jul 10 2020, 11:19 AM
  • Reverted two changes that shouldn't have made it into the patch

RNA/python API looks good to me (besides note below), did not really check the rest of the patch.

source/blender/makesrna/intern/rna_sequencer.c
2411

Description should be last string, second to last is for label (which is completely unused in case of function parameters).

  • Feedback from @Richard Antalik (ISS). I moved some logic around and thereby could remove openanim_attempt_load() altogether.
This revision was not accepted when it landed; it landed in state Needs Review.Jul 13 2020, 3:09 PM
This revision was automatically updated to reflect the committed changes.