How to get screenshot as fast as possible?


#1

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.


#2

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


#3

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.


#4

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


#5

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.


#6

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


#7

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


#8

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


#9

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 - https://www.kamcord.com/. 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.


#12

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


#13

I used FrameBuffer, RenderTexture and ImageIO.


#14

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:


#15

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.


#16

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


#17

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:


#18

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