0

Depending on what is shown on the monitor, the screenshot of Python MSS can go up to 2 MB even though I have the compression set to the maximum which is 9. Is there another way to reduce the filesize or to save it instead as a jpg which would be even more compressed? Quality doesn't much matter and I'd rather not have to use PIL.

from mss import mss

with mss() as sct:
    sct.compression_level = 9
    sct.shot(mon=-1, output="C:\test\test.png")
Tiger-222
  • 6,677
  • 3
  • 47
  • 60
Zurd
  • 686
  • 7
  • 16

1 Answers1

1

As of now MSS includes only a basic PNG compressor. Even if we implemented more complex filters in the PNG format, it may be still heavy.

The screenshot size depends heavily on the screen size.

An idea would be to include a JPG compressor, in pure Python, but I do not have the time for that, so pull requests are always welcome. What module can you use? Because you can play with pixels and pass them to another module perhaps?

Tiger-222
  • 6,677
  • 3
  • 47
  • 60
  • Thank you for the information. We get 180-200 KB on a 1920x1080 or 2560x1080 screen which is quite good but we get 1.8 MB to 2.0 MB in a RDP session, I wonder why there's such a huge difference. I'm using as less module as possible to make the software as small as possible in the end. I'm using pyinstaller to create an executable file and adding PIL double the size and the number of files. I don't know of any other modules we can use. – Zurd Aug 08 '18 at 15:34
  • How do you use MSS via RDP? Could you post a screenshot to have an idea of the result? – Tiger-222 Aug 08 '18 at 16:07
  • I compile the python code with MSS with pyinstaller. Copy the executable file over RDP and then open the file. You can probably just run MSS code to get a screenshot over RDP to test it but you need to RDP computer to have python. – Zurd Aug 08 '18 at 23:40
  • OK, I will give a try and let you know :) – Tiger-222 Aug 09 '18 at 08:52
  • I cannot reproduce. Using via RDP or not, the screenshot size is about 1.20Mo (because I have full screen 2560*1335 in high quality and a detailled background image). So I do not see anything weird from my side. – Tiger-222 Aug 09 '18 at 18:25
  • I think you're right, RDP doesn't change anything. I just wish there was a way to make the filesize smaller. I can reproduce a 10 MB screenshot with 2 monitors and 2 desktop background. – Zurd Aug 09 '18 at 23:31
  • Yeah, depending on the background and monitors sizes, it can grow rapidly. If you want to try something, you could check to add a JPG compressor to MSS :) Else you should remove the background when you are using via RDP. It will greatly help reducing the size. – Tiger-222 Aug 10 '18 at 07:56