ActiveStorage is a great addition to the framework but it only allows image variants and not e.g audio or video variants.
FFmpeg offers many filters to transform audio, video and text tracks and is already used in ActiveStorage for video preview/analysis, so why not build from there?
Our app would very much benefit from such a feature. At least having a mechanism to register custom variant transformers for specific content types would be welcome.
Here is a demo which works on my machine (some details are left out):
I think theyâd at least be interested in a PR to support custom variant transformers. I would open an issue on the Rails repo, describe the problem space and your current best stab at an API design, and ask for feedback on that design. When you do so, please remember to mention that youâre interested in writing a PR for it thatâs upstreamed from your application.
Thank you @Betsy_Haibel, I have submitted a PR to enable variants for custom media types in ActiveStorage. For anyone reading this, it would be lovely to have feedback. CC @georgeclaghorn. Thanks!
I know that itâs easier for the Rails maintainers to review small PRs, so thank you for keeping this one relatively focused â I had a moment of âoh noâ when I saw 200 lines added, but then I realized it a lot of it was documentation.
Let me know if youâd like help breaking the PR up even further, though.
@Betsy_Haibel thatâd be great , here are some questions:
can we already remove MiniMagickTransformer from the codebase (in a separate PR), as it has a deprecation warning saying it should disappear in Rails 6.1? That would simplify the PR for sure.
Iâve renamed config.active_storage.variable_content_types to *.variable_image_content_types to make clear they only apply to the ImageProcessingTransformer (this is a breaking change). I could revert that change to avoid the breaking change and make PR smaller.
I had to modify ActiveStorage::Variation to receive blob which is required by accept?. Any suggestions for alternative approaches?
I could reduce the amount of comments in the code (some of which are redundant) and keep the explanations only in the ActiveStorage guide
That sounds like a great start â that piece sounds like it has well-defined edges and is easy to slice off.
I would definitely revert that change here (and possibly open a separate PR for it after this PR is accepted.) Breaking changes are going to be a lot scarier for the maintainers than adding new features.
Not off the top of my head, but Iâll think more about it.
I definitely wouldnât remove the comments! More documentation is great. Signalling to the maintainers in the PR description that this is mostly comments might be helpful though.
@Betsy_Haibel thanks for the suggestions, Iâve implemented them and updated the PR.
I am quite excited about this as it would open many possibilities to transform on the fly any ActiveStorage file in many creative ways, using Ruby or system commands.
My hope is that this could land in Rails 6.1, do you think itâs possible?
I donât know! I donât have a commit bit, and Iâm not deeply embedded in the code, so I canât speak to technical details â I can only go off of what the maintainers are telling me about making PRs smaller and breaking-change migration paths clearer.