Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a loop range feature to MLT Producer #964

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/framework/mlt.vers
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions src/mlt++/mlt++.vers
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading