Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a loop range feature to MLT Producer
Browse files Browse the repository at this point in the history
bmatherly committed Dec 6, 2023
1 parent c5c199e commit 1e9f104
Showing 6 changed files with 53 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/framework/mlt.vers
Original file line number Diff line number Diff line change
@@ -687,4 +687,9 @@ MLT_7.22.0 {
mlt_property_is_color;
mlt_property_is_numeric;
mlt_property_is_rect;
} MLT_7.18.0;
} MLT_7.18.0;

MLT_7.24.0 {
global:
mlt_producer_set_loop_range;
} MLT_7.22.0;
33 changes: 33 additions & 0 deletions src/framework/mlt_producer.c
Original file line number Diff line number Diff line change
@@ -356,6 +356,14 @@ int mlt_producer_seek(mlt_producer self, mlt_position position)
// Do not bounds check a link.
} else if (position < 0 || mlt_producer_get_playtime(self) == 0) {
position = 0;
} else if (mlt_properties_exists(MLT_PRODUCER_PROPERTIES(self), "_loop_start")) {
int loopStart = mlt_properties_get_int(MLT_PRODUCER_PROPERTIES(self), "_loop_start");
int loopEnd = mlt_properties_get_int(MLT_PRODUCER_PROPERTIES(self), "_loop_end");
if (loopStart >= 0 && loopEnd > 0 && loopStart < loopEnd) {
if (position > loopEnd || position < loopStart) {
position = loopStart;
}
}
} else if (use_points && (eof == NULL || !strcmp(eof, "pause"))
&& position >= mlt_producer_get_playtime(self)) {
mlt_producer_set_speed(self, 0);
@@ -1304,3 +1312,28 @@ int mlt_producer_probe(mlt_producer self)
}
return 0;
}

/** Set the loop range for the producer.
*
* When the loop range is set, the producer will automatically seek to the start frame
* after it provides the end frame. Set start to -1 to disable looping.
*
* \public \memberof mlt_producer_s
* \param self a producer
* \param start the frame number for the beginning of the loop
* \param end the frame number for the end of the loop
*/

void mlt_producer_set_loop_range(mlt_producer self, int start, int end)
{
if (!self)
return;
mlt_properties properties = MLT_PRODUCER_PROPERTIES(self);
if (start < 0 || end < 0) {
mlt_properties_clear(properties, "_loop_start");
mlt_properties_clear(properties, "_loop_end");
} else {
mlt_properties_set_int(properties, "_loop_start", start);
mlt_properties_set_int(properties, "_loop_end", end);
}
}
1 change: 1 addition & 0 deletions src/framework/mlt_producer.h
Original file line number Diff line number Diff line change
@@ -145,5 +145,6 @@ extern void mlt_producer_close(mlt_producer self);
int64_t mlt_producer_get_creation_time(mlt_producer self);
void mlt_producer_set_creation_time(mlt_producer self, int64_t creation_time);
extern int mlt_producer_probe(mlt_producer self);
extern void mlt_producer_set_loop_range(mlt_producer self, int start, int end);

#endif
5 changes: 5 additions & 0 deletions src/mlt++/MltProducer.cpp
Original file line number Diff line number Diff line change
@@ -266,3 +266,8 @@ bool Producer::probe()
{
return mlt_producer_probe(get_producer());
}

void Producer::set_loop_range(int start, int end)
{
return mlt_producer_set_loop_range(get_producer(), start, end);
}
1 change: 1 addition & 0 deletions src/mlt++/MltProducer.h
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ class MLTPP_DECLSPEC Producer : public Service
int64_t get_creation_time();
void set_creation_time(int64_t creation_time);
bool probe();
void set_loop_range(int start, int end);
};
} // namespace Mlt

7 changes: 7 additions & 0 deletions src/mlt++/mlt++.vers
Original file line number Diff line number Diff line change
@@ -733,3 +733,10 @@ MLT_7.14.0 {
"Mlt::Chain::attach_normalizers()";
};
} MLT_7.12.0;

MLT_7.24.0 {
global:
extern "C++" {
"Mlt::Producer::set_loop_range(int, int)";
};
} MLT_7.14.0;

0 comments on commit 1e9f104

Please sign in to comment.