-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Feature for saving gif files #5118
Comments
The p5.createloop library by @mrchantey currently provides straightforward GIF loop export functionality for p5.js. I have used it very successfully with my students (Art first-year undergrads with no prior programming experience); the only "advanced skill" needed is knowing how to add the include to the HTML. It would be worth evaluating whether it should be incorporated wholesale, or, remain an external library and simply advertised better, for example on the https://p5js.org/libraries/ page.
|
Thanks @golanlevin ! Yes I saw createLoop in exploring and it seems really cool. I think there is still a bit of curtain pulling back here that could ideally be avoided for something this core to the use of p5. Depending on the education context revealing a secondary file with a markup language, adding additional libraries, and passing object literals as parameters can all feel pretty intimidating. I have had students ask to download gifs on their first or second day of class. I believe that since we already have gif encoding functionality in the core library we should take advantage of this and have a simple |
Thanks @stalgiag, I completely understand. This especially makes sense for middle-schoolers. Uh, so let's think through some proposals then: (1) saveGif(filename, nFrames); This immediately starts recording the next nFrames frames, and when it's done, saves it out as a GIF. Puts the burden on the programmer of knowing whether they are actively writing to a GIF. Could cause problems if the programmer calls saveGif while another call to saveGif is actively running. (2) (3) (4) |
Thanks for this! Number 1 is what I was originally thinking. My thought was that the library could keep a flag true during recording and ignore additional calls (maybe use FES). I like that both parameters can be optional here with a default name and frame count. We could also enforce a maximum frame count to prevent memory problems. Anything over 500ish frames should likely be a screen recording. This has the benefit of being a single command that could be put in I like 2 and 3. The start and stop formatting feels natural. My primary concern would be holding programmers responsible for not overflowing the memory. I dig the flexibility and power of 4. Would it be overdoing it to combine 1 & 4? Webgl camera offers something like this with the ability to create a persistent camera with I'd love to hear thoughts from other people as well. I think this issue can stay open for a while as it warrants discussion. In the meantime, p5.createLoop is a great alternative and is heavily encouraged for people facing this challenge right now. |
I would also love to hear other voices in this.
FWIW, The following would be a Processing (Java) style way of doing things:
|
Great to see this discussion being had. In writing p5.createGIF, and then deprecating it in favour of p5.createLoop, I encountered a handful of discoveries:
|
Out of interest the library was created after following some of @shiffman's more loopy tutorials on coding train :) For anybody interested in an implementation, these are a great starting point for observing the workflow and where it can be improved. |
@mrchantey — thanks for making such a great, easy-to-use library. I had very good results using p5.createLoop with my students, Art-school first-years. I totally get what you're saying about making looping GIFs being the goal for many people. The variables you exposed for this (0..1, 0....2pi) are super useful. Your looping noise also elegantly obscures some really complex, difficult-to-explain stuff under the hood -- nicely done. I wasn't sure how to trigger p5.createLoop to start recording at any time other than in setup(). Admittedly I didn't work very hard to figure out an answer. But FWIW, this became a small issue for a student who wanted to record a GIF after the screen had already built up some imagery through user interaction. She ended up doing something else. I don't think it's crazy to want a screen-recording tool, that produces animated GIFs, whose recording the p5 programmer can .start() and .stop() when they choose. I agree that this is a different workflow. |
@golanlevin that is a very understandable use-case. Not crazy at all, and the implementation wouldnt be either. If you're interested, the encoding library works just like this. All that would be needed is to create a p5 wrapper for it. |
Thanks for the library @mrchantey ! I love the ability to create seamless loops. p5 has an encoding library omggif. It is similar to gif.js, just smaller. We actually already encode gifs for people that are saving image assets that are already animated as seen in |
Super excited to see this discussion! Would love to help in any way that I can. A totally different but related direction (a la the Processing "MovieMaker" tool) would be to build in a saveGIF button / export option into the web editor itself! This is probably a step 2 or longer term option (and has its downsides as well) but could be really wonderful for the short 2 hour intro to p5 weekend workshop context. |
Hi everyone! As a p5.js user and aspiring library contributor, I'm really excited to see this discussion. My experience as a userIn case adding another perspective helps, I'll describe my experience learning to create my first Twitter GIF using p5.js. I learned p5.js on my own (with the help of The Coding Train videos by @shiffman), and despite my previous programming experience, it took a lot of effort to make the GIF. Since my sketch involved a computationally expensive simulation, real-time rendering wasn't smooth, which ruled out a screen recording tool like Apowersoft Online Screen Recorder. The p5.js reference pointed me to ccapture.js. Eventually I found a video on YouTube that broke down how to use ccapture.js. Due to the randomness in the duration of my sketch, I had to include logic around the start and stop calls. For some reason, it didn't work. After that, I found p5.createLoop. Thank you @mrchantey for making this! I did manage to get it working, with a hack: I guessed an upper bound on the duration. The result is a looping GIF that either gets cut short or has a delay before restarting. (Here's the sketch in question. Please note that it is currently set to download the GIF automatically.) If you run the sketch, you will see a warning, but I believe that could be fixed by a recent update to p5.createLoop. My takeawayI was thrilled to make the GIFs, but the process felt complicated and unreliable. In addition to understanding how to include a library in a sketch, along with the other issues @stalgiag mentioned, there is always a problem of having to decide which library is best, and even potentially having to try out multiple libraries. For a feature as essential as GIF creation, eliminating any steps in this process would be incredibly helpful. A flexible, well-documented solution that's built directly into p5.js would make a big difference. A simple GIF solution is especially crucial since easy GIF creation will allow creative coders to make their creations visible on social media, and that will help build the p5.js community by spreading awareness! Including a "Save GIF" button in the web editor, as @shiffman proposed, would be amazing. Perhaps the button could cover the most common use case(s), and there could be a more flexible solution that can be implemented in the code. My thoughts on the more flexible optionsFor the more flexible option, I like Why I like
Why I prefer
A two-pronged solution?Ease of use is really important, but so is flexibility, so a two-pronged approach seems reasonable, similar to what @stalgiag proposed.
|
|
Hi @DivyamAhuja my sense is that this will not be enough work to constitute an entire GSoC project. This will be more of a matter of adding a few public functions that expose things that the library already does. The biggest challenge here is design but the work there will likely happen in the form of this ongoing community discussion. It is possible that this could be part of a larger GSoC project but I don't expect that the work for this particular feature (even if we do both The Movie Maker option could be the correct scope for GSoC but this would likely require further discussion to decide if the feature is appropriate. This is all to say that this could be a part of a GSoC proposal but shouldn't be the entirety of one unless the community comes together and decides strongly in favor of multi-export tool in the online editor. |
@stalgiag That's what I was thinking, but I don't think I got any idea of integrating this feature in any other project other than batch of bug fixes XD |
Hi there everyone! I got here through the project list that Processing has published for GSoC 2022. As far as I can see, the discussion states that this is indeed a wanted feature (presented as high priority), but that it may not fulfil a complete GSoC project, though it is published as a potential project. I am writing to ask what is the state of this discussion, since I see the last comment was exactly a year ago. I am a GSoC aspiring contributor and feel like I can tackle this topic, but wanted to know the team's opinion on it! Thanks a lot for your time beforehand! |
Hi @jesi-rgb thanks for this question! GSoC is structured a little bit differently this year. Applicants choose between two different project scopes when applying: 175 hours (medium) and 350 hours (large). I can imagine a 175 hour or medium-sized project that proposes implementing p5.GifWriter, adding all of the utility functions necessary to work with it, writing tests, and writing examples. This work could be supplemented with related bug fixes and optimizations. |
@stalgiag nice to hear! I would be very glad to implement this feature, since I myself am a particular user that's struggled with this particular topic. Publishing the beautiful animation you've just created to the web should be just as easy as a download button. May I ask who could be the potential mentor to contact and ask feedback to? Thanks much! 🙏🏻 |
I am not sure who is mentoring this year but when you are ready you can make a post on the Summer of Code category on the Discourse (where these discussions take place) and tag me. I would be happy to give feedback on your proposal. |
Hi everyone! I am so excited to see this discussion. As @GregStanton said, both ease of use and flexibility are important. For ease of use, I think a GUI like the recording button is a great option. Adding code for recording to a sketch is difficult for a beginner. Also, it would be nice not to have to add any code to the sketch, since the creative code and the code for recording should be separated. As for flexibility, there are many factors. And based on the above ideas, I have developed p5.capture, a library for easy recording of p5.js animations. The differences from p5.createloop are as follows
It is truly designed for beginners to easily record their work and share it quickly. In addition, an API is provided for flexibility. Does this help? |
Hello, everyone! I am very excited to tell you that I am now a GSoC contributor for the processing foundation! My project aims to solve the very problem stated here in this conversation, so hopefully we'll be able to create an easy and fast method to download gif files directly. Thanks a lot for your time and I am super excited to get to know you all! Have a great summer! |
Congrats @jesi-rgb! I look forward to seeing what you will create during GSoC. |
New feature details:
I am getting this request quite a lot from my students. They want to be able to share their work on social media in animated form. I know that
saveFrames
exists but students have to already be relatively advanced to use that and it doesn't encode to gif.Other options like using ccapture.js, require a number of advanced skills that students often don't have during their first experiences with coding.
Since GIF support was enabled we already have most of the work in place for this feature. saveGif already exists as a private method for saving animated p5.Image objects as GIFs. To enable this feature, we would have to add a separate public method (probably
saveGif
and the private one would be renamed) that stores frames over a certain number of frames and then turns them into an animated p5.Image object. This object could then be sent to the private method which could handle all of the encoding.How would this new feature help increase access to p5.js?
It would enable students to share their work in animated form without needing advanced skills.
Most appropriate sub-area of p5.js?
The text was updated successfully, but these errors were encountered: