Skip to content

Video editing with Python

Fix credits, added tests

Tom Burrows1f25e8f2d068
diff --git a/moviepy/video/tools/credits.py b/moviepy/video/tools/credits.py
index 14d50a5f..dbc023b9 100644
--- a/moviepy/video/tools/credits.py
+++ b/moviepy/video/tools/credits.py
@@ -6,7 +6,7 @@ matter.
from moviepy.video.VideoClip import TextClip, ImageClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
-from moviepy.video.fx import resize
+from moviepy.video.fx.resize import resize
def credits1(creditfile, width, stretch=30, color='white', stroke_color='black',
@@ -37,25 +37,38 @@ def credits1(creditfile, width, stretch=30, color='white', stroke_color='black',
Total width of the credits text in pixels
gap
- Gap in pixels between the jobs and the names.
-
- **txt_kw
- Additional argument passed to TextClip (font, colors, etc.)
-
+ Horizontal gap in pixels between the jobs and the names
+ color
+ Color of the text. See ``TextClip.list('color')``
+ for a list of acceptable names.
+
+ font
+ Name of the font to use. See ``TextClip.list('font')`` for
+ the list of fonts you can use on your computer.
+
+ fontsize
+ Size of font to use
+
+ stroke_color
+ Color of the stroke (=contour line) of the text. If ``None``,
+ there will be no stroke.
+
+ stroke_width
+ Width of the stroke, in pixels. Can be a float, like 1.5.
Returns
---------
image
- An ImageClip instance that looks like this and can be scrolled
- to make some credits:
-
- Executive Story Editor MARCEL DURAND
- Associate Producers MARTIN MARCEL
- DIDIER MARTIN
- Music Supervisor JEAN DIDIER
+ An ImageClip instance that looks like this and can be scrolled
+ to make some credits:
+
+ Executive Story Editor MARCEL DURAND
+ Associate Producers MARTIN MARCEL
+ DIDIER MARTIN
+ Music Supervisor JEAN DIDIER
"""
@@ -93,11 +106,11 @@ def credits1(creditfile, width, stretch=30, color='white', stroke_color='black',
cc = CompositeVideoClip([left, right.set_pos((left.w+gap, 0))],
size=(left.w+right.w+gap, right.h),
- transparent=True)
+ bg_color=None)
# SCALE TO THE REQUIRED SIZE
- scaled = cc.fx(resize, width=width)
+ scaled = resize(cc, width=width)
# TRANSFORM THE WHOLE CREDIT CLIP INTO AN ImageCLip
diff --git a/tests/test_videotools.py b/tests/test_videotools.py
new file mode 100644
index 00000000..c4016359
--- /dev/null
+++ b/tests/test_videotools.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+"""Video file clip tests meant to be run with pytest."""
+import sys
+import os
+
+from moviepy.video.tools.credits import credits1
+
+sys.path.append("tests")
+from test_helper import TMP_DIR
+
+
+def test_credits():
+ credit_file = "# This is a comment\n" \
+ "# The next line says : leave 4 blank lines\n" \
+ ".blank 2\n" \
+ "\n" \
+ "..Executive Story Editor\n" \
+ "MARCEL DURAND\n" \
+ "\n" \
+ ".blank 2\n" \
+ "\n" \
+ "..Associate Producers\n" \
+ "MARTIN MARCEL\n" \
+ "DIDIER MARTIN\n" \
+ "\n" \
+ "..Music Supervisor\n" \
+ "JEAN DIDIER\n"
+
+ file_location = os.path.join(TMP_DIR, "credits.txt")
+ vid_location = os.path.join(TMP_DIR, "credits.mp4")
+ with open(file_location, "w") as file:
+ file.write(credit_file)
+
+ image = credits1(file_location, 600, gap=100, stroke_color="blue",
+ stroke_width=5)
+ image = image.set_duration(3)
+ image.write_videofile(vid_location, fps=24)
+ assert os.path.isfile(vid_location)