• Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login
RetroPie forum home
  • Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login

Take and Scrape Your Own Screenshots

Scheduled Pinned Locked Moved Ideas and Development
retroarchscreenshotscrapesselphruncommand
122 Posts 8 Posters 66.5k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H
    herb_fargus administrators
    last edited by herb_fargus 16 Aug 2016, 23:18

    UPDATE!!! SEE WIKI PAGE FOR LATEST GUIDE:

    https://github.com/RetroPie/RetroPie-Setup/wiki/Take-and-Scrape-Your-Own-Screenshots


    Taking your own screenshots and creating your own gamelists

    Some of the scraping resources can be a bit shoddy with old boxart scans and poor quality data, so I prefer to use screenshots as they are more or less standardised and don't have to many variances in quality (ignoring pixel scaling issues) so I wanted to come up with a simple ish semi-automated way to generate my own imagery from screenshots.

    A few disclaimers first:

    • MAKE A BACKUP AND USE AT YOUR OWN RISK!

    • You need to be on RetroPie 4.0 or be fully updated to the latest version

    • You can only create one screenshot per game (I can append a date variable to it so that you can have more than one but it really defeats the purpose as in the end when generating the gamelists sselphs scraper can only handle a one to one relationship)

    • This only works with retroarch emulators

    • note this is just something I put together in an afternoon so there is room for improvement to be sure.

    LETS BEGIN!

    Set the Stage

    You need create an images folder in each rom folder you want screenshots for and then set the system based retroarch.cfg screenshot path to each respective images folder so that the images can be easily joined with sselphs scraper, unlike the default retropie behaviour this will keep your images and gamelists in each system folder with your roms; the pattern is as follows:

    /home/pi/RetroPie/roms/<system>/images

    so for example if I'm adding screenshots to the snes I would create:

    /home/pi/RetroPie/roms/snes/images

    Then I would add that screenshot path to:

    /opt/retropie/configs/snes/retroarch.cfg

    # Settings made here will only override settings in the global retroarch.cfg if placed above the #include line
    
    input_remapping_directory = "/opt/retropie/configs/snes/"
    screenshot_directory = "/home/pi/RetroPie/roms/snes/images/"
    
    #include "/opt/retropie/configs/all/retroarch.cfg"
    

    Take a Screenshot

    The default screenshot button is F8 which means if you've configured your keyboard through emulationstation you have to hold the hotkey button (by default the button you configured as select) and then press F8. If you want to have it so that you can take a screenshot with your controller you'll change the screenshot button to a button that isn't already being used for hotkey behaviour. To do this you'll edit the overall or master retroarch.cfg if you will at
    /opt/retropie/configs/all/retroarch.cfg

    the key line you want to change is ~line 580

    # Take screenshot
    # input_screenshot = f8

    so in my case I changed it to my right analogue thumb

    # Take screenshot
    input_screenshot_btn = "12"
    

    Runcommand

    In order to link our screenshots with our roms, the screenshot filename has to match the rom filename. We use the runcommand function to help automate generating the filenames for our screenshots to match the rom we are playing.

    you need to create a file called runcommand-onend.sh in the folder /opt/retropie/configs/all/

    copy the following contents:

    #!/usr/bin/env bash
    system="$1"
    rom="$3"
    rom_bn="${rom##*/}"
    rom_bn="${rom_bn%.*}"
    imgdir="$HOME/RetroPie/roms/$system/images"
    # find the most recent RetroArch screenshot
    screenshot=$(find "$imgdir" -type f -name '*RetroArch*' | tail -1)
    # Rename most recent RetroArch screenshot (if it exists) to rom name and remove leftover RetroArch screenshots
    if [[ -f "$screenshot" ]]; then
    mv "$screenshot" "$imgdir/$rom_bn.png"
    rm -f "$imgdir"/*RetroArch*
    fi

    Now you can play your games and take your screenshots and it will fill your images folder with your screenshots.

    Create gamelist with Sselphs scraper

    If you haven't already, download sselphs scraper from the setup script

    Now that you've got your screenshots ready all you have to do is use sselph's scraper to generate a gamelist for your screenshots- this will effectually link your roms to their respective screenshots.

    You need to exit emulationstation first

    so again using the snes as an example

    cd /home/pi/RetroPie/roms/snes
    /opt/retropie/supplementary/scraper/scraper -img_format=png -add_not_found=true -download_images=false -image_suffix=

    it will create a gamelist.xml file in /home/pi/RetroPie/roms/snesand will override the gamelist.xml in /home/pi/.emulationstation/gamelists/snes

    and if all went according to plan, when you boot emulationstation back up your images will be the screenshots that you took! TADA!

    I suppose there may also be the possibility of using raspi2png in the same way, except raspi2png has much larger filesizes and takes a picture of the whole screen-including the blackspace on the edges if the game is 4:3- see references for more details

    References:

    https://retropie.org.uk/forum/topic/1975/taking-an-actual-screenshot/
    https://retropie.org.uk/forum/topic/2483/screenshot-with-rom-name/
    https://github.com/RetroPie/RetroPie-Setup/issues/1242
    https://github.com/retropie/retropie-setup/wiki/scraper

    If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

    Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

    M 1 Reply Last reply 17 Aug 2016, 02:16 Reply Quote 5
    • M
      meleu @herb_fargus
      last edited by meleu 17 Aug 2016, 02:16

      @herb_fargus
      cool trick dude!

      just some suggestions for improvements in runcommand-onend.sh:

      1. Get the system and the rom from the arguments. system is arg 1 and rom is arg 3, as you can see here: https://github.com/RetroPie/RetroPie-Setup/blob/master/scriptmodules/supplementary/runcommand/runcommand.sh#L777

      2. Get the most recent screenshot with tail.

      3. Avoid error messages.

      4. Platform independent (home directory not hardcoded to /home/pi).

      5. Set a variable to store the image directory (if you change your mind about where to store the images, you have to change only one line).

      The script becomes like this:

      #!/usr/bin/env bash
      system="$1"
      rom="$3"
      rom_bn="${rom##*/}"
      rom_bn="${rom_bn%.*}"
      imgdir="$HOME/RetroPie/roms/$system/images"
      # find the most recent RetroArch screenshot
      screenshot=$(find "$imgdir" -type f -name 'RetroArch*' 2>/dev/null | tail -1)
      # rename the recently taken screenshot to the rom name and copy into the images folder
      if [[ -n "$screenshot" ]]; then
      mv "$screenshot" "$imgdir/$rom_bn.png"
      rm -f "$imgdir"/*RetroArch*
      fi
      • Useful topics
      • joystick-selection tool
      • rpie-art tool
      • achievements I made
      H 2 Replies Last reply 17 Aug 2016, 02:43 Reply Quote 1
      • H
        herb_fargus administrators @meleu
        last edited by 17 Aug 2016, 02:43

        @meleu Thanks! I tried earlier with the $rom variable but I forgot I had to initialise it so it didn't work, ill give your updated script a go.

        If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

        Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

        1 Reply Last reply Reply Quote 0
        • H
          herb_fargus administrators @meleu
          last edited by herb_fargus 17 Aug 2016, 02:57

          @meleu yep it works, I've updated my original post with your latest code.

          There are a few caveats:

          • If you for example take 5 screenshots while playing super mario world, then open up donkey kong, and then don't take a screenshot, the 4th super mario world screenshot becomes your donkey kong screenshot

          • If you take a new screenshot after scraping, it will overwrite the screenshot that is there and will automatically replace the screenshot for that game (which is kinda cool, but also can be a bad thing depending on how you look at it.)

          If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

          Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

          M 2 Replies Last reply 17 Aug 2016, 03:01 Reply Quote 1
          • M
            meleu @herb_fargus
            last edited by 17 Aug 2016, 03:01

            @herb_fargus said in Take and Scrape Your Own Screenshots:

            • If you for example take 5 screenshots while playing super mario world, then open up donkey kong, and then don't take a screenshot, the 4th super mario world screenshot becomes your donkey kong screenshot

            Oh, I see. Maybe it's better to remove all the remaining screenshots after the last mv. I'll edit my post.

            • Useful topics
            • joystick-selection tool
            • rpie-art tool
            • achievements I made
            1 Reply Last reply Reply Quote 0
            • M
              meleu @herb_fargus
              last edited by 17 Aug 2016, 03:05

              @herb_fargus It's important to mention that this trick only works on the Raspberry Pi version (home directory is /home/pi).

              • Useful topics
              • joystick-selection tool
              • rpie-art tool
              • achievements I made
              H 1 Reply Last reply 17 Aug 2016, 03:10 Reply Quote 0
              • H
                herb_fargus administrators @meleu
                last edited by 17 Aug 2016, 03:10

                @meleu ah thats right too, perhaps if we use the $user variable like we did with the retropie manager that should address it?

                If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                M 1 Reply Last reply 17 Aug 2016, 03:16 Reply Quote 0
                • M
                  meleu @herb_fargus
                  last edited by meleu 17 Aug 2016, 03:16

                  @herb_fargus
                  I've just realized that the rom name has a full path filename! We can get the home directory from it:

                  homedir=$(echo "$rom" | grep -o '\/home\/[^\/]*')
                  

                  [EDIT: explaining the grep: the -o tells the grep to show only the matching pattern (and not the entire line); the regex means: the string "/home/" followed by anything different from "/" (which is the username).]

                  updating my script on the post...

                  • Useful topics
                  • joystick-selection tool
                  • rpie-art tool
                  • achievements I made
                  H 1 Reply Last reply 17 Aug 2016, 05:33 Reply Quote 0
                  • H
                    herb_fargus administrators @meleu
                    last edited by 17 Aug 2016, 05:33

                    @meleu what about this?

                    #!/usr/bin/env bash
                    system="$1"
                    rom="$3"
                    rom_bn="${rom##*/}"
                    rom_bn="${rom_bn%.*}"
                    # Find most recent screenshot taken
                    screenshot=$(find "/home/$USER/RetroPie/roms/$system/images" -type f -print | grep 'RetroArch' | tail -n -1)
                    #rename most recent screenshot to rom name *note after scraping if you take a screenshot again it will overwrite the original image
                    mv "$screenshot" "/home/$USER/RetroPie/roms/$system/images/$rom_bn.png"
                    # Remove every RetroArch screenshot except the most recent
                    find "/home/$USER/RetroPie/roms/$system/images" -type f -name '*RetroArch*' -delete

                    If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                    Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                    M 1 Reply Last reply 17 Aug 2016, 11:24 Reply Quote 0
                    • M
                      meleu @herb_fargus
                      last edited by meleu 17 Aug 2016, 11:24

                      @herb_fargus
                      I avoided the $USER because I was never really sure when RetroPie/emulationstation is executing a command with the regular user or with sudo. But now I checked here and it's the regular user (looked at the es_system.cfg to see the runcommand calling line, no sudo).

                      I would suggest just some superfluous/cosmetic changes:

                      1. use $HOME instead of /home/$USER;
                      2. use a variable to store the image directory path instead type it 3 times (if you change your mind about where to store the images, you have to change only one line):
                      imgdir="$HOME/RetroPie/roms/$system/images"
                      
                      1. I put a 2> /dev/null in the screenshot's variable find to avoid error messages. I did it because all the error messages when executing runcommand-on{start,end}.sh scripts are logged in runcommand.log. I used that if to check if screenshot is not empty for the same reason.
                      2. the last find to delete the unwanted screenshots is fully OK for this application. But for other applications it would delete all the files that match the -name pattern in the subdirectories too. I used rm with -f because this option ignores nonexistent files, therefore no error messages if there is no screenshots to delete.

                      Updating my script again...

                      • Useful topics
                      • joystick-selection tool
                      • rpie-art tool
                      • achievements I made
                      H 1 Reply Last reply 17 Aug 2016, 16:13 Reply Quote 1
                      • H
                        herb_fargus administrators @meleu
                        last edited by herb_fargus 17 Aug 2016, 16:13

                        @meleu typo:

                        rm -f "$imgdir/*RetroArch*

                        should be

                            rm -f "$imgdir"/*RetroArch*
                        

                        I presume. There may be ways we can refactor it further as well

                        also is the print necessary?

                        If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                        Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                        M 1 Reply Last reply 17 Aug 2016, 16:19 Reply Quote 1
                        • M
                          meleu @herb_fargus
                          last edited by meleu 17 Aug 2016, 16:19

                          @herb_fargus
                          Actually the double quotes comes in the end, otherwise some parsing problems can happen. Thanks for noting this.

                          [EDIT: this doesn't work. Look the next posts...]

                          rm -f "$imgdir/*RetroArch*"
                          
                          • Useful topics
                          • joystick-selection tool
                          • rpie-art tool
                          • achievements I made
                          H 1 Reply Last reply 17 Aug 2016, 16:21 Reply Quote 0
                          • H
                            herb_fargus administrators @meleu
                            last edited by 17 Aug 2016, 16:21

                            @meleu you should really test things before you say them authoritatively ;) quotes at the end doesnt work.

                            If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                            Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                            M 1 Reply Last reply 17 Aug 2016, 16:32 Reply Quote 1
                            • M
                              meleu @herb_fargus
                              last edited by meleu 17 Aug 2016, 16:32

                              @herb_fargus
                              You're right... updated my script...
                              I deserve a downvote!
                              undefined

                              • Useful topics
                              • joystick-selection tool
                              • rpie-art tool
                              • achievements I made
                              H 1 Reply Last reply 17 Aug 2016, 17:01 Reply Quote 1
                              • H
                                herb_fargus administrators @meleu
                                last edited by 17 Aug 2016, 17:01

                                @meleu alright I've taken some of your changes and just tweaked it a bit, and modified the original post. It seems to be working with my tests.

                                There may have been a slight lag either because I was taking screenshots too fast or I exited before it could be saved properly so it saved a screenshot from a couple seconds earlier rather than my latest one, so I'll have to look into that a little further. If you don't take a ton in a short period of time it seems to work as intended.

                                Also if anyone else cares, if you set it to 16:9 in the retroarch.cfg your screenshots will also be 16:9 rather than 4:3

                                If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                                Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                                M 1 Reply Last reply 19 Aug 2016, 06:20 Reply Quote 1
                                • M
                                  meleu @herb_fargus
                                  last edited by meleu 19 Aug 2016, 06:20

                                  @herb_fargus
                                  I was thinking about this trick again and realized one thing:

                                  When using this trick, the user can't get screenshots for any other purpose.

                                  The runcommand-onend.sh will delete the screenshots.

                                  While we don't make a workaround for this, I think it would be appropriate to add this warning at the first post disclaimers.

                                  • Useful topics
                                  • joystick-selection tool
                                  • rpie-art tool
                                  • achievements I made
                                  H 1 Reply Last reply 19 Aug 2016, 06:57 Reply Quote 0
                                  • H
                                    herb_fargus administrators @meleu
                                    last edited by 19 Aug 2016, 06:57

                                    @meleu They can as long as they change the screenshot directory to somewhere else other than the images folder within a rom folder.

                                    If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                                    Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                                    M 1 Reply Last reply 19 Aug 2016, 07:46 Reply Quote 0
                                    • H
                                      hiulit
                                      last edited by 19 Aug 2016, 07:17

                                      This tutorial could make a great entry in the RetroPie Wiki! What do you guys think?

                                      My little contributions to the RetroPie project:

                                      • Shell-Script-Boilerplate
                                      • Fun-Facts-Splashscreens
                                      • Limit-Last-Played-Games
                                      H 2 Replies Last reply 19 Aug 2016, 07:42 Reply Quote 0
                                      • H
                                        herb_fargus administrators @hiulit
                                        last edited by 19 Aug 2016, 07:42

                                        @hiulit perhaps once I've cleaned up the code a bit more, might even be able to make a module of sorts perhaps, idk. Id also like for 4.0 to be released before adding something like this.

                                        If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                                        Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                                        H 1 Reply Last reply 19 Aug 2016, 07:45 Reply Quote 0
                                        • H
                                          hiulit @herb_fargus
                                          last edited by 19 Aug 2016, 07:45

                                          @herb_fargus Yeah sure, no rush! Just thinking out loud. Great work, btw!

                                          My little contributions to the RetroPie project:

                                          • Shell-Script-Boilerplate
                                          • Fun-Facts-Splashscreens
                                          • Limit-Last-Played-Games
                                          1 Reply Last reply Reply Quote 0
                                          20 out of 122
                                          • First post
                                            20/122
                                            Last post

                                          Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                          Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.

                                            This community forum collects and processes your personal information.
                                            consent.not_received