scrcpy icon indicating copy to clipboard operation
scrcpy copied to clipboard

Added Save Screenshot

Open Spudmn opened this issue 4 years ago • 8 comments

Pressing the MOD + Q key will save a screenshot the next time the screen is rendered.

It saves a PNG file with a date time stamp filename.

It uses lodepng to encode the file. Thanks Lode Vandevenne (https://github.com/lvandeve/lodepng)

The save_screenshot function has been modified from user1902824 (https://stackoverflow.com/questions/34255820/save-sdl-texture-to-file)

Limitations.

If 2 screenshots are taken within the same second, the file name will be the same and the first file will be overwritten

Does not handle client side screen rotation.

Spudmn avatar Jan 16 '21 07:01 Spudmn

Thank you for working on this. This is a feature often requested (#684), and it is not trivial.

will save a screenshot the next time the screen is rendered.

Why not the current frame immediately? (if the screen content does not change, the next frame could be sent seconds or minutes later in theory)

I have several general remarks.

This PR adds a dependency (lodepng). Scrcpy already depends on FFmpeg, which can encode images, so I'd prefer to use FFmpeg. This is far less straightforward, but this avoids a separate image encoder (I have pending work for decoding images too). Btw, since the input picture is already compressed (it comes from a H.264 stream), it would be better to save it to JPG than PNG (lossless is unnecessary on a lossy input).

Also, encoding a picture takes time: it should not be done on the UI thread, but on a separate thread.

I think that it would be more straightforward to encode the content of the decoded frame (the rendering frame in struct video_buffer, which would need to be refcounted), rather than to retrieve the SDL texture content (moreover, it's in YUV, which is the native JPEG format). Even semantically, in theory we could want to capture a screenshot even if we don't display the frame on screen.

Regards

rom1v avatar Jan 16 '21 20:01 rom1v

Also came here to add that instant screenshot would be amazing to add. It's probably the only feature missing from this amazing program at the moment.

JASHIKO avatar Feb 15 '21 10:02 JASHIKO

If I press a key mod + Q, it doesn't take a screenshot. What could be the reason? My version: scrcpy v1.17 on Jan 2.

ghost avatar Apr 27 '21 16:04 ghost

If I press a key mod + Q, it doesn't take a screenshot. What could be the reason? My version: scrcpy v1.17 on Jan 2.

This PR has not been merged. You can build scrcpy based on this PR manually to include this feature.

npes87184 avatar Apr 28 '21 01:04 npes87184

Can you help me with how I can do it? I'd be grateful for.

ghost avatar May 17 '21 12:05 ghost

Can you help me with how I can do it? I'd be grateful for.

You will need to build scrcpy from my PR.
If you like you can build it from my fork here https://github.com/Spudmn/scrcpy/tree/Added_Save_Screenshot Please note that I do not have time to maintain this fork. It worked for what I needed, maybe it will work for you.

Spudmn avatar May 17 '21 22:05 Spudmn

This could be a convenient solution so don't have to go through different commands for screenshots.

mamatagelanee07 avatar Feb 01 '22 16:02 mamatagelanee07

If I press a key mod + Q, it doesn't take a screenshot. What could be the reason? My version: scrcpy v1.17 on Jan 2.

This PR has not been merged. You can build scrcpy based on this PR manually to include this feature.

How we can build with this PR?

YerongLi avatar Jun 13 '24 06:06 YerongLi