From 5a3cb6e78cd473a9b73f19b7cd0a31e371077da7 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 17 Jul 2017 11:18:38 -0400 Subject: [PATCH] Use max fps for CompositeVideoClip (#610) As of commit c0f6925, concatenate_videoclips uses the max fps of the video clips. This commit adds the same functionality for CompositeVideoClip. --- moviepy/video/compositing/CompositeVideoClip.py | 12 ++++++------ tests/test_PR.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/moviepy/video/compositing/CompositeVideoClip.py b/moviepy/video/compositing/CompositeVideoClip.py index e65224864..0b195fe4a 100644 --- a/moviepy/video/compositing/CompositeVideoClip.py +++ b/moviepy/video/compositing/CompositeVideoClip.py @@ -40,8 +40,7 @@ class CompositeVideoClip(VideoClip): have the same size as the final clip. If it has no transparency, the final clip will have no mask. - If all clips with a fps attribute have the same fps, it becomes the fps of - the result. + The clip with the highest FPS will be the FPS of the composite clip. """ @@ -60,10 +59,11 @@ def __init__(self, clips, size=None, bg_color=None, use_bgclip=False, if bg_color is None: bg_color = 0.0 if ismask else (0, 0, 0) - - fps_list = list(set([c.fps for c in clips if hasattr(c,'fps')])) - if len(fps_list)==1: - self.fps= fps_list[0] + fpss = [c.fps for c in clips if hasattr(c, 'fps') and c.fps is not None] + if len(fpss) == 0: + self.fps = None + else: + self.fps = max(fpss) VideoClip.__init__(self) diff --git a/tests/test_PR.py b/tests/test_PR.py index 0c4e2849d..a608c97f7 100644 --- a/tests/test_PR.py +++ b/tests/test_PR.py @@ -8,6 +8,7 @@ from moviepy.video.io.VideoFileClip import VideoFileClip from moviepy.video.tools.interpolators import Trajectory from moviepy.video.VideoClip import ColorClip, ImageClip, TextClip +from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip sys.path.append("tests") from test_helper import TMP_DIR, TRAVIS @@ -112,5 +113,18 @@ def test_PR_529(): assert video_clip.rotation == 180 +def test_PR_610(): + """ + Test that the max fps of the video clips is used for the composite video clip + """ + clip1 = ColorClip((640, 480), color=(255, 0, 0)).set_duration(1) + clip2 = ColorClip((640, 480), color=(0, 255, 0)).set_duration(1) + clip1.fps = 24 + clip2.fps = 25 + composite = CompositeVideoClip([clip1, clip2]) + + assert composite.fps == 25 + + if __name__ == '__main__': pytest.main()