You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into a problem where output frames would be corrupted when using time remapping on some 4K footage. Specifically, the source was a MP4 file, 3840x2160 at 29.8471 Hz, and the rendered output being 30 Hz. The *.mlt I was running came out of a kdenlive project. What I observed was the following:
Nearest mode: Single frames would be corrupted (mostly greenish, arbitrary patterns, looked like something partially decoded)
Blend mode: Looked like corrupted frames would be interpolated/blended with non-corrupted frames
This made me think that it's probably a problem of the data flowing into the time remapping getting corrupted, rather than anything after the remapping. Also, the problem with nearest seemed to mainly appear at the boundary from a sped-up section to a 100% section, and never within the sped-up section. With blend mode the corruption would appear in many more places.
Digging through the code and running a debug build of melt and specially libmltcore with my own tweaks/hacks, I realized the following: Locking and unlocking a pthread_mutex in link_timeremap.c before link_get_image_blend/link_get_image_nearest would call mlt_frame_get_image until after the image data has been copied/processed would completely get rid of the problem. This suggests that there might be a data race on the calls to mlt_frame_get_image, where the returned image buffer might be corrupted by a second call to the function in a concurrent thread.
I'm not familiar enough with the code base and how it uses threading to know where to look to fix this more properly than my ugly static mutex in the critical parts of the code. Are there any considerations related to this in the design of MLT, or does the time remapping hit a new corner case because it requires more random access to input frames? Would this require adding the ability to lock/unlock the returned image data somehow?
The text was updated successfully, but these errors were encountered:
Fix an issue in `link_timeremap.c`, where multiple concurrent threads
calling `mlt_frame_get_image` would cause the returned image data to be
corrupted, or to be consumed incorrectly. As a result, the produced
frames would be seemingly arbitrarily corrupted, more so in "blend" mode
than in "nearest" mode, due to the increased number of frames fetched.
Add a `mlt_service_lock` and `mlt_service_unlock` call around the
critical function calls to ensure data returned is intact.
Fixesmltframework#729.
* Fix data race in time remapping
Fix an issue in `link_timeremap.c`, where multiple concurrent threads
calling `mlt_frame_get_image` would cause the returned image data to be
corrupted, or to be consumed incorrectly. As a result, the produced
frames would be seemingly arbitrarily corrupted, more so in "blend" mode
than in "nearest" mode, due to the increased number of frames fetched.
Add a `mlt_service_lock` and `mlt_service_unlock` call around the
critical function calls to ensure data returned is intact.
Fixes#729.
I ran into a problem where output frames would be corrupted when using time remapping on some 4K footage. Specifically, the source was a MP4 file, 3840x2160 at 29.8471 Hz, and the rendered output being 30 Hz. The
*.mlt
I was running came out of akdenlive
project. What I observed was the following:This made me think that it's probably a problem of the data flowing into the time remapping getting corrupted, rather than anything after the remapping. Also, the problem with nearest seemed to mainly appear at the boundary from a sped-up section to a 100% section, and never within the sped-up section. With blend mode the corruption would appear in many more places.
Digging through the code and running a debug build of
melt
and speciallylibmltcore
with my own tweaks/hacks, I realized the following: Locking and unlocking apthread_mutex
inlink_timeremap.c
beforelink_get_image_blend
/link_get_image_nearest
would callmlt_frame_get_image
until after the image data has been copied/processed would completely get rid of the problem. This suggests that there might be a data race on the calls tomlt_frame_get_image
, where the returned image buffer might be corrupted by a second call to the function in a concurrent thread.I'm not familiar enough with the code base and how it uses threading to know where to look to fix this more properly than my ugly static mutex in the critical parts of the code. Are there any considerations related to this in the design of MLT, or does the time remapping hit a new corner case because it requires more random access to input frames? Would this require adding the ability to lock/unlock the returned image data somehow?
The text was updated successfully, but these errors were encountered: