diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2020-07-13 16:02:25 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2020-07-13 16:09:18 +0300 |
commit | b9f565881e15f13f5f30b6aca9fc656b3f92b900 (patch) | |
tree | a070bb7b6df13030a81c80a0cbf0d19784156723 /source/blender/makesrna/intern/rna_sequencer_api.c | |
parent | 9db0c36af1140082b8e4bcf42564482eb477a682 (diff) |
VSE: Python API, allow creation of VSE Movie strips with missing file
It was already possible to create Sound and Image strips that reference
non-existing files. Now it's also possible to create Movie strips
referencing missing files via the Python API call
`Sequences.new_movie()`. In this case, the duration of the strip will be
set to 1 frame.
Note that this commit does not change anything in the user interface.
The Python API of the `MovieStrip` class is extended with a function
`reload_if_needed()`. This function only performs disk I/O if the movie
strip cannot produce frames, that is either when its filepath points to
a non-existing file, or when the video sequence editor has not been
shown yet (for example because it is in an inactive workspace).
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.
Once `demo.mkv` has appeared at the expected location, either
`strip.reload_if_needed()` or `strip.filepath = strip.filepath` will
load it.
Differential Revision: https://developer.blender.org/D8257
Reviewed By: Sergey, ISS
Diffstat (limited to 'source/blender/makesrna/intern/rna_sequencer_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_sequencer_api.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/source/blender/makesrna/intern/rna_sequencer_api.c b/source/blender/makesrna/intern/rna_sequencer_api.c index 0fb582c41fd..4157747455d 100644 --- a/source/blender/makesrna/intern/rna_sequencer_api.c +++ b/source/blender/makesrna/intern/rna_sequencer_api.c @@ -205,33 +205,28 @@ static Sequence *rna_Sequences_new_image(ID *id, return seq; } -static Sequence *rna_Sequences_new_movie(ID *id, - Editing *ed, - ReportList *reports, - const char *name, - const char *file, - int channel, - int frame_start) +static Sequence *rna_Sequences_new_movie( + ID *id, Editing *ed, const char *name, const char *file, int channel, int frame_start) { Scene *scene = (Scene *)id; Sequence *seq; StripAnim *sanim; - struct anim *an = openanim(file, IB_rect, 0, NULL); + seq = alloc_generic_sequence(ed, name, frame_start, channel, SEQ_TYPE_MOVIE, file); + struct anim *an = openanim(file, IB_rect, 0, NULL); if (an == NULL) { - BKE_report(reports, RPT_ERROR, "Sequences.new_movie: unable to open movie file"); - return NULL; + /* Without anim, the strip gets duration 0, which makes it impossible to select in the UI. */ + seq->len = 1; } + else { + sanim = MEM_mallocN(sizeof(StripAnim), "Strip Anim"); + BLI_addtail(&seq->anims, sanim); + sanim->anim = an; - seq = alloc_generic_sequence(ed, name, frame_start, channel, SEQ_TYPE_MOVIE, file); - - sanim = MEM_mallocN(sizeof(StripAnim), "Strip Anim"); - BLI_addtail(&seq->anims, sanim); - sanim->anim = an; - - seq->anim_preseek = IMB_anim_get_preseek(an); - seq->len = IMB_anim_get_duration(an, IMB_TC_RECORD_RUN); + seq->anim_preseek = IMB_anim_get_preseek(an); + seq->len = IMB_anim_get_duration(an, IMB_TC_RECORD_RUN); + } BKE_sequence_calc_disp(scene, seq); BKE_sequence_invalidate_cache_composite(scene, seq); @@ -667,7 +662,7 @@ void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_return(func, parm); func = RNA_def_function(srna, "new_movie", "rna_Sequences_new_movie"); - RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID); + RNA_def_function_flag(func, FUNC_USE_SELF_ID); RNA_def_function_ui_description(func, "Add a new movie sequence"); parm = RNA_def_string(func, "name", "Name", 0, "", "Name for the new sequence"); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); |