Skip to content

Video editing with Python

fix Issue 368.. ValueError: Invalid value for quantizer: 'wu' (#460)

Billy Earneyf221a18b9d39
diff --git a/.travis.yml b/.travis.yml
index e117f29f..efeaef85 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,7 +12,8 @@ before_install:
- sudo apt-get -y update
- sudo apt-get install -y ffmpeg
- mkdir media
-install:
+install:
+ - if [[ $TRAVIS_PYTHON_VERSION == '3.4' || $TRAVIS_PYTHON_VERSION == '3.5' || $TRAVIS_PYTHON_VERSION == '3.6' ]]; then pip install matplotlib; pip install -U scikit-learn; pip install scipy; fi
- pip install coveralls
- pip install pytest-cov
- python setup.py install
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index e4ec0572..9a8f0aee 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -408,7 +408,7 @@ class VideoClip(Clip):
@requires_duration
@convert_masks_to_RGB
def write_gif(self, filename, fps=None, program='imageio',
- opt=0, fuzz=1, verbose=True,
+ opt='nq', fuzz=1, verbose=True,
loop=0, dispose=False, colors=None, tempfiles=False):
""" Write the VideoClip to a GIF file.
@@ -464,7 +464,7 @@ class VideoClip(Clip):
#convert imageio opt variable to something that can be used with
#ImageMagick
opt1=opt
- if opt1 == 0:
+ if opt1 == 'nq':
opt1='optimizeplus'
else:
opt1='OptimizeTransparency'
diff --git a/moviepy/video/io/gif_writers.py b/moviepy/video/io/gif_writers.py
index 9de07d47..b46e5c58 100644
--- a/moviepy/video/io/gif_writers.py
+++ b/moviepy/video/io/gif_writers.py
@@ -277,7 +277,7 @@ def write_gif_with_image_io(clip, filename, fps=None, opt=0, loop=0,
if fps is None:
fps = clip.fps
- quantizer = 0 if opt!= 'nq' else 'nq'
+ quantizer = 0 if opt!= 0 else 'nq'
writer = imageio.save(filename, duration=1.0/fps,
quantizer=quantizer, palettesize=colors)
diff --git a/tests/test_issues.py b/tests/test_issues.py
index 6754cac4..1b9c2589 100644
--- a/tests/test_issues.py
+++ b/tests/test_issues.py
@@ -28,7 +28,6 @@ def test_issue_285():
merged_clip = concatenate_videoclips([clip_1, clip_2, clip_3])
assert merged_clip.duration == 30
-
def test_issue_354():
clip = ImageClip("media/python_logo.png")
@@ -46,6 +45,48 @@ def test_issue_359():
video.fps=30
video.write_gif(filename="/tmp/issue_359.gif", tempfiles=True)
+def test_issue_368():
+ import sys
+ if sys.version_info < (3,4): #matplotlib only supported in python >= 3.4
+ return
+
+ # $DISPLAY not set error in (travis-ci) python 3.5, so ignore 3.5 for now
+ if sys.version_info.major == 3 and sys.version_info.minor ==5:
+ return
+
+ import numpy as np
+ import matplotlib.pyplot as plt
+ from sklearn import svm
+ from sklearn.datasets import make_moons
+ from moviepy.video.io.bindings import mplfig_to_npimage
+ import imageio
+
+ X, Y = make_moons(50, noise=0.1, random_state=2) # semi-random data
+
+ fig, ax = plt.subplots(1, figsize=(4, 4), facecolor=(1,1,1))
+ fig.subplots_adjust(left=0, right=1, bottom=0)
+ xx, yy = np.meshgrid(np.linspace(-2,3,500), np.linspace(-1,2,500))
+
+ def make_frame(t):
+ ax.clear()
+ ax.axis('off')
+ ax.set_title("SVC classification", fontsize=16)
+
+ classifier = svm.SVC(gamma=2, C=1)
+ # the varying weights make the points appear one after the other
+ weights = np.minimum(1, np.maximum(0, t**2+10-np.arange(50)))
+ classifier.fit(X, Y, sample_weight=weights)
+ Z = classifier.decision_function(np.c_[xx.ravel(), yy.ravel()])
+ Z = Z.reshape(xx.shape)
+ ax.contourf(xx, yy, Z, cmap=plt.cm.bone, alpha=0.8,
+ vmin=-2.5, vmax=2.5, levels=np.linspace(-2,2,20))
+ ax.scatter(X[:,0], X[:,1], c=Y, s=50*weights, cmap=plt.cm.bone)
+
+ return mplfig_to_npimage(fig)
+
+ animation = VideoClip(make_frame,duration=2)
+ animation.write_gif("/tmp/svm.gif",fps=20)
+
def test_issue_407():
red = ColorClip((800, 600), color=(255,0,0)).set_duration(5)
red.fps=30