Search code examples
pythonmaskmoviepyvideo-editing

How can the "thr" and "s" parameters in MoviePy's mask_color function be optimized for maximum quality and minimum rendering time?


I'm trying to separate a white animation from a black background. The results were poor (black pixelation around edges of animation) when using: mask_color(clip, color=[0,0,0]). I know the function's optional parameters thr=SomeNumber and s=SomeNumber will fix this but I'm unsure what they mean and how they can be chosen in the interests of good quality results and quick rendering times.


Solution

  • hi thanks for posting the question. First let's quickly go through the meaning of these parameters;

    • thr: threshold. Only well beyond this threshold is the masking effective, ie transparent
    • s: stiffness. How strong the effect will be.

    So as you can imagine, the values that you would feed into these arguments are highly dependent with your inputs and your desired outputs. So maybe you can let the s be its default, and slowly increase thr from 0 to 100 in a linear manner and inspect its output every steps of 10. then choose the best one. then if this is not satisfactory per your requirement, then you can try fine-tuning the stiffness if this would help you get the output that you need.