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

Incorrect size being sent to ffmpeg #102

Closed
jdelman opened this issue Dec 11, 2014 · 2 comments
Closed

Incorrect size being sent to ffmpeg #102

jdelman opened this issue Dec 11, 2014 · 2 comments

Comments

@jdelman
Copy link
Contributor

jdelman commented Dec 11, 2014

Trying to save a short clip of a resized video. I explicitly resize the video clip here:

height = 400 
width = 532
clip = master_video.resize(width=width, height=height).subclip(start, end)

But ffmpeg was throwing an error that the width was not divisible by 2. Getting ffmpeg_video_writer to print out the ffmpeg command confirmed that an incorrect command is being sent to ffmpeg:

[MoviePy] Writing video /volumes/sigma/151.mp4
attempting to write video with the following command:
ffmpeg -y -loglevel error -f rawvideo -vcodec rawvideo -s 533x400 -pix_fmt rgb24 -r 59.94 -i - -an -i 151TEMP_MPY_wvf_snd.m4a -acodec copy -vcodec libx264 -preset medium -pix_fmt yuv420p /volumes/sigma/151.mp4

If I explicitly set the size, why is it being sent wrong to ffmpeg?

@Zulko
Copy link
Owner

Zulko commented Dec 11, 2014

What you want to write is:

clip = master_video.resize(newsize=(532, 400))

Or even simpler:

clip = master_video.resize((532, 400))

As explained in the docstring (but maybe I need to clarify or throw an error), height and width should not be used together, but alone, to preserve automatically the aspect ratio:

clip.resize(width=532) # the height will be automatically computed
clip.resize(height=400) # width will be automatically computed 

Note that this sometimes makes clips with uneven sizes, which some formats (like yours) don't like. In this case you can use the effect even_size which will automatically remove the last line or column of pixel to make the dimensions even:

# import moviepy.editor as mpy ...
clip = master_video.resize(height=400).fx( mpy.vfx.even_size)

@jdelman
Copy link
Contributor Author

jdelman commented Dec 11, 2014

Thanks! That did the trick.

@jdelman jdelman closed this as completed Dec 11, 2014
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

2 participants