Takenover83
Posts: 166
Joined: Mon Sep 02, 2013 5:39 am

Take screenshots/video's without X server?

Wed Nov 20, 2013 12:39 am

I have been trying various method's but I have yet to get anything to work outside of x. I would like to get some screenshot's of xbmc, omxplayer, retroarch, emulationstation, etc... These all seem to run without X. So how do I go about capturing the screen they run on? ffmpeg? x11grab is a no go, as these are not using X as far as I know. capturing the framebuffer via fbdev? I tried that, but I usually just end up with a black screenshot.

So can anyone point me in the right direction or better yet give me a example?

User avatar
DrDominodog51
Posts: 79
Joined: Sun Sep 29, 2013 6:16 pm

Re: Take screenshots/video's without X server?

Wed Nov 20, 2013 1:29 am

I would get an external display recorder and take screenshots from the video.This requires another computer for taking the screenshot from the video though....
If you don't make it, it's your own damn vault. -Land of the Lost poster

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Take screenshots/video's without X server?

Wed Nov 20, 2013 1:51 am

I have written a program called raspi2png that will take a snapshot of whatever is displayed on the Raspberry Pi screen. You will need to compile it yourself! It should run on any of the Linux derived operating systems.

Takenover83
Posts: 166
Joined: Mon Sep 02, 2013 5:39 am

Re: Take screenshots/video's without X server?

Wed Nov 20, 2013 9:25 am

Thank's. This is the first program that's actually been able to capture what's on the screen for me. Much appreciated.

forumisto
Posts: 386
Joined: Fri Mar 16, 2012 8:41 am

Re: Take screenshots/video's without X server?

Wed Nov 20, 2013 2:07 pm

Takenover83 wrote:I have been trying various method's but I have yet to get anything to work outside of x. I would like to get some screenshot's of xbmc, omxplayer, retroarch, emulationstation, etc... These all seem to run without X. So how do I go about capturing the screen they run on? ffmpeg? x11grab is a no go, as these are not using X as far as I know. capturing the framebuffer via fbdev? I tried that, but I usually just end up with a black screenshot.

So can anyone point me in the right direction or better yet give me a example?
do you have a particular configuratino for omxplayer?

Takenover83
Posts: 166
Joined: Mon Sep 02, 2013 5:39 am

Re: Take screenshots/video's without X server?

Wed Nov 20, 2013 2:57 pm

I use omxplayer along side emulationstation, as seen here or here.

Heater
Posts: 12646
Joined: Tue Jul 17, 2012 3:02 pm

Re: Take screenshots/video's without X server?

Wed Nov 20, 2013 3:54 pm

What a wonderfully small, simple, and useful program. Thank you for raspi2png.

Takenover83
Posts: 166
Joined: Mon Sep 02, 2013 5:39 am

Re: Take screenshots/video's without X server?

Wed Nov 20, 2013 5:24 pm

I am trying to build a script to auto increment filename and capture. After googling I pieced this together. Likely not the best way to go about it. Anyone have a better way.

Code: Select all

#!/bin/bash

count=1000
while [ $count -ne 1500 ] ; do

    count=`expr $count + 1`    
    raspi2png -h 480 -w 640 -p ~/screens/${count:1}.png
   
done
My real goal is to convert the captures images to video via ffmpeg

Kreten
Posts: 1
Joined: Sun Mar 30, 2014 10:17 am

Re: Take screenshots/video's without X server?

Sun Mar 30, 2014 10:26 am

AndyD wrote:I have written a program called raspi2png that will take a snapshot of whatever is displayed on the Raspberry Pi screen. You will need to compile it yourself! It should run on any of the Linux derived operating systems.
Would it be possible to tell me how to do this for G-Box Slav with J1nx Linux xbmc 12? Every time I take a screenshot through xbmc: If UI then screenshot is ok but in Video just blank screen or just screenshot of play pause ui. I'm thinking it's the same exact problem as RasPi has of directly outputing video to hdmi so it doesn't capture it.

I would really appreciate your help as I've tried everything I could for past 8 months with no dice :-(
Thanks

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Take screenshots/video's without X server?

Sun Mar 30, 2014 9:17 pm

Kreten wrote:Would it be possible to tell me how to do this for G-Box Slav with J1nx Linux xbmc 12? Every time I take a screenshot through xbmc: If UI then screenshot is ok but in Video just blank screen or just screenshot of play pause ui. I'm thinking it's the same exact problem as RasPi has of directly outputing video to hdmi so it doesn't capture it.
Unfortunately, no I have no idea. The raspi2png program is a very simple program that uses an API provided for the Raspberry Pi that takes a snapshot of the image displayed by the compositor. It is specific to the Raspberry Pi.

colinsjones
Posts: 1
Joined: Wed Jul 10, 2013 6:36 am

Re: Take screenshots/video's without X server?

Sun Apr 13, 2014 8:09 am

Thanks AndyD for raspi2png, nice simple code which works a treat, very professional.

plasmasnake
Posts: 14
Joined: Wed Dec 09, 2015 7:25 pm

Re: Take screenshots/video's without X server?

Tue Jan 19, 2016 12:39 am

AndyD wrote:I have written a program called raspi2png that will take a snapshot of whatever is displayed on the Raspberry Pi screen. You will need to compile it yourself! It should run on any of the Linux derived operating systems.
Amazing, just what I needed! Thanks for the great tool :)

I'm using it essentially to display a thumbnail of the screen on a web interface. So I'm running "raspi2png -w 320 -h 180 -c 0". It's almost instantaneous with the compression disabled, and the file size is still small because of the low resolution.

plasmasnake
Posts: 14
Joined: Wed Dec 09, 2015 7:25 pm

Re: Take screenshots/video's without X server?

Tue Jan 19, 2016 12:56 am

AndyD wrote:I have written a program called raspi2png that will take a snapshot of whatever is displayed on the Raspberry Pi screen. You will need to compile it yourself! It should run on any of the Linux derived operating systems.
So as I posted above, I tried this tool and at first it worked great, but after taking a few screenshots I'm now getting the error "raspi2png: vc_dispmanx_snapshot() failed". Any idea why that may be happening?

Edit: If I leave out the width/height/compression parameters I get a different error message: "raspi2png: unable to allocated image buffer"

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Take screenshots/video's without X server?

Tue Jan 19, 2016 7:49 am

plasmasnake wrote:
AndyD wrote:I have written a program called raspi2png that will take a snapshot of whatever is displayed on the Raspberry Pi screen. You will need to compile it yourself! It should run on any of the Linux derived operating systems.
So as I posted above, I tried this tool and at first it worked great, but after taking a few screenshots I'm now getting the error "raspi2png: vc_dispmanx_snapshot() failed". Any idea why that may be happening?

Edit: If I leave out the width/height/compression parameters I get a different error message: "raspi2png: unable to allocated image buffer"
No idea sorry. There is nothing very special about the raspi2png program. There first error is because on an error from DispmanX api. The second error is more surprising. It would appear that you have very little free memory. Can you post the output of free command.

plasmasnake
Posts: 14
Joined: Wed Dec 09, 2015 7:25 pm

Re: Take screenshots/video's without X server?

Tue Jan 19, 2016 11:55 pm

AndyD wrote:No idea sorry. There is nothing very special about the raspi2png program. There first error is because on an error from DispmanX api. The second error is more surprising. It would appear that you have very little free memory. Can you post the output of free command.
Thanks for the response Andy! I just tried and this is what I get:

Code: Select all

             total       used       free     shared    buffers     cached
Mem:        380072     358320      21752      13592      29644     228024
-/+ buffers/cache:     100652     279420
Swap:       102396          0     102396
Considering there's 20MB free and over 200MB cached, I assume that's plenty? Anything else you think I should try?

plasmasnake
Posts: 14
Joined: Wed Dec 09, 2015 7:25 pm

Re: Take screenshots/video's without X server?

Wed Jan 20, 2016 1:03 am

OK, this is quite strange. I edited the source code, and under the following line:
void *dmxImagePtr = malloc(dmxPitch * dmxHeight);

I added:
printf("%d, %d\n", dmxPitch, dmxHeight);

Then I ran the tool again, and it worked. The output was "7680, 1080". I ran it several times for good measure, and it worked fine.

Then I went downstairs for dinner, and after coming back I ran the tool again, and here's the new output:

raspi2png: unable to allocated image buffer
64, 516593392

Edit: OK, I figured out what was wrong. The TV is scheduled to turn on/off at specific times. It turns out this is what happens when the TV is off. I wonder if there's an easy way to add a line that checks if the display is active? If not, no big deal... I can take care of that in a shell script.

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Take screenshots/video's without X server?

Wed Jan 20, 2016 8:11 am

plasmasnake wrote:OK, this is quite strange. I edited the source code, and under the following line:
void *dmxImagePtr = malloc(dmxPitch * dmxHeight);

I added:
printf("%d, %d\n", dmxPitch, dmxHeight);

Then I ran the tool again, and it worked. The output was "7680, 1080". I ran it several times for good measure, and it worked fine.

Then I went downstairs for dinner, and after coming back I ran the tool again, and here's the new output:

raspi2png: unable to allocated image buffer
64, 516593392

Edit: OK, I figured out what was wrong. The TV is scheduled to turn on/off at specific times. It turns out this is what happens when the TV is off. I wonder if there's an easy way to add a line that checks if the display is active? If not, no big deal... I can take care of that in a shell script.
That is interesting. I will see if I can reproduce it.

plasmasnake
Posts: 14
Joined: Wed Dec 09, 2015 7:25 pm

Re: Take screenshots/video's without X server?

Thu Jan 21, 2016 4:18 am

AndyD wrote: That is interesting. I will see if I can reproduce it.
It only seems to happen when the HDMI output is powered down (via the tvservice tool). If the TV is turned off manually but the HDMI output is still active, I can still take screenshots.

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Take screenshots/video's without X server?

Thu Jan 21, 2016 7:54 am

plasmasnake wrote:It only seems to happen when the HDMI output is powered down (via the tvservice tool). If the TV is turned off manually but the HDMI output is still active, I can still take screenshots.
So using:-

Code: Select all

tvservice -o
I will give it a try and let you know.

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Take screenshots/video's without X server?

Thu Jan 21, 2016 1:07 pm

OK, I can reproduce it. I should have been checking the return value of vc_open_display(), it returns 0 (zero) on error.

The bad news is, you can't take a snapshot when the display is off.

MrEngman
Posts: 3828
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Take screenshots/video's without X server?

Thu Jan 21, 2016 1:30 pm

I don't run X gui. I communicate with my Pi's using SSH. Should I be able to take a snapshot of a terminal window. I have tried and all I get is a black rectangle.


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Take screenshots/video's without X server?

Thu Jan 21, 2016 2:08 pm

MrEngman wrote:I don't run X gui. I communicate with my Pi's using SSH. Should I be able to take a snapshot of a terminal window. I have tried and all I get is a black rectangle.


MrEngman
Yes, you can run raspi2png when you have ssh'ed into the Raspberry Pi. The snapshot will be of the output of the Raspberry Pi.

MrEngman
Posts: 3828
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Take screenshots/video's without X server?

Thu Jan 21, 2016 2:16 pm

AndyD wrote:
MrEngman wrote:I don't run X gui. I communicate with my Pi's using SSH. Should I be able to take a snapshot of a terminal window. I have tried and all I get is a black rectangle.


MrEngman
Yes, you can run raspi2png when you have ssh'ed into the Raspberry Pi. The snapshot will be of the output of the Raspberry Pi.
Strange then as all I get is a black rectangle with no text showing. The command I have run is ./raspi2png with no options set just to try it out.



MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

tvjon
Posts: 704
Joined: Mon Jan 07, 2013 9:11 am

Re: Take screenshots/video's without X server?

Thu Jan 21, 2016 5:11 pm

"Should I be able to take a snapshot of a terminal window. I have tried and all I get is a black rectangle."

Can you elaborate MrEngman?

What is your hdmi configuration? Do you have nothing plugged in to the hdmi socket?

Here's the snapshot I have as a result of running

raspi2png

(On this Jessie µSD card, I have raspi2png in my bin folder, hence don't need a ./ prefix.)

with no monitor connected, from an iOS device via ssh after switching on the RPi.
snapshot.png
snapshot.png (17.96 KiB) Viewed 4713 times

DirkS
Posts: 9839
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Take screenshots/video's without X server?

Thu Jan 21, 2016 5:20 pm

"Should I be able to take a snapshot of a terminal window. I have tried and all I get is a black rectangle."

Can you elaborate MrEngman?
I think I'm seeing the same as MrEngman.
AndyD updated the program today and now emits an error instead of an empty image.
SSH'd into a headless Pi (Zero to be precise) I get:

Code: Select all

raspi2png: unable to open display 0
Output of tvservice -s

Code: Select all

state 0x40001 [NTSC 4:3], 720x480 @ 60.00Hz, interlaced

Return to “General discussion”