How to access the VM preview picture when VM is in saved state?

This is for discussing general topics about how to use VirtualBox.
Post Reply
-JK-
Posts: 14
Joined: 3. Dec 2017, 02:23
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Mostly Ubuntu

How to access the VM preview picture when VM is in saved state?

Post by -JK- »

Is it possible to access the VM preview picture from command line when the VM is in saved state? Host OS is linux.
Is it somehow possible to export the preview into a .png or .jpg file?
Where is this preview data stored?
Thank you for your help!
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to access the VM preview picture when VM is in saved state?

Post by mpack »

No, the preview thumbnail is requested from the GAs inside a live running VM (see VBoxManage controlvm <vm> screenshotpng). It has nothing to do with the saved state.
-JK-
Posts: 14
Joined: 3. Dec 2017, 02:23
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Mostly Ubuntu

Re: How to access the VM preview picture when VM is in saved state?

Post by -JK- »

In the attached picture there is a VM called VBU16-YB01 which is in saved state. Preview of the VM screen just before save is shown on the right. That same preview is shown to user, when he/she starts the VM again.
My question was how can I get this same preview out of the VirtualBox preferably in png or jgp format after I have put the VM in saved state? The screenshot is stored somewhere, because VirtualBox GUI can show it.
Using information in your answer I can build a script that
1) takes the screenshot to a png-file
2) run the savestate
so that is one very possible way to solve my problem.

On the other hand if VirtualBox anyway stores this Preview somewhere, I would prefer a using that screenshot. That solution works also in case when the user initiates the savestate from GUI, not by running my script.
Attachments
VM-Preview.png
VM-Preview.png (87.75 KiB) Viewed 4013 times
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to access the VM preview picture when VM is in saved state?

Post by scottgus1 »

I don't find any binary/hex data inside the saved-state VM's .vbox file 8r the main Virtualbox.xml file, nor any jpg/png's in any Virtualbox folders. I would suspect the picture is stored within the saved state's .sav file. Wash it through a hex editor, see what you get.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: How to access the VM preview picture when VM is in saved state?

Post by fth0 »

The single screenshot of a VM in the saved state is indeed part of the .sav file, but I don't know any ready-made command to access it. Depending on your programming skills, there may be two possible alternatives:

1. You could take a look at the VirtualBox source code (e.g. VirtualBox-6.1.30.tar.bz2). A suitable starting point would be the readSavedDisplayScreenshot() (*) function in src/VBox/Main/src-all/DisplayUtils.cpp. Note that the VirtualBox source code is huge, so don't try to understand it all at once. ;)

2. You could take a look at the VirtualBox SDK Programming Guide, especially the readSavedScreenshotToArray() function. This guide isn't small either (~450 pages), but you'd probably only have to read ~30 of them. ;)

While the first alternative could be used to see how it's done in VirtualBox and reprogram something similar, the second alternative would be suited to write a Python script that uses the VirtualBox API. A third alternative would be not to use this single screenshot, since it's much easier to take screenshots from a running VM.

(*) Additional hint: In the readSavedDisplayScreenshot() function, you'd discover that the tag of interest in the .sav file is named "DisplayScreenshot".
-JK-
Posts: 14
Joined: 3. Dec 2017, 02:23
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Mostly Ubuntu

Re: How to access the VM preview picture when VM is in saved state?

Post by -JK- »

fth0 wrote: 2. You could take a look at the VirtualBox SDK Programming Guide, especially the readSavedScreenshotToArray() function. This guide isn't small either (~450 pages), but you'd probably only have to read ~30 of them. ;)
Thanks for these pointers. I will check the SDK and especially the vboxwebsrv.
Post Reply