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

Allow resizing frames in ffmpeg when reading #489

Merged
4 commits merged into from
Mar 15, 2017
Merged

Allow resizing frames in ffmpeg when reading #489

4 commits merged into from
Mar 15, 2017

Conversation

gyglim
Copy link
Contributor

@gyglim gyglim commented Mar 13, 2017

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

@coveralls
Copy link

coveralls commented Mar 13, 2017

Coverage Status

Coverage decreased (-0.08%) to 46.781% when pulling 124109a on gyglim:lowres into caf955c on Zulko:master.

@Zulko
Copy link
Owner

Zulko commented Mar 13, 2017

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.

@gyglim
Copy link
Contributor Author

gyglim commented Mar 13, 2017

I had a look at 1 minute of video at 1280x720 resized to 128x128 and got the following numbers

Linear interpolation:
Read resized with FFMEG linear:
1 loop, best of 3: 4.66 s per loop
Read resized with FFMEG fast_linear:
1 loop, best of 3: 3.83 s per loop
Read and resize with OpenCV:
1 loop, best of 3: 5.18 s per loop
Note: OpenCV does not provide fast_linear.

Area interpolation, which is used by moviepy, as I understand:
Read resized with FFMPEG:
1 loop, best of 3: 5.47 s per loop
Read and resize with cv2:
1 loop, best of 3: 10.4 s per loop
Read and resize with moviepy:
1 loop, best of 3: 11.2 s per loop

differences for cubic are smaller.
I suspect ffmpeg has more efficient resizing. And there is a little bit of cost of writing and reading the binary stream I would assume.

Also run the same comparison of OpenCV2 vs ffmpeg on a larger machine (32 cores) and got
Read resized with FFMEG linear:
1 loop, best of 3: 1.36 s per loop
Read and resize with OpenCV:
1 loop, best of 3: 5.8 s per loop

So it seems ffmpeg has better mutlithreading.
@Zulko What do you think?

@coveralls
Copy link

coveralls commented Mar 13, 2017

Coverage Status

Coverage decreased (-0.08%) to 46.781% when pulling 469a6e4 on gyglim:lowres into caf955c on Zulko:master.

@coveralls
Copy link

coveralls commented Mar 14, 2017

Coverage Status

Coverage increased (+0.2%) to 47.605% when pulling 57bd77a on gyglim:lowres into 0b40803 on Zulko:master.

@ghost
Copy link

ghost commented Mar 15, 2017

@Zulko Since you have contributed to this conversation, I want to give you a chance to approve/disapprove this PR.

@Zulko
Copy link
Owner

Zulko commented Mar 15, 2017

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).

@coveralls
Copy link

coveralls commented Mar 15, 2017

Coverage Status

Coverage increased (+1.2%) to 48.624% when pulling 097b4a6 on gyglim:lowres into 0b40803 on Zulko:master.

@gyglim
Copy link
Contributor Author

gyglim commented Mar 15, 2017

Awesome. Another advantage I see is that it is the same for everyone. The resizing in moviepy tries OpenCV, the PIL, then scipy:

# TRY USING OpenCV AS RESIZER

But everybody needs to have ffmpeg if they are using moviepy. Not necessarily OpenCV. Resizing with PIL is much slower

bilinear:
1 loop, best of 3: 12.1 s per loop
ANTIALIAS (as used in moviepy):
1 loop, best of 3: 21.7 s per loop

where ffmpeg bilinear was:
1 loop, best of 3: 5.47 s per loop

I know scipy is also slower from earlier tests.

@gyglim
Copy link
Contributor Author

gyglim commented Mar 15, 2017

give me a minute before merging anything

@Zulko
Copy link
Owner

Zulko commented Mar 15, 2017

@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).

@coveralls
Copy link

coveralls commented Mar 15, 2017

Coverage Status

Coverage increased (+1.2%) to 48.624% when pulling 3ff5169 on gyglim:lowres into 0b40803 on Zulko:master.

@gyglim
Copy link
Contributor Author

gyglim commented Mar 15, 2017

@Zulko Thank you.
re PEP8 and variable names: Will do.

fixed that you can do also up-scaling incl. test (was an artifact from our own version).
From my side it is all good now

@ghost ghost merged commit d633510 into Zulko:master Mar 15, 2017
This pull request was closed.
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

Successfully merging this pull request may close these issues.

None yet

3 participants