Skip to content

FEAT: New Plugin for pyAV - #745

Merged
FirefoxMetzger merged 65 commits into
imageio:masterfrom
FirefoxMetzger:feat-pyav-plugin
Apr 13, 2022
Merged

FirefoxMetzger merged 65 commits into
imageio:masterfrom
FirefoxMetzger:feat-pyav-plugin

Conversation

@FirefoxMetzger

@FirefoxMetzger FirefoxMetzger commented Jan 31, 2022 •

Copy link
Copy Markdown
Contributor

Closes: #610, #220, #686

This PR adds a pyAV plugin to ImageIO using the v3 API. This is in parallel to our imageio-ffmpeg plugin, because (a) it doesn't have feature parity and (b) I still need to work out how well maintained pyAV is. One of the reasons why we still want to have a pyAV plugin is because pyAV is more performant and - depending on the task - I get a 3x -10x speedup by switching to this plugin.

Other features:

  • sophisticated way of checking if ffmpeg can handle the ImageResource that is based on ffmpeg's logic instead of us manually checking extensions
  • ImageProperties (shape+dtype) without reading pixel data 🎉
  • supports reading and writing of videos
  • adjustable thread count when reading/decoding
  • optimised threading model for bulk-reading (index=None)
  • custom conversion between av.VideoFrame and np.ndarray to support formats that pyAV doesn't support yet (I think I will try to get this merged upstream at some point)
  • support for filters and graphs (arbitrary ones when iterating, zero-delay ones writing writing or reading single frames)
  • typing support

Planned features for upcoming PRs:

  • support for streams (needs rework of core.Requests to accept relevant schemes)
  • Fast-path based on file extension. [This will happen in a separate PR because it is quite substantial (more than 150 supported formats) and I want to keep this PR focussed on code].
  • support for libavdevice (again to keep this PR on core functionality)

@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

@hmaarrfk I saw your name pop up while reading through the pyAV issues. Do you have any interest in a plugin like this?

@hmaarrfk

Copy link
Copy Markdown
Contributor

(between .3x - 10x times faster in my naive timings).

Did you forget a 1 somewhere?

@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

(between .3x - 10x times faster in my naive timings).

Did you forget a 1 somewhere?

True. it's 1.3x - 10x as fast. 1.3x (30% faster) for bulk reading of an entire video (where decoding dominates runtime), about 5x faster for first frame access (where setup cost dominates), and 10x faster for a random frame (where seeking dominates). Although the seeking depends heavily on the contents of the file and how keyframes are distributed, so that number should be taken with some salt.

@hmaarrfk

Copy link
Copy Markdown
Contributor

For what its worth, I've been trying to get the hardware decoders in reasonable versions of ffmpeg to work.

I think I got the intel ones in conda-forge.

I tried to get nvidia ones in, but I think there are some intriciacies with dependencies and driver versions.

So i am generally interested in speedups :D but not sure how to help at this point. I might be able to give a review if that is what you want?

@hmaarrfk

hmaarrfk commented Feb 1, 2022

Copy link
Copy Markdown
Contributor

Is there a way to hide codecov from the PR? it is really annoyign to read it.

@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

but not sure how to help at this point. I might be able to give a review if that is what you want?

Sure that would help :) Though, I wouldn't want to take up too much of your time at this stage. Maybe I can ping you once the PR is RTR (so that, among other things, the codecov messages are gone ;) ).

I primarily pinged you for awareness, because I thought you could be interested in a feature like this.

I haven't yet figured out a good way to disseminate news around ImageIO nor a good way to estimate interest in new/upcoming features, so this is also partly me figuring out a good way to go about this. Ideas are welcome :D

I tried to get nvidia ones in, but I think there are some intriciacies with dependencies and driver versions.

Interesting. I've always thought of hardware acceleration (especially via GPU) as something that encoding benefits from, but decoding not so much. Primarily, because sending data back and forth isn't exactly cheap. Do you know of a benchmark for this? (I did some searching yesterday, but didn't find any comparisons beyond people guesstimating)

On that note, you are probably aware of this note in pyAV that hardware acceleration won't be supported. Not sure how much we can do from here without adding new features to pyAV (e.g., to expose the required config).

@hmaarrfk

hmaarrfk commented Feb 5, 2022

Copy link
Copy Markdown
Contributor

-hwaccel is one thing, but there are different encoders that can help speed things up.

Thanks for looking into this!

@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

-hwaccel is one thing, but there are different encoders that can help speed things up.

@hmaarrfk Ah, so you are mainly interested in encoding/writing of video?

@hmaarrfk

hmaarrfk commented Feb 5, 2022

Copy link
Copy Markdown
Contributor

Decoding too! It is very useful when dealing with large stacks of images!

@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

I am done with the bulk of the work for this. I still need to write some narrative docs and fix pypy (though I think it breaks because of the new astropy and not because of pyav), but the code is there and it is covered by tests.

@hmaarrfk Would you have the time in the coming days to review the code section of this PR (the file pyav.py)?

@FirefoxMetzger
FirefoxMetzger marked this pull request as ready for review March 5, 2022 17:11

@hmaarrfk hmaarrfk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments for now.

Comment thread tests/test_pyav.py Resolved
Comment thread tests/test_pyav.py Resolved
Comment thread tests/test_pyav.py Resolved
Comment thread imageio/plugins/pyav.py Resolved
Comment thread imageio/plugins/pyav.py Resolved
Comment thread tests/test_pyav.py Resolved

@almarklein almarklein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread imageio/plugins/pyav.py Resolved
Comment thread imageio/plugins/pyav.py Resolved
Comment thread imageio/plugins/pyav.py Resolved
Comment thread imageio/plugins/pyav.py Resolved
Comment thread imageio/plugins/pyav.py Resolved
Comment thread imageio/plugins/pyav.py Resolved
@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

Nice! I just sorted out the pending suggestions from your reviews @almarklein , @hmaarrfk (thanks for taking the time!). I also sorted out the astropy failures on pypy [by no longer installing astropy, because I can't work out where/why it fails and I also can't reproduce the failure locally].

What's left?

@FirefoxMetzger FirefoxMetzger mentioned this pull request Apr 4, 2022
@daveisfera

Copy link
Copy Markdown

Anything I can do to help test this or otherwise help get it out the door?

@FirefoxMetzger

FirefoxMetzger commented Apr 5, 2022 •

Copy link
Copy Markdown
Contributor Author

@daveisfera I can"t think of anything specific from the top of my head. The main thing that is missing is approval from @almarklein and - perhaps - some documentation, which I will look into after I finished #769).

If you want, you could help proofreading the docs and see if they are intelligible and user friendly, or - depending on your level of expertise, time, and interest - you can also review the PR itself and see if there is anything that you think should be added or changed.

@almarklein

Copy link
Copy Markdown
Member

LGTM, but CI does not approve yet?

@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

One of the things it will trip over is the changes in pillow 9.1 which break our CI. We've merged the PR that fixes this already, but I still have to rebase this PR on them. Will do soon(TM).

@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

The time has finally come. Once CI is happy, I will merge the pyav plugin, Thanks @almarklein @hmaarrfk @daveisfera for your feedback and discussion.

@FirefoxMetzger
FirefoxMetzger merged commit 22ab97e into imageio:master Apr 13, 2022
@FirefoxMetzger
FirefoxMetzger deleted the feat-pyav-plugin branch April 13, 2022 05:33
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.

Reading tags? make ffmpeg's can_read more sophisticated Wrap python av Animated gif writer via ffmpeg

4 participants