30#include "RNA_prototypes.hh"
38#include "opentimelineio/clip.h"
39#include "opentimelineio/color.h"
40#include "opentimelineio/effect.h"
41#include "opentimelineio/externalReference.h"
42#include "opentimelineio/freezeFrame.h"
43#include "opentimelineio/gap.h"
44#include "opentimelineio/generatorReference.h"
45#include "opentimelineio/imageSequenceReference.h"
46#include "opentimelineio/linearTimeWarp.h"
47#include "opentimelineio/marker.h"
48#include "opentimelineio/missingReference.h"
49#include "opentimelineio/stack.h"
50#include "opentimelineio/timeline.h"
51#include "opentimelineio/track.h"
52#include "opentimelineio/transition.h"
91 return RationalTime(count, ctx.
fps);
96 return TimeRange(
frames(ctx, start),
frames(ctx, duration));
119 return strip.right_handle(ctx.
scene) - strip.left_handle();
121 return strip.anim_startofs + strip.content_length() + strip.anim_endofs;
135 &ctx.
scene->
id, RNA_Strip,
const_cast<Strip *
>(&strip));
136 const char *identifier =
"";
144 SerializableObjectWithMetadata &
object)
147 &ctx.
scene->
id, RNA_Strip,
const_cast<Strip *
>(&strip));
150 object.metadata()[
"blender"] =
data;
164 unsigned short digits_len;
167 r_padding = digits_len;
168 if (digits_len == 0) {
176 if (r_frame_step < 1) {
188 r_start_frame + i * r_frame_step);
200 int start_frame, frame_step,
padding;
202 strip.
data->stripdata_num,
210 return new MissingReference(strip.name + 2);
218 const double rate = ctx.
fps * frame_step;
219 return new ImageSequenceReference(dirpath,
226 ImageSequenceReference::MissingFramePolicy::error,
233 const bool has_media = strip.
data && strip.
data->stripdata;
235 switch (strip.
type) {
239 return new MissingReference(strip.name + 2);
246 return new MissingReference(strip.name + 2);
256 return new MissingReference(strip.name + 2);
271 return new GeneratorReference(
277 return new MissingReference(strip.name + 2);
286 const Strip &speed_strip)
291 const float speed_length = speed_strip.right_handle(ctx.
scene) - speed_strip.left_handle();
292 return speed_length != 0.0f ? (input.length(ctx.
scene) - input.startofs) / speed_length :
304 const Strip &effect_strip)
306 const std::string name = effect_strip.name + 2;
307 SerializableObject::Retainer<otio::Effect> effect;
311 else if (
const float factor =
speed_factor(ctx, input, effect_strip); factor != 0.0f) {
312 effect =
new LinearTimeWarp(name,
"", factor);
315 effect =
new FreezeFrame(name);
326 item.set_enabled(!(strip.flag &
SEQ_MUTE));
339 SerializableObject::Retainer<MediaReference> reference =
media_reference(ctx, strip);
341 CLOG_WARN(&
LOG,
"Skipping strip '%s' of unsupported type", strip.name + 2);
344 "Strip '%s' was not exported, its type is currently unsupported",
349 double source_start = strip.left_handle() - int(strip.content_start()) + strip.anim_startofs;
350 const int duration = strip.right_handle(ctx.
scene) - strip.left_handle();
355 source_start -= strip.sound_offset * ctx.
fps;
358 auto clip = SerializableObject::Retainer<Clip>(
359 new Clip(strip.name + 2, reference,
frame_range(ctx, source_start, duration)));
369 ListBaseT<Strip> &seqbase,
370 const ListBaseT<SeqTimelineChannel> *channels,
378 ListBaseT<SeqTimelineChannel> *channels;
381 const_cast<Strip *
>(&strip), &channels, &origin);
389 const int start = strip.left_handle();
390 const int end = strip.right_handle(ctx.
scene);
391 const TimeRange range =
frame_range(ctx, start -
int(strip.content_start()), end - start);
393 for (
const bool is_audio : {
false,
true}) {
399 auto stack = SerializableObject::Retainer<Stack>(
new Stack(strip.name + 2, range));
400 for (
const SerializableObject::Retainer<Track> &track : nested) {
401 stack->append_child(track);
404 (is_audio ? items.
audio : items.
video).append({&strip, start, end, stack.value});
412 if (item.strip == strip) {
420 const RationalTime before,
421 const RationalTime after)
423 Item *otio_item =
dynamic_cast<Item *
>(item.
composable.value);
424 const TimeRange range = otio_item->trimmed_range();
425 otio_item->set_source_range(
426 TimeRange(range.start_time() - before, range.duration() + before + after));
430 const Strip &transition,
431 std::map<int, ChannelItems> &channel_items)
433 const Strip *input1 = transition.input1;
434 const Strip *input2 = transition.input2;
437 if (input1 && input2 && input1->channel == input2->channel) {
445 if (!from || !to || from->
end >= to->
start) {
446 CLOG_WARN(&
LOG,
"Skipping transition strip '%s'", transition.name + 2);
449 "Transition strip '%s' was not exported, its inputs must be on the same channel",
450 transition.name + 2);
455 const int in_offset =
length / 2;
456 const int out_offset =
length - in_offset;
459 from->
end += in_offset;
460 to->
start -= out_offset;
462 auto otio_transition = SerializableObject::Retainer<Transition>(
463 new Transition(transition.name + 2,
465 Transition::Type::SMPTE_Dissolve,
467 frames(ctx, out_offset)));
473 const int cut = from->
end;
474 channel_items[input1->channel].video.append({&transition, cut, cut, otio_transition.value});
479 const std::string &kind,
481 const int channel_index,
485 return std::tie(a.
start, a.
end) < std::tie(
b.start,
b.end);
488 auto track = SerializableObject::Retainer<Track>(
489 new Track(channel ? channel->
name :
"", std::nullopt, kind));
490 track->set_enabled(!(channel && channel->is_muted()));
493 track->metadata()[
"blender"] =
data;
500 if (item.start > cursor) {
501 track->append_child(
new Gap(
frames(ctx, item.start - cursor)));
503 track->append_child(item.composable);
511 ListBaseT<Strip> &seqbase,
512 const ListBaseT<SeqTimelineChannel> *channels,
515 std::map<int, ChannelItems> channel_items;
516 for (
const Strip &strip : seqbase) {
524 if (SerializableObject::Retainer<Clip> clip =
strip_to_clip(ctx, editing, strip)) {
526 .append({&strip, strip.left_handle(), strip.right_handle(ctx.
scene), clip.value});
530 for (
const Strip &strip : seqbase) {
537 for (
auto &[channel_index, items] : channel_items) {
541 if (!items.video.is_empty()) {
543 build_track(ctx, items.video, Track::Kind::video, channel, channel_index, origin));
545 if (!items.audio.is_empty()) {
547 build_track(ctx, items.audio, Track::Kind::audio, channel, channel_index, origin));
556 stack.markers().push_back(
571 int origin = scene->
r.
sfra;
573 origin = std::min(origin, strip.left_handle());
578 auto timeline = SerializableObject::Retainer<Timeline>(
580 for (
const SerializableObject::Retainer<Track> &track : tracks.
video) {
581 timeline->tracks()->append_child(track);
583 for (
const SerializableObject::Retainer<Track> &track : tracks.
audio) {
584 timeline->tracks()->append_child(track);
590 timeline->metadata()[
"blender"] =
data;
596 opentimelineio::OPENTIMELINEIO_VERSION_NS::ErrorStatus error_status;
600 const schema_version_map schema_version_targets = {{
"Marker", 2}};
601 if (!timeline->to_json_file(params.
filepath, &error_status, &schema_version_targets)) {
603 "Failed to write OTIO file '%s': %s",
605 error_status.full_description.c_str());
615 "%d scene strip(s) found, this is currently unsupported",
621 "%d image sequence(s) with non-sequential filenames found, this is currently "
#define BLENDER_FILE_SUBVERSION
#define BLENDER_FILE_VERSION
#define BLI_path_join(...)
#define CLOG_ERROR(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
constexpr IndexRange()=default
Stack(Allocator allocator={}) noexcept
const T & data(const Action &owning_action) const
float length(VecOp< float, D >) RET
std::string filename(const std::string_view &str, size_t pos)
static TimeRange frame_range(const StripExportContext &ctx, const double start, const int duration)
static Tracks export_strips(StripExportContext &ctx, Editing &editing, ListBaseT< Strip > &seqbase, const ListBaseT< SeqTimelineChannel > *channels, int origin)
static std::string strip_type_identifier(const StripExportContext &ctx, const Strip &strip)
static PlacedItem * find_item(Vector< PlacedItem > &items, const Strip *strip)
static void extend_source_range(PlacedItem &item, const RationalTime before, const RationalTime after)
static void add_transition(const StripExportContext &ctx, const Strip &transition, std::map< int, ChannelItems > &channel_items)
static bool add_nested_items(StripExportContext &ctx, Editing &editing, const Strip &strip, ChannelItems &items)
void resolve_add_clip_data(const Scene &scene, const Strip &strip, const Map< const Strip *, int64_t > &link_groups, Clip &clip)
static bool is_single_input_effect(const Strip &strip)
static SerializableObject::Retainer< Track > build_track(const StripExportContext &ctx, Vector< PlacedItem > &items, const std::string &kind, const SeqTimelineChannel *channel, const int channel_index, const int origin)
AnyDictionary rna_to_dictionary(PointerRNA &ptr)
static void add_strip_metadata(const StripExportContext &ctx, const Strip &strip, SerializableObjectWithMetadata &object)
static void export_markers(const StripExportContext &ctx, const int origin, Stack &stack)
static SerializableObject::Retainer< otio::Effect > strip_to_effect(const StripExportContext &ctx, const Strip &input, const Strip &effect_strip)
static std::string media_filepath(const StripExportContext &ctx, const Strip &strip)
static float speed_factor(const StripExportContext &ctx, const Strip &input, const Strip &speed_strip)
static SerializableObject::Retainer< MediaReference > image_sequence_reference(StripExportContext &ctx, const Strip &strip)
GeneratorReference * resolve_generator_reference(const Strip &strip, const TimeRange &available_range)
static int media_length(const StripExportContext &ctx, const Strip &strip)
static bool is_transition(const Strip &strip)
static SerializableObject::Retainer< Clip > strip_to_clip(StripExportContext &ctx, Editing &editing, const Strip &strip)
void exporter_main(bContext *C, const OTIOExportParams ¶ms)
void resolve_add_transition_data(const Scene &scene, const Strip &transition, Transition &otio_transition)
static SerializableObject::Retainer< MediaReference > media_reference(StripExportContext &ctx, const Strip &strip)
Map< const Strip *, int64_t > resolve_link_groups(const ListBaseT< Strip > &seqbase)
void resolve_add_track_data(const SeqTimelineChannel *channel, Track &track)
static bool image_sequence_pattern_get(const StripElem *elems, const int elems_num, char *r_name_prefix, char *r_name_suffix, int &r_start_frame, int &r_frame_step, int &r_padding)
static void add_strip_data(const StripExportContext &ctx, Editing &editing, const Strip &strip, Item &item)
void resolve_add_timeline_metadata(Timeline &timeline)
static bool is_nested(const Strip &strip)
void add_foreign_metadata(IDProperty *properties, SerializableObjectWithMetadata &object)
static RationalTime frames(const StripExportContext &ctx, const double count)
Editing * editing_get(const Scene *scene)
bool effect_is_transition(StripType type)
bool transform_single_image_check(const Strip *strip)
Span< Strip * > lookup_effects_by_strip(Editing *ed, const Strip *key)
SeqTimelineChannel * channel_get_by_index(const ListBaseT< SeqTimelineChannel > *channels, const int channel_index)
ListBaseT< Strip > * get_seqbase_from_strip(Strip *strip, ListBaseT< SeqTimelineChannel > **r_channels, int *r_offset)
uint padding(uint offset, uint alignment)
Scene * CTX_data_sequencer_scene(const bContext *C)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
bool RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_identifier)
@ STRIP_TYPE_GAUSSIAN_BLUR
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void BKE_report(ReportList *reports, eReportType type, const char *message)
BMesh const char void * data
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Main * CTX_data_main(const bContext *C)
int BLI_path_sequence_decode(const char *path, char *head, size_t head_maxncpy, char *tail, size_t tail_maxncpy, unsigned short *r_digits_len)
void BLI_path_sequence_encode(char *path, size_t path_maxncpy, const char *head, const char *tail, unsigned short numlen, int pic)
ListBaseT< SeqTimelineChannel > channels
ListBaseT< Strip > seqbase
bool use_resolve_metadata
ListBaseT< TimeMarker > markers
eEffectSpeedControlType speed_control_type
Vector< PlacedItem > audio
Vector< PlacedItem > video
SerializableObject::Retainer< Composable > composable
const OTIOExportParams & params
Map< const Strip *, int64_t > resolve_link_groups
int unsupported_image_sequences
int unsupported_scene_strips
Vector< SerializableObject::Retainer< Track > > video
Vector< SerializableObject::Retainer< Track > > audio