Replies: 1 comment
|
I don't have a strong opposition to this change since it is self-contained and backwards compatible. But... If you give the user fractional speeds, they will ask for continuous audio. I have been thinking about this in the past and had considered adding this to the consumer implementation instead of the producer service. I would see it working something like this:
The downside to this is that the consumer implementation would add an optional dependency on a resampler (probably SRC) and pitch compensation (probably rubberband). Since we already have proven examples for these capabilities in producer_timewarp and link_timeremap, your favorite AI coding assistant could probably whip up a demo pretty fast. |
Uh oh!
There was an error while loading. Please reload this page.
Support fractional playback speeds in mlt_producer
Background & Problem
Currently,
mlt_producer_prepare_next()advances the playhead position using:Because
mlt_producer_position()returnsmlt_position(int32_t) andmlt_producer_seek()takesmlt_position, non-integer speeds are integer-truncated on every frame tick:position + 1.5truncates to+1frame every step (plays at 1.0X).position + 0.5truncates to+0every step (freezes playback completely).As discussed in #541, changing
mlt_positionfromint32_ttodoubleis not viable because it breaks the external/internal ABI and C++ APIProposed Solution:
We can support precise fractional playback speeds without modifying
mlt_positionby using a sub-frame accumulator stored as a producer property (_sub_position):_sub_position = 0.0inmlt_producer_init()._sub_position = 0.0inmlt_producer_set_speed()when speed changes.mlt_producer_prepare_next(), accumulate the fractional speed on each step:How It Works in Practice
sub_pos = 1.5->step = 1,remainder = 0.5sub_pos = 2.0->step = 2,remainder = 0.00 -> 1 -> 3 -> 4 -> 6 -> 7 -> 9sub_pos = 0.5->step = 0,remainder = 0.5sub_pos = 1.0->step = 1,remainder = 0.00, 0, 1, 1, 2, 2...stepis always an exact integer, remainder is0.0, resulting in behavior identical to the current implementation.I have started testing this change on Kdenlive locally, please let me know what you think!
All reactions