Search code examples
python-3.xffmpegmoviepy

Mirrored Arabic Letters using TextClip Moviepy


I am trying to render the video which contains arabic letters. let's use مرحبا for the example. After video rendered the result is mirrored.

background = mp.ColorClip(mobile_size, (255, 255, 255), duration=0.5) #float(audiolength.info.length)
text1 = mp.TextClip(english, fontsize=45, color=fcolor, font=Font, size= (mobile_size[0], 185), method = 'caption', align="south").set_duration(0.5) #float(audiolength.info.length)
text2 = mp.TextClip(formatChineseSentences(translated).encode("utf-8"), fontsize=45, color=fcolor2, font=Font, size= (mobile_size[0], 185), method = 'caption', align="north").set_duration(0.5) #float(audiolength.info.length)

clip1 = mp.CompositeVideoClip([background, text1.set_position(('center', "top")), text2.set_position(('center', "bottom"))])

Expected Behavior

Correct Arrabic Letter

Actual Behavior

Mirrored Arabic Letter

Steps to Reproduce the Problem

Rendering TextClip with Arabic Characters. For this case we can use مرحبا.

Specifications

Python Version: Python 3.8.5 Moviepy Version: 1.0.3 Platform Name: Mac OS Catalina Platform Version: 10.15.6


Solution

  • Problem solved. The solution is to reshape and reverse the font.

    import arabic_reshaper
    from bidi.algorithm import get_display
    
    def formatArabicSentences(sentences):
       formatedSentences = arabic_reshaper.reshape(sentences)
       return get_display(formatedSentences)