How to get screenshot as fast as possible?

How to get screenshot as fast as possible?
0.0 0


Hello! Please help me.
I want to make screenshot every frame to make a video (gif, mp4) animation when player will lose but the most fast way to do the screenshot is 30 ms! It’s very very slow for my objective!

RenderTexture is not working for me because I’m using Sprite3D objects and many cameras so RenderTexture is not working.

Maybe frame buffer can help me some how?

Thank you.


Inspired from Steppy Pants?:slight_smile: We also want to implement something similar what would be best solution for GIF creation?


Yes, you are right. How do they do that? I have no idea. By the way my research results is to create MP4 instead of GIF coz it’s really faster.


They creating video and then converting it to gif I think. Need to find way how to buffer only lat 5 seconds.


We don’t know when a seconds will be a last so need to capture all the time. Do you have any solution to grab a screen as faster as possible? Thanks.


I mean you just buffering last 5 seconds of what happening on screen and deleting older buffer.


Right. Which method are you planning to use for getting the screen data?


I have noticed that using frame buffer is the faster way to get something like image (Texture2D). But how can I save it?


You’ll have to look into high-performance screenshot / screen to video solutions that exist out there. I would suggest looking into the platform-specific record game APIs. Next you could look at an sdk/plugin like Kamcord - Finally you can read up on the couple blogs of similar companies like Kamcord on their implementations.

If you want to handle this yourself you can do async screenshots, so you could just have the callback save out the image to a file. Then post-process the images into a gif/video. Beyond that you’ll have to use the not common OpenGL APIs around pixel buffers and stuff.


Wow) awesome! Have u used some sdk or your own code to make it work?


I used FrameBuffer, RenderTexture and ImageIO.


As stevetranby told, are you using some asynch approach so that game performance is not declined for the cost of capturing real time in-game video?

Great work. May be you would like to make your own library and add this feature to cocos2d-x for next versions. :+1:


Hi. RenderTexture with small resolution did the trick! In the main thread! But I did not save results to the file otherwise I store it in the memory and create gif from memory so it works fast.

If you guys @catch_up @energyy wants I can share my solution. Because I don’t think that this is should be a part of Framework coz it’s very specific feature.


Hi @igormats , I appreciate if you can share your code snippets for this here or in private message. Thanks


Yeah, would surely love to learn that. Thank you.

Also, I feel that this can be a part of framework, as just like single screen shot capturing, some people might love having this. Who knows this might shape the future of cocos2d-x and more people might start using it… This feature looks gimmick but it’s not just that much. :smile:


What (free) libraries do you recommend to use in c++ cocos2d-x project to save gif and mp4 videos?