Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

moviepy resize not working in some sizes

Tags:

python

moviepy

I have a mp4 video of 720x1280, and I want it in different sizes like: 0.66%, 0.5% and 0.33%.

For each of these sizes I use:

clip = mp.VideoFileClip(file)
clip_resized1 = clip.resize(height=int(clip.h * float(0.66666))) 
clip_resized1.write_videofile(name + '-2x' + ext)

I do this for each of the sizes but some of them work and some not. The 0.66 not works, just like the 0.33. The 0.5% works just fine.

It creates the files for every size, but they are corrupt, and can't open them (except 0.5 as I said, which works ok).

Any clue on this? Any better solution for resizing in Python?

like image 580
facumedica Avatar asked Sep 11 '15 17:09

facumedica


1 Answers

The issue I believe is that most video player cannot play mp4 if one of the dimensions of the clip is an odd number. For instance 720x1280 works on all players but 721x1280 will only play on some video players like VLC.

So make sure that clip.h and clip.w are both even before writing to a video file. There are several ways you can do that, either indicate the new dimensions of the clip yourself, like clip.resize((844, 476)), or redimension the clip of 66% and add a 1px black margin at the top, like clip.resize(0.66).margin(top=1)

like image 104
Zulko Avatar answered Oct 17 '22 07:10

Zulko