Skip to content

Commit

Permalink
Use max fps for CompositeVideoClip (#610)
Browse files Browse the repository at this point in the history
As of commit c0f6925, concatenate_videoclips uses the max fps of the
video clips.

This commit adds the same functionality for CompositeVideoClip.
  • Loading branch information
scherroman authored and bearney74 committed Jul 17, 2017
1 parent 9664b38 commit 5a3cb6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions moviepy/video/compositing/CompositeVideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

Expand All @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions tests/test_PR.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 5a3cb6e

Please sign in to comment.