Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too stupid to rotate :D #22

Closed
oxivanisher opened this issue Mar 19, 2014 · 6 comments
Closed

Too stupid to rotate :D #22

oxivanisher opened this issue Mar 19, 2014 · 6 comments

Comments

@oxivanisher
Copy link
Contributor

Hi all

I really love this project. It helps me with a problem i have since three years and my sister finally will have a wedding video and not only photos. But now i am facing a problem.
I try to rotate the Images which are somehow not rotated from ffmpeg. The EXIF rotation tag allows me to detect if the image is "wrong", so that is not a problem. But i don't know how to use rotation correctly. Here is my test code:

if imgData['orientation'] == 1:
    clips.append(ImageClip(imgData['path']).resize(height = HEIGHT).set_pos('center').set_start(clipStart).fadein(FADEIN).set_duration(IMGDURATION).crossfadeout(FADEOUT)) #, width = WIDTH
else:
    #please rotate the image...
    clip = ImageClip(imgData['path']).resize(width = HEIGHT).set_pos('center').set_start(clipStart).fadein(FADEIN).set_duration(IMGDURATION).crossfadeout(FADEOUT)
    clip1 = vfx.rotation(clip, -90)
    video = CompositeVideoClip([clip1], size = MOVIESIZE)
    video.to_videofile(DSTPATH + "/video.avi", fps=25, codec=CODEC)

I tried around and fiddled with it, but did not get behind how to do this correctly. Finally all these images are put into a list (clips) and rendered over another background video. This video rendering here is just for testing purposes.
The error output i get is:

  File "/usr/local/lib/python2.7/dist-packages/moviepy/video/VideoClip.py", line 325, in blit_on
    return blit(img, picture, pos, mask=mask, ismask=self.ismask)
  File "/usr/local/lib/python2.7/dist-packages/moviepy/video/tools/drawing.py", line 43, in blit
    1.0 * mask * blitted + (1.0 - mask) * blit_region)
ValueError: operands could not be broadcast together with shapes (3,717,3) (3,1080,717)

Can you give me a hint how to do this right?
Thanks and have a nice day. :)
gn8 from switzerland

@Zulko
Copy link
Owner

Zulko commented Mar 20, 2014

This was a bug, I just fixed it on github and pypi. Tell me if it works !

@oxivanisher
Copy link
Contributor Author

I will tell you as soon as i can. Probably in about 12 hours.

@Zulko
Copy link
Owner

Zulko commented Mar 20, 2014

Yeah sure, no hurry, have a nice day :)

@oxivanisher
Copy link
Contributor Author

It works like a charm! Thank you very much 💃

@tburrows13
Copy link
Collaborator

I know this a long shot, but @oxivanisher can you tell me where you got your imgData['orientation']? I am trying to find a way for python to automatically find the orientation, and nothing has come up yet. Thanks

@oxivanisher
Copy link
Contributor Author

oxivanisher commented Dec 25, 2016

Hi @Gloin1313

It took me some digging to find this 3 year old script, but i did get lucky. I used the following code (just copy & pasted the relevant stuff):

from moviepy.editor import *
from PIL import Image as PILImage
from PIL import ExifTags

for filepath in files:
    data = []
    img = PILImage.open(filepath)
    exif = {
        ExifTags.TAGS[k]: v
        for k, v in img._getexif().items()
        if k in ExifTags.TAGS
    }

    data.append({'path'       : filepath,
                 'camModel'   : exif['Model'],
                 'camMake'    : exif['Make'],
                 'orientation': exif['Orientation'], })

and then further down

    if imgData['orientation'] == 1:
        clip = ImageClip(imgData['path']).resize(height = HEIGHT).set_pos('center').set_start(clipStart).fadein(FADEIN).set_duration(IMGDURATION).crossfadeout(FADEOUT) #, width = WIDTH
    else:
        clip = vfx.rotation(ImageClip(imgData['path']).resize(width = HEIGHT).set_pos('center').set_start(clipStart).fadein(FADEIN).set_duration(IMGDURATION).crossfadeout(FADEOUT), 90)

Hopefully this helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants