Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.09k stars 1.51k forks source link

Resize gives wrong shaped output #2049

Open EsbernTK opened 8 months ago

EsbernTK commented 8 months ago

Expected Behavior

I have a video file with frame size width: 4480 height: 3096, and i am doing a resize of (224, None) The expected resized frame would be (224, 324)

Actual Behavior

The actual frame i get back is (223, 324), and it is caused by the integer conversion on this line The ratio calculation resolves to 0.07235142118863049 which when multiplied with 3096 gives 223.99999999999997 and is thus rounded down to 223 by the integer conversion. It would be lovely if the shape calculation forced the given axis to be the same as the requested shape, instead of recalculating it using the ratio calculation which is prone to error.

Steps to Reproduce the Problem

from moviepy import *
path = "test.mp4" #test.mp4 is a video with shape (3096, 4480, 3)
video = VideoFileClip(path, target_resolution=(224, None))
frame = video.get_frame(0)
frame.shape #frame.shape = (223, 324, 3)

Specifications

Dotrar commented 5 months ago

I added a little change to fix but it raises a few questions on how should we cater to this case.

Should we:

  1. leave as is - because if you want a specific resolution, you should specify it completely.
  2. use the target dimension as specified, calculate the other. and/or
  3. use proper rounding functions? perhaps use ceil or at the very least round even?

One could argue that if a result comes to " 12.2 pixels" (or in the example case 223.9999) then it should be ceil'd so that we have a pixel to cover that extra little bit that should be there.

But on the whole, I would expect that if i said "I want target height to be 100" it should come out as 100.