r/moviepy•
FlorianN1990B

Resize error

Hi everyone,

I am currently working on a project to animate PNG graphics into an MP4. At the beginning I have a GPX file containing several (thousand) track points and I like to produce a video from it where analogue gauges display these values.

So I created myself two PNG's, one with the faceplate, and one with the needle.

def __rotate_needle():
    for v in values:
        if v['duration'] > 0:
            rotImg = self.__animateNeedleRotation(
                v['angleFrom'],
                v['angleTo'],
                v['duration'],
                needleImg
            )
    needleList.append(rotImg)

def __animateNeedleRotation(self, aFrom, aTo, dur, needleImg):
    baseNeedle = getattr(self, needleImg).set_duration(dur)
    delta = (aFrom - aTo) / dur

    # Invert starting angle because of rotation direction.
    aFrom = aFrom * -1

    # Rotate needle
    return baseNeedle.rotate(lambda t: aFrom+t*delta)

So far, I expect to have a list with a bunch of rotated needles. For the simplicity of this post, I striped off where __rotate_needle() gets all its variables from.

Lastly I run the following to fuse all images together into a clip.

needleClip = mpy.concatenate_videoclips(needleList, \
    method="compose", bg_color=None)
gaugeclip = [
    faceplateClip \
        .resize(self._Size) \
        .set_position('center'),
    needleClip \
        .resize(self._Size) \
        .set_position('center')
]
gaugeclip = mpy.CompositeVideoClip(gaugeclip)

# Get clips in order. First clip will be played at the bottom, last at
# the top.
composition = [
    bgClip,
    gaugeclip.set_position(self._Position)
]
final_video = mpy.CompositeVideoClip(composition)

But here comes the tricky part! Depending on how many trackpoints my GPX file holds, the needle is displayed in different sizes! Even though needleClip.size returns the correct value each time.

What am I doing wrong?

In advance, thanks for your help!

Florian

Posted Apr 26, 2017, 6:08 PM UTC

10
Loading comments…