Screen Shot from Python not working.

15 views
Skip to first unread message

Leslie Rhorer

unread,
Sep 10, 2025, 5:20:42 AM (11 days ago) Sep 10
to Stellarium
I want to have a python script cause Stellarium to focus on an object, take a screenshot, and exit.  Stellarium loads, but does not create a screenshot or exit.  It also This script was created by Grok AI

#!/usr/bin/python3
import os
import subprocess
import time

# Set the path to Stellarium and FFmpeg
stellarium_path = "/usr/bin/stellarium" # Adjust as necessary
ffmpeg_path = "/usr/bin/ffmpeg" # Adjust as necessary

# Create a directory to store images
output_dir = "/RAID/Server-Main/FlatEarth/Stellarium Screen Shots/Video"
os.makedirs(output_dir, exist_ok=True)

def capture_images(object_name, field_of_view, start_latitude, end_latitude, longitude, time_of_day):
# Loop through the specified latitude range
for latitude in range(start_latitude, end_latitude + 1):
# Prepare the Stellarium command
command = f'"{stellarium_path}" --full-screen=no --script=screenshot_script.py --longitude={longitude} --latitude={latitude} --time={time_of_day} --fov={field_of_view} --object="{object_name}" --screen-capture="{output_dir}/image_lat{latitude}.png"'
print(f"command: {command}")

# Execute the Stellarium command
print(f"Capturing image at Latitude: {latitude}")
subprocess.run(command, shell=True)

# Wait for a moment to ensure Stellarium has time to process
time.sleep(20)

def create_video(output_dir):
# Create a video from the captured images
video_output = "output_video.mp4"

ffmpeg_command = f'"{ffmpeg_path}" -framerate 1 -i "{output_dir}/image_lat*.png" -c:v libx264 -pix_fmt yuv420p "{video_output}"'

print("Creating video...")
print(f"ffmpeg command: {ffmpeg_command}")

subprocess.run(ffmpeg_command, shell=True)
print(f"Video created: {video_output}")

if __name__ == "__main__":
# User-defined parameters
object_name = "Moon" # Example: Name of the celestial object
field_of_view = 3 # Field of view in degrees
start_latitude = 0 # Starting latitude
end_latitude = 90 # Ending latitude
longitude = 100 # Longitude
time_of_day = "2025-10-01T12:00:00" # Time in ISO format

capture_images(object_name, field_of_view, start_latitude, end_latitude, longitude, time_of_day)
create_video(output_dir)


I also tried creating a script named screenshot_script.py
# Hide the GUI
core.setFlagHideGui(true)
# Take a screenshot
core.screenshot("screenshot.png")
# Exit Stellarium
core.quit()

Georg Zotti

unread,
Sep 10, 2025, 5:31:21 AM (11 days ago) Sep 10
to Stellarium
interesting way to delegate debugging of an AI generated program to a non-AI forum. 
Have you run the command manually from the command line? And the script from within Stellarium? screenshot_script.py is at least misleading as Stellarium does not process python scripts. As always, the logfile may contain hints of what's wrong. 

Leslie Rhorer

unread,
Sep 10, 2025, 7:17:48 AM (11 days ago) Sep 10
to Stellarium
Yes, I have run it from the command line as a separate process.  The behavior is the same.It comes up, but does not take a screen shot or exit.

The suggested Stellarium script did not look like a Python script to me, either, but what the heck do I know?  I used Duck AI's search assist and that is what it said.

Georg Zotti

unread,
Sep 10, 2025, 9:14:45 AM (10 days ago) Sep 10
to Stellarium
If you load the script in the script console, you see working and non-working syntax.
Homework:
Find out how StelMainAPI's functions are called to hide GUI and quit the program.

Leslie Rhorer

unread,
Sep 10, 2025, 11:57:53 PM (10 days ago) Sep 10
to Stellarium
OK, so that was a little bit helpful - thank you - but I am still not there.  All I need is a list of the Stellarium script codes and their syntax.  I did learn comments using the pound sign are apparently not supported.  Why the reference I used put them there is rather beyond me.  I renamed the script to screenshot
_script.ssc and stripped it of everything but the actual commands.  When I run it, Stellarium complains

core.setFlagHideGui[undefined] is not a function

I am not sure if that means the target (true) is undefined because core.setFlagHideGu() is not a recognized system call or because "true" is not a recognized value for that function.  If I read the preprocessor correctly, apparently it isn't

I looked up the Stelmain AP, and it looked nothing like these calls, unless I am missing something.The sentax and some of the functiond are not clear to me, either.  For one thing, many of them call for "const Qstring &".  I am not familiar with that directive.

In the AI generated script I am not entirely sure what core.setFlagHideGui() is supposed to do.  In the API it says a similar function merely hides the toolbars.

When I removed all the lines except the

core.screenshot("/RAID/Server-Main/Flat Earth/Stellarium Screen Shots/Video/screenshot.png")

the preprocessor no longer complained (I don't think) and running the sctipt produced no errors inside Stellarium, but in the calling shell it reports

INFO Saving screenshot in file: "/RAID/Server-Main/Flat Earth/Stellarium Screen Shots/Video/screenshot.png001.png"
WARNING failed to write screenshot to : "/RAID/Server-Main/Flat Earth/Stellarium Screen Shots/Video/screenshot.png001.png"

While the suffix puzzles me a bit, it says nothing about why it did not write the screenshot.
Reply all
Reply to author
Forward
0 new messages