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

Python2 unicode_literals errors #293

Closed
prokaktus opened this issue May 13, 2016 · 3 comments
Closed

Python2 unicode_literals errors #293

prokaktus opened this issue May 13, 2016 · 3 comments
Labels
bug Issues that report (apparent) bugs.

Comments

@prokaktus
Copy link

prokaktus commented May 13, 2016

Hi!

  • moviepy==0.2.2.11
  • python2.7

Sample file:

from moviepy.editor import ImageClip, VideoFileClip, CompositeVideoClip
filepath = 'server/media/24d9adba48c588111e072939dc47227bb1ec23f8.mp4'
mark = 'media/img/logo.png'


vclip = VideoFileClip(filepath)
iclip = ImageClip(mark, duration=vclip.duration).set_pos(
    ('right', 'bottom', )
)

final = CompositeVideoClip([vclip, iclip])

final.write_videofile('/tmp/test.mp4')

Everything works great. But if I add unicode_literals:

from __future__ import unicode_literals
from moviepy.editor import ImageClip, VideoFileClip, CompositeVideoClip
filepath = 'server/media/24d9adba48c588111e072939dc47227bb1ec23f8.mp4'
mark = 'media/img/logo.png'


vclip = VideoFileClip(filepath)
iclip = ImageClip(mark, duration=vclip.duration).set_pos(
    ('right', 'bottom', )
)

final = CompositeVideoClip([vclip, iclip])

final.write_videofile('/tmp/ttt.mp4')

Script crashes with traceback:

Traceback (most recent call last):
  File "1.tmp", line 8, in <module>
    iclip = ImageClip(mark, duration=vclip.duration).set_pos(
  File ".../lib/python2.7/site-packages/moviepy/video/VideoClip.py", line 897, in __init__
    if len(img.shape) == 3:  # img is (now) a RGB(a) numpy array
AttributeError: 'unicode' object has no attribute 'shape'

If I prepend 'media/img/logo.png' with 'b': b'media/img/logo.png', then stacktrace change to:

[MoviePy] >>>> Building video /tmp/ttt.mp4
[MoviePy] Writing video /tmp/ttt.mp4
  0%|                                                          | 0/157 [00:00<?, ?it/s]Traceback (most recent call last):
  File "1.py", line 16, in <module>
    final.write_videofile('/tmp/ttt.mp4')
  File "<decorator-gen-51>", line 2, in write_videofile
  File "...lib/python2.7/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<decorator-gen-50>", line 2, in write_videofile
  File "...lib/python2.7/site-packages/moviepy/decorators.py", line 137, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "<decorator-gen-49>", line 2, in write_videofile
  File "...lib/python2.7/site-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "...lib/python2.7/site-packages/moviepy/video/VideoClip.py", line 339, in write_videofile
    ffmpeg_params=ffmpeg_params)
  File "...lib/python2.7/site-packages/moviepy/video/io/ffmpeg_writer.py", line 204, in ffmpeg_write_video
    fps=fps, dtype="uint8"):
  File "...lib/python2.7/site-packages/tqdm/_tqdm.py", line 459, in __iter__
    for obj in iterable:
  File "...lib/python2.7/site-packages/moviepy/Clip.py", line 473, in generator
    frame = self.get_frame(t)
  File "<decorator-gen-14>", line 2, in get_frame
  File "...lib/python2.7/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "...lib/python2.7/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "...lib/python2.7/site-packages/moviepy/video/compositing/CompositeVideoClip.py", line 110, in make_frame
    f = c.blit_on(f, t)
  File "...lib/python2.7/site-packages/moviepy/video/VideoClip.py", line 569, in blit_on
    pos = map(int, pos)
ValueError: invalid literal for int() with base 10: 'right'

Workaround to last stacktrace is to prepend 'right' and 'bottom' with 'b': (b'right', b'bottom', )

I've found similar issue, but not exactly the same
#76

I can try to fix it myself, but without tests it can be really dangerous. @Zulko can you consider adding at least some tests from #121? Even small amount of tests better than their absence ☀️

Thanks!

@JeremyThiesen
Copy link

I was able to work around this problem by going to line 897 in VideoClip.py and in addition to checking "isinstance(img,str)" I added in "isinstance(img,str) or isinstance(img,unicode):" And then casting img as a string before sending to imread from imageio.

@keikoro keikoro added the bug Issues that report (apparent) bugs. label Feb 18, 2017
@ghost
Copy link

ghost commented Feb 22, 2017

this should be fixed with pull request #438 is merged into the repo.

@ghost
Copy link

ghost commented Mar 13, 2017

@prokaktus .. please reopen if this issue continues..

@ghost ghost closed this as completed Mar 13, 2017
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs.
Projects
None yet
Development

No branches or pull requests

3 participants