-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Allow resizing frames in ffmpeg when reading #489
Conversation
Interesting. Ideally, I would be for using ffmpeg just for decoding the video, and then do all the logics inside moviepy. Can you give numbers on how much you time your PR saves ? How do you explain the speed difference between resizing on ffmpeg side versus on moviepy's side ? It's C routines on both sides. |
I had a look at 1 minute of video at 1280x720 resized to 128x128 and got the following numbers Linear interpolation: Area interpolation, which is used by moviepy, as I understand: differences for cubic are smaller. Also run the same comparison of OpenCV2 vs ffmpeg on a larger machine (32 cores) and got So it seems ffmpeg has better mutlithreading. |
@Zulko Since you have contributed to this conversation, I want to give you a chance to approve/disapprove this PR. |
I'd say approve. I am a bit against creating another way of resizing and against using ffmpeg for more than read/write, but in this case it seems that there is much to gain (and I cant think of a simple way to get the same performance). |
Awesome. Another advantage I see is that it is the same for everyone. The resizing in moviepy tries OpenCV, the PIL, then scipy: moviepy/moviepy/video/fx/resize.py Line 4 in 32b7007
But everybody needs to have ffmpeg if they are using moviepy. Not necessarily OpenCV. Resizing with PIL is much slower bilinear: where ffmpeg bilinear was: I know scipy is also slower from earlier tests. |
give me a minute before merging anything |
@gyglim I know, I use Pillow by default in moviepy because it's lightweight and easy to install everywhere. It's not difficult to create a custom filter using opencv's resize. Thanks for the PR, it's a solid one. For future contributions, please make sure to use PEP8 (all lines <80 chars) and consistent names (resize_algo vs resize algorithms). |
@Zulko Thank you. fixed that you can do also up-scaling incl. test (was an artifact from our own version). |
This PR is adds the possibility to read videos frames that have been resized in ffmpeg.
This is much faster than streaming in high-res and then resizing in python and important for applications where speed is crucial