Capture Screenshot on Linux Headless Machine
I am trying to build a Unity application that can run on a cloud Linux server (Ubuntu 16.04) and that will be taking input from network application (my client) and generate shapes based on the client input (user interacts with client). Since the system on cloud I will not be having any Physical display attached to it. This machine has just integrated Intel GPU.
I am able to get the end to end flow working when I run the application with Physical display connected to the Ubuntu machine. however, when I try to run the application on batchmode or by attaching to a virtual frame buffer (Xvfb) display then the application just generates the first frame (I came to know this by adding log in the update method and also captured screenshot via RenderTexture from Camera).
But, I am unable to get the application running with Virtual Frame Buffer / BatchMode. The app runs fine with -nographics option but the images that screencapture gets are just gray (blank). So, that's not an ideal solution for my problem.
I tried to set the default frame rate rate for my application but that didn't help. I am not sure what causing the engine to stop right after the first update call. I did end up trying the following solutions. but, nothing helped .
https://answers.unity.com/questions/353653/can-a-unity-game-be-started-over-ssh.html https://towardsdatascience.com/how-to-run-unity-on-amazon-cloud-or-without-monitor-3c10ce022639
sudo Xvfb :10 -ac -screen 0 1024x768x24 &
DISPLAY=:10 ./MyGaem.x86_64 -> Not working. Just first update gets called.
DISPLAY=:10 ./MyGaem.x86_64 -batchmode -> Not working. Just first update gets called.
DISPLAY=:10 ./MyGaem.x86_64 -batchmode -nographics -> Gray images.
Note, I am using Integrated Intel GPU
I can provide the Player.log for both working & non-working cases if someone can help.
Answer by RohitNutalapati · Oct 19, 2018 at 05:49 PM
Try modifying the prefs file. It's in the same location as your Player.log file. Set full screen to 0 and monitor value appropriately.. the application should run in window mode and capture a screenshot. I tested on AWS running ubuntu 16.04..
<unity_prefs version_major="1" version_minor="1">
<pref name="Screenmanager Is Fullscreen mode" type="int">0</pref>
<pref name="Screenmanager Resolution Height" type="int">1024</pref>
<pref name="Screenmanager Resolution Width" type="int">1280</pref>
<pref name="UnitySelectMonitor" type="int">0</pref>
...
</unity_prefs>
Also try disabling the resolution prompt in player settings!
Your answer
Follow this Question
Related Questions
how simply writing text on texture 0 Answers
Count colored pixels of RenderTexture and get this data on CPU. 0 Answers
Render Texture from Cameras targetTexture produces seams. 1 Answer
Is it possible to render only specific texture (albedo for instance) 0 Answers
Read Pixels to Texture2D in EditorWindow make unity crash 2 Answers