Skip to content

Commit

Permalink
Add support for XML embedded in chains
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Nov 4, 2024
1 parent 335d009 commit c219de0
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/mlt++/MltChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "MltChain.h"

#include <cstring>

using namespace Mlt;

Chain::Chain()
Expand All @@ -34,6 +36,12 @@ Chain::Chain(Profile &profile, const char *id, const char *service)
}

mlt_producer source = mlt_factory_producer(profile.get_profile(), id, service);
if (source
&& !strcmp("xml", mlt_properties_get(MLT_PRODUCER_PROPERTIES(source), "mlt_service"))) {
mlt_producer_close(source);
// Always use a producer-consumer for xml so that the profile can be changed
source = mlt_factory_producer(profile.get_profile(), "consumer", service);
}
if (source) {
instance = mlt_chain_init(profile.get_profile());
mlt_chain_set_source(instance, source);
Expand Down
36 changes: 32 additions & 4 deletions src/modules/avformat/link_avdeinterlace.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ static int link_get_image(mlt_frame frame,
// Operate on the native image format/size;
srcimg.width = mlt_properties_get_int(unique_properties, "width");
srcimg.height = mlt_properties_get_int(unique_properties, "height");
srcimg.format = mlt_properties_get_int(unique_properties, "format");
if (mlt_properties_exists(unique_properties, "format")) {
srcimg.format = mlt_properties_get_int(unique_properties, "format");
} else {
srcimg.format = *format;
}

// Sanitize the input
if (srcimg.width <= 1 || srcimg.height <= 1) {
Expand Down Expand Up @@ -522,10 +526,34 @@ static int link_get_frame(mlt_link self, mlt_frame_ptr frame, int index)
return error;
}

// Pass original producer dimensions with the frame
mlt_properties unique_properties = mlt_frame_unique_properties(*frame, MLT_LINK_SERVICE(self));
mlt_properties_pass_list(unique_properties,
MLT_PRODUCER_PROPERTIES(original_producer),
"width height format");
mlt_properties original_producer_properties = MLT_PRODUCER_PROPERTIES(original_producer);
if (mlt_properties_exists(original_producer_properties, "width")) {
mlt_properties_set_int(unique_properties,
"width",
mlt_properties_get_int(original_producer_properties, "width"));
} else if (mlt_properties_exists(original_producer_properties, "meta.media.width")) {
mlt_properties_set_int(unique_properties,
"width",
mlt_properties_get_int(original_producer_properties,
"meta.media.width"));
}
if (mlt_properties_exists(original_producer_properties, "height")) {
mlt_properties_set_int(unique_properties,
"height",
mlt_properties_get_int(original_producer_properties, "height"));
} else if (mlt_properties_exists(original_producer_properties, "meta.media.height")) {
mlt_properties_set_int(unique_properties,
"height",
mlt_properties_get_int(original_producer_properties,
"meta.media.height"));
}
if (mlt_properties_exists(original_producer_properties, "format")) {
mlt_properties_set_int(unique_properties,
"format",
mlt_properties_get_int(original_producer_properties, "format"));
}

// Pass future frames
int i = 0;
Expand Down
16 changes: 16 additions & 0 deletions src/modules/core/producer_consumer.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ mlt_producer producer_consumer_init(mlt_profile profile,
mlt_properties properties = MLT_PRODUCER_PROPERTIES(self);
mlt_properties_set(properties, "resource", arg);
mlt_properties_pass_list(properties, MLT_PRODUCER_PROPERTIES(real_producer), "out, length");
mlt_properties_set_int(properties, "meta.media.width", temp_profile->width);
mlt_properties_set_int(properties, "meta.media.height", temp_profile->height);
mlt_properties_set_int(properties, "meta.media.progressive", temp_profile->progressive);
mlt_properties_set_int(properties,
"meta.media.frame_rate_num",
temp_profile->frame_rate_num);
mlt_properties_set_int(properties,
"meta.media.frame_rate_den",
temp_profile->frame_rate_den);
mlt_properties_set_int(properties,
"meta.media.sample_aspect_num",
temp_profile->sample_aspect_num);
mlt_properties_set_int(properties,
"meta.media.sample_aspect_den",
temp_profile->sample_aspect_den);
mlt_properties_set_int(properties, "meta.media.colorspace", temp_profile->colorspace);

// Done with the producer - will re-open later when we have the profile property
mlt_producer_close(real_producer);
Expand Down
19 changes: 18 additions & 1 deletion src/modules/core/producer_melt.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,24 @@ mlt_producer producer_melt_init(mlt_profile profile,
if (title == NULL && strstr(argv[i], "<?xml") != argv[i])
title = argv[i];

producer = create_producer(profile, field, argv[i]);
if (chain != NULL) {
// Clone the profile so that it can be changed as needed by the chain without changing the main profile
mlt_profile native_profile = mlt_profile_clone(profile);
native_profile->is_explicit = 0;
producer = create_producer(native_profile, field, argv[i]);
if (producer) {
mlt_properties_set_data(MLT_PRODUCER_PROPERTIES(producer),
"_native_profile",
native_profile,
0,
(mlt_destructor) mlt_profile_close,
NULL);
} else {
mlt_profile_close(native_profile);
}
} else {
producer = create_producer(profile, field, argv[i]);
}
if (!first_producer) {
first_producer = producer;
}
Expand Down

0 comments on commit c219de0

Please sign in to comment.