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

Resize gives wrong shaped output #2049

Open
EsbernTK opened this issue Oct 9, 2023 · 1 comment · May be fixed by #2093
Open

Resize gives wrong shaped output #2049

EsbernTK opened this issue Oct 9, 2023 · 1 comment · May be fixed by #2093
Labels
bug Issues that report (apparent) bugs. video Related to VideoClip and related classes, or handling of video in general.

Comments

@EsbernTK
Copy link

EsbernTK commented Oct 9, 2023

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

  • Python Version: 3.9
  • MoviePy Version: 1.0.3
  • Platform Name: Windows 10
  • Platform Version: 22H3
@EsbernTK EsbernTK added the bug Issues that report (apparent) bugs. label Oct 9, 2023
@Dotrar Dotrar linked a pull request Jan 12, 2024 that will close this issue
2 tasks
@Dotrar
Copy link

Dotrar commented Jan 12, 2024

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.

@keikoro keikoro added the video Related to VideoClip and related classes, or handling of video in general. label Feb 10, 2024
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. video Related to VideoClip and related classes, or handling of video in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants