I'm using Ubuntu 22.04.1 LTS and when I try to run a Python code that uses the moviepy library, it returns an error related to ImageMagick:
My simple code:
from moviepy.editor import *
text = TextClip("test", fontsize=24, color='white')
text = text.set_duration(10)
background = ColorClip((1920, 1080), color=(0, 0, 0))
background = background.set_duration(10)
test_video = CompositeVideoClip([background, text.set_pos(('right', 'bottom'))])
The error when I run python3 code.py
(I'm using virtual env called ttenv
):
Traceback (most recent call last):
File "/home/myuser/project/ttenv/lib/python3.10/site-packages/moviepy/video/VideoClip.py", line 1137, in __init__
subprocess_call(cmd, logger=None)
File "/home/myuser/project/ttenv/lib/python3.10/site-packages/moviepy/tools.py", line 54, in subprocess_call
raise IOError(err.decode('utf8'))
OSError: convert: delegate library support not built-in '/usr/share/fonts/type1/gsfonts/n022003l.pfb' (Freetype) @ warning/annotate.c/RenderFreetype/2067.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/741.
convert: no images defined `PNG32:/tmp/tmpg4dfl7dq.png' @ error/convert.c/ConvertImageCommand/3342.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/myuser/project/make-video.py", line 4, in <module>
text = TextClip("test", fontsize=24, color='white')
File "/home/pedro/tt-project/ttenv/lib/python3.10/site-packages/moviepy/video/VideoClip.py", line 1146, in __init__
raise IOError(error)
OSError: MoviePy Error: creation of None failed because of the following error:
convert: delegate library support not built-in '/usr/share/fonts/type1/gsfonts/n022003l.pfb' (Freetype) @ warning/annotate.c/RenderFreetype/2067.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/741.
convert: no images defined `PNG32:/tmp/tmpg4dfl7dq.png' @ error/convert.c/ConvertImageCommand/3342.
.
.This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect
My /etc/ImageMagick-6/policy.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policymap [
<!ELEMENT policymap (policy)*>
<!ATTLIST policymap xmlns CDATA #FIXED ''>
<!ELEMENT policy EMPTY>
<!ATTLIST policy xmlns CDATA #FIXED '' domain NMTOKEN #REQUIRED
name NMTOKEN #IMPLIED pattern CDATA #IMPLIED rights NMTOKEN #IMPLIED
stealth NMTOKEN #IMPLIED value CDATA #IMPLIED>
]>
<!--
Configure ImageMagick policies.
Domains include system, delegate, coder, filter, path, or resource.
Rights include none, read, write, execute and all. Use | to combine them,
for example: "read | write" to permit read from, or write to, a path.
Use a glob expression as a pattern.
Suppose we do not want users to process MPEG video images:
<policy domain="delegate" rights="none" pattern="mpeg:decode" />
Here we do not want users reading images from HTTP:
<policy domain="coder" rights="none" pattern="HTTP" />
The /repository file system is restricted to read only. We use a glob
expression to match all paths that start with /repository:
<policy domain="path" rights="read" pattern="/repository/*" />
Lets prevent users from executing any image filters:
<policy domain="filter" rights="none" pattern="*" />
Any large image is cached to disk rather than memory:
<policy domain="resource" name="area" value="1GP"/>
Use the default system font unless overwridden by the application:
<policy domain="system" name="font" value="/usr/share/fonts/favorite.ttf"/>
Define arguments for the memory, map, area, width, height and disk resources
with SI prefixes (.e.g 100MB). In addition, resource policies are maximums
for each instance of ImageMagick (e.g. policy memory limit 1GB, -limit 2GB
exceeds policy maximum so memory limit is 1GB).
Rules are processed in order. Here we want to restrict ImageMagick to only
read or write a small subset of proven web-safe image types:
<policy domain="delegate" rights="none" pattern="*" />
<policy domain="filter" rights="none" pattern="*" />
<policy domain="coder" rights="none" pattern="*" />
-->
<policy domain="coder" rights="read|write" pattern="{GIF,JPEG,PNG,WEBP}" />
<policymap>
<policy domain="resource" name="temporary-path" value="/tmp"/>
<policy domain="resource" name="memory" value="256MiB"/>
<policy domain="resource" name="map" value="512MiB"/>
<policy domain="resource" name="width" value="16KP"/>
<policy domain="resource" name="height" value="16KP"/>
<!-- <policy domain="resource" name="list-length" value="128"/> -->
<policy domain="resource" name="area" value="128MP"/>
<policy domain="resource" name="disk" value="1GiB"/>
<!-- <policy domain="resource" name="file" value="768"/> -->
<!-- <policy domain="resource" name="thread" value="4"/> -->
<!-- <policy domain="resource" name="throttle" value="0"/> -->
<!-- <policy domain="resource" name="time" value="3600"/> -->
<!-- <policy domain="coder" rights="none" pattern="MVG" /> -->
<!-- <policy domain="module" rights="none" pattern="{PS,PDF,XPS}" /> -->
<!-- <policy domain="cache" name="memory-map" value="anonymous"/> -->
<!-- <policy domain="cache" name="synchronize" value="True"/> -->
<!-- <policy domain="cache" name="shared-secret" value="passphrase" stealth="true"/> -->
<!-- <policy domain="system" name="max-memory-request" value="256MiB"/> -->
<!-- <policy domain="system" name="shred" value="2"/> -->
<!-- <policy domain="system" name="precision" value="6"/> -->
<!-- <policy domain="system" name="font" value="/path/to/font.ttf"/> -->
<!-- <policy domain="system" name="pixel-cache-memory" value="anonymous"/> -->
<!-- <policy domain="system" name="shred" value="2"/> -->
<!-- <policy domain="system" name="precision" value="6"/> -->
<!-- not needed due to the need to use explicitly by mvg: -->
<!-- <policy domain="delegate" rights="none" pattern="MVG" /> -->
<!-- use curl -->
<policy domain="delegate" rights="none" pattern="URL" />
<policy domain="delegate" rights="none" pattern="HTTPS" />
<policy domain="delegate" rights="none" pattern="HTTP" />
<!-- in order to avoid to get image with password text -->
<policy domain="path" rights="none" pattern="@*"/>
<!-- disable ghostscript format types -->
<policy domain="coder" rights="none" pattern="PS" />
<policy domain="coder" rights="none" pattern="PS2" />
<policy domain="coder" rights="none" pattern="PS3" />
<policy domain="coder" rights="none" pattern="EPS" />
<policy domain="coder" rights="none" pattern="PDF" />
<policy domain="coder" rights="none" pattern="XPS" />
<policy domain="coder" rights="none" pattern="TEXT" />
</policymap>
My /usr/share/fonts/type1/gsfonts
permissions:
-rwxrwxrwx 1 root root
for all files
I've already tried this solutions:
- Updating it to the latest version running
sudo apt-get update && sudo apt-get upgrade
- Giving permissions on
/tmp
and on font's file to my user - Changing some configurations on
policy.xml
Edit:
The
file /usr/share/fonts/type1/gsfonts/n022003l.pfb
output:/usr/share/fonts/type1/gsfonts/n022003l.pfb: PostScript Type 1 font program data (NimbusMonL-Regu 1.06)
The
ls -l /user/share/fonts/type1/gsfonts/n022003l.pfb
output:-rwxrwxrwx 1 root root 94786 jan 3 15:54 /usr/share/fonts/type1/gsfonts/n022003l.pfb
The
convert -debug all -font /usr/share/fonts/type1/gsfonts/n022003l.pfb -pointsize 48 label:"Hello World" hello.png
output:2023-01-05T04:13:50+00:00 0:00.000 0.000u 7.1.0 Configure convert[4089]: utility.c/ExpandFilenames/973/Configure Command line: convert {-debug} {all} {-font} {/usr/share/fonts/type1/gsfonts/n022003l.pfb} {-pointsize} {48} {label:Hello World} {hello.png} 2023-01-05T04:13:50+00:00 0:00.000 0.000u 7.1.0 Policy convert[4089]: policy.c/IsRightsAuthorized/647/Policy Domain: Module; rights=Unrecognized; pattern="LABEL" ... 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Policy convert[4089]: policy.c/IsRightsAuthorized/647/Policy Domain: Coder; rights=Read; pattern="LABEL" ... 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Pixel convert[4089]: pixel.c/SetPixelChannelMask/6307/Pixel Hello World[07ffffff] 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Pixel convert[4089]: pixel.c/LogPixelChannels/6191/Pixel Hello World[07ffffff] 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Pixel convert[4089]: pixel.c/LogPixelChannels/6288/Pixel 0: red (update) 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Pixel convert[4089]: pixel.c/LogPixelChannels/6288/Pixel 1: green (update) 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Pixel convert[4089]: pixel.c/LogPixelChannels/6288/Pixel 2: blue (update) 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireMagickResource/390/Resource Area: 1B/0B/15.4046GiB 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireMagickResource/390/Resource Memory: 12B/12B/7.70229GiB 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Cache convert[4089]: cache.c/OpenPixelCache/3798/Cache open Hello World[0] (Heap Memory, 1x1x3 12B) 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Cache convert[4089]: cache.c/DestroyPixelCache/1064/Cache destroy Hello World[0] 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Resource convert[4089]: resource.c/RelinquishMagickResource/1074/Resource Memory: 12B/0B/7.70229GiB 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireMagickResource/390/Resource Width: 264B/0B/409.6PiB 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Locale convert[4089]: locale.c/GetLocaleOptions/824/Locale Searching for locale file: "/usr/local/share/ImageMagick-7/locale.xml" 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Locale convert[4089]: locale.c/GetLocaleOptions/824/Locale Searching for locale file: "/usr/local/lib/ImageMagick-7.1.0//config-Q16HDRI/locale.xml" 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Locale convert[4089]: locale.c/GetLocaleOptions/824/Locale Searching for locale file: "/usr/local/etc/ImageMagick-7/locale.xml" 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Locale convert[4089]: locale.c/GetLocaleOptions/824/Locale Searching for locale file: "/usr/local/share/doc/ImageMagick-7/locale.xml" 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Locale convert[4089]: locale.c/GetLocaleOptions/824/Locale Searching for locale file: "/home/pedro/.config/ImageMagick/locale.xml" 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Configure convert[4089]: locale.c/LoadLocaleCache/1177/Configure Loading locale configure file "/usr/local/share/ImageMagick-7/locale.xml" ... 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Locale convert[4089]: locale.c/GetLocaleOptions/824/Locale Searching for locale file: "/usr/local/share/ImageMagick-7/english.xml" 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Locale convert[4089]: locale.c/GetLocaleOptions/824/Locale Searching for locale file: "/usr/local/lib/ImageMagick-7.1.0//config-Q16HDRI/english.xml" 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Locale convert[4089]: locale.c/GetLocaleOptions/824/Locale Searching for locale file: "/usr/local/etc/ImageMagick-7/english.xml" 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Locale convert[4089]: locale.c/GetLocaleOptions/824/Locale Searching for locale file: "/usr/local/share/doc/ImageMagick-7/english.xml" 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Locale convert[4089]: locale.c/GetLocaleOptions/824/Locale Searching for locale file: "/home/pedro/.config/ImageMagick/english.xml" 2023-01-05T04:13:50+00:00 0:00.001 0.000u 7.1.0 Configure convert[4089]: locale.c/LoadLocaleCache/1177/Configure Loading locale configure file "/usr/local/share/ImageMagick-7/english.xml" ... 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Exception convert[4089]: annotate.c/RenderFreetype/2067/Exception delegate library support not built-in '/usr/share/fonts/type1/gsfonts/n022003l.pfb' (Freetype) 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Annotate convert[4089]: annotate.c/RenderPostscript/2193/Annotate Font /usr/share/fonts/type1/gsfonts/n022003l.pfb; pointsize 48 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireUniqueFileResource/584/Resource ... 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireUniqueFileResource/641/Resource /tmp/magick-jFaf2l7OrlfUHLbBH6k8gV6rt2rScPzL 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Policy convert[4089]: policy.c/IsRightsAuthorized/647/Policy Domain: Module; rights=Unrecognized; pattern="PS" ... 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Policy convert[4089]: policy.c/IsRightsAuthorized/647/Policy Domain: Path; rights=Read; pattern="/tmp/magick-jFaf2l7OrlfUHLbBH6k8gV6rt2rScPzL" ... 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Blob convert[4089]: blob.c/OpenBlob/3453/Blob read 3 magic header bytes 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Cache convert[4089]: cache.c/DestroyPixelCache/1064/Cache destroy 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Policy convert[4089]: policy.c/IsRightsAuthorized/647/Policy Domain: Coder; rights=Read; pattern="PS" ... 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Policy convert[4089]: policy.c/IsRightsAuthorized/647/Policy Domain: Path; rights=Read; pattern="/tmp/magick-jFaf2l7OrlfUHLbBH6k8gV6rt2rScPzL" ... 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Blob convert[4089]: blob.c/OpenBlob/3453/Blob read 3 magic header bytes 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireUniqueFileResource/584/Resource ... 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireUniqueFileResource/641/Resource /tmp/magick-faN1FzvtOzDGwqP1YcnLHRxwC4IEtWRQ 2023-01-05T04:13:50+00:00 0:00.002 0.000u 7.1.0 Resource convert[4089]: resource.c/RelinquishUniqueFileResource/1113/Resource /tmp/magick-faN1FzvtOzDGwqP1YcnLHRxwC4IEtWRQ 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireUniqueFileResource/584/Resource ... 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireUniqueFileResource/641/Resource /tmp/magick-YZX9RZBSyTVr3ShLu0CNAr_BqGDvAgCI 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Configure convert[4089]: configure.c/GetConfigureOptions/695/Configure Searching for configure file: "/usr/local/share/ImageMagick-7/delegates.xml" 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Configure convert[4089]: configure.c/GetConfigureOptions/695/Configure Searching for configure file: "/usr/local/lib/ImageMagick-7.1.0//config-Q16HDRI/delegates.xml" 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Configure convert[4089]: configure.c/GetConfigureOptions/695/Configure Searching for configure file: "/usr/local/etc/ImageMagick-7/delegates.xml" 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Configure convert[4089]: configure.c/GetConfigureOptions/695/Configure Searching for configure file: "/usr/local/share/doc/ImageMagick-7/delegates.xml" 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Configure convert[4089]: configure.c/GetConfigureOptions/695/Configure Searching for configure file: "/home/pedro/.config/ImageMagick/delegates.xml" 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Configure convert[4089]: delegate.c/LoadDelegateCache/2094/Configure Loading delegate configuration file "/usr/local/etc/ImageMagick-7/delegates.xml" ... 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireUniqueFileResource/584/Resource ... 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireUniqueFileResource/641/Resource /tmp/magick-IjaxzuCSMrQfTLIUilHJYLnuZLFP8Sjb 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Resource convert[4089]: resource.c/RelinquishUniqueFileResource/1113/Resource /tmp/magick-IjaxzuCSMrQfTLIUilHJYLnuZLFP8Sjb 2023-01-05T04:13:50+00:00 0:00.003 0.000u 7.1.0 Policy convert[4089]: policy.c/IsRightsAuthorized/647/Policy Domain: Delegate; rights=Execute; pattern="gs" ... 2023-01-05T04:13:50+00:00 0:00.063 0.000u 7.1.0 Resource convert[4089]: resource.c/RelinquishUniqueFileResource/1113/Resource /tmp/magick-YZX9RZBSyTVr3ShLu0CNAr_BqGDvAgCI 2023-01-05T04:13:50+00:00 0:00.063 0.000u 7.1.0 Resource convert[4089]: resource.c/RelinquishUniqueFileResource/1113/Resource /tmp/magick-faN1FzvtOzDGwqP1YcnLHRxwC4IEtWRQ 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Policy convert[4089]: policy.c/IsRightsAuthorized/647/Policy Domain: Path; rights=Read; pattern="/tmp/magick-IjaxzuCSMrQfTLIUilHJYLnuZLFP8Sjb1" ... 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Blob convert[4089]: blob.c/OpenBlob/3453/Blob read 3 magic header bytes 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Cache convert[4089]: cache.c/DestroyPixelCache/1064/Cache destroy 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Policy convert[4089]: policy.c/IsRightsAuthorized/647/Policy Domain: Path; rights=Read; pattern="/tmp/magick-IjaxzuCSMrQfTLIUilHJYLnuZLFP8Sjb1" ... 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Blob convert[4089]: blob.c/OpenBlob/3453/Blob read 3 magic header bytes 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Cache convert[4089]: cache.c/DestroyPixelCache/1064/Cache destroy 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Exception convert[4089]: constitute.c/ReadImage/741/Exception no decode delegate for this image format `' 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Resource convert[4089]: resource.c/RelinquishUniqueFileResource/1113/Resource /tmp/magick-IjaxzuCSMrQfTLIUilHJYLnuZLFP8Sjb1 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Resource convert[4089]: resource.c/RelinquishUniqueFileResource/1113/Resource /tmp/magick-IjaxzuCSMrQfTLIUilHJYLnuZLFP8Sjb1 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Cache convert[4089]: cache.c/DestroyPixelCache/1064/Cache destroy convert: delegate library support not built-in '/usr/share/fonts/type1/gsfonts/n022003l.pfb' (Freetype) @ warning/annotate.c/RenderFreetype/2067. convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/741. 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Resource convert[4089]: resource.c/RelinquishUniqueFileResource/1113/Resource /tmp/magick-jFaf2l7OrlfUHLbBH6k8gV6rt2rScPzL 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Annotate convert[4089]: annotate.c/GetTypeMetrics/933/Annotate Metrics: text: Hello World; width: 0; height: 0; ascent: 0; descent: 0; max advance: 0; bounds: 0,0 0,0; origin: 0,0; pixels per em: 0,0; underline position: 0; underline thickness: 0 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Resource convert[4089]: resource.c/AcquireMagickResource/390/Resource Height: 0B/0B/409.6PiB 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Cache convert[4089]: cache.c/DestroyPixelCache/1064/Cache destroy 2023-01-05T04:13:50+00:00 0:00.064 0.000u 7.1.0 Exception convert[4089]: convert.c/ConvertImageCommand/3342/Exception no images defined `hello.png' convert: no images defined `hello.png' @ error/convert.c/ConvertImageCommand/3342.
Trying to use a
.ttf
font withconvert -font /usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf -pointsize 48 label:"Hello World" hello.png
returns an error too:convert: delegate library support not built-in '/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf' (Freetype) @ warning/annotate.c/RenderFreetype/2067. convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/741. convert: no images defined `hello.png' @ error/convert.c/ConvertImageCommand/3342.