(Proof that this works)
If you saw my last post you probably know that I’m into retro video games. What you might not know is that I do my retro gaming using a RetroPie. I can take screen shots of my games while I’m playing, but the RetroPie does not come with the built-in ability to create game play videos. As a result I did some Googling and found a fantastic blog post detailing how to accomplish this on RetroResolution.com: Recording Live Gameplay in RetroPie’s RetroArch Emulators Natively on the Raspberry Pi. The following is a log of how I accomplished this following RetroResolution’s instructions.
Everything I did here I did on an Ubuntu machine running 16.04 LTS. I’m sure you can do all of this Mac box without any changes, but on Windows you’ll need Bash (Windows 10) or an equivalent installed to ssh and perform the backup. If you follow along and if everything goes well I would expect this to take about one full evening.
Note: This post is basically my implementation of the details laid out on retroresolution.com. Be sure to read the original author’s post for all the nitty-gritty details.
This worked for me but please be careful when following the instructions and be sure to backup all your SD Card before proceeding. Proceed at your own risk.
Before starting anything we should backup the Rsapberry Pi’s SD card so that we can get RetroPie running again if we break anything. To do this I plugged my retro pie into my USB to SD Card reader and then plugged it into my computer.
The USB was mounted to ‘/media/selsine/’ as two partitions: ‘/media/selsine/boot’ and ‘/media/selsine/retroppie’. But I didn’t want to backup each partition separately I wanted to backup the entire SD Card. To do that I needed to figure out which disk in ‘/dev/’ was the SD Card. To figure that out I used the following command:
$ mount | grep "/media/selsine"
The output showed me that the two partitions from the SD Card were under ‘/dev’ as ‘/dev/sdb1’ and ‘/dev/sdb2’ that meant that I needed to backup ‘/dev/sdb’.
I did so using the following command which created a compressed image of the disk in a folder named ‘backup’ in my home directory:
$ sudo dd if=/dev/sdb | gzip > ~/backup/retro_pie_backup.gz
It took about 15 minutes for the backup to complete so go do something interesting while that happens. After that I popped the SD card back into the Raspberry Pi and starting working.
Note: Use the following command to restore if something foes wrong:
$ gzip -dc ~/backup/retro_pie_backup.gz | dd of=/dev/sdb
Much of what we need to do we will do by ssh’ing into the Raspberry pPi. To do this you will need the IP address of your RetroPi on the local network. You can get this by going to the RetroPi setup within RetroPie and then selecting “Show IP Address” from the menu. Once you have your IP address you are good to go.
Then you can SSH into the RetroPi using the following command (where 192.168.3.103 is your retro pie’s IP address:
$ ssh email@example.com
NOTE: The default login to a RetroPie is: User=pi Password=raspberry
Before going any further I recommend that you update your RetroPie to the latest version of RetroPie. The makes sure that you don’t run into any issues where you’ve updated one part of RetorPie but not another. To update your RetroPie ssh in and run the following command:
This will bring up the RetroPie setup screen:
From there select ‘Update RetroPie-Setup script’ to update the setup script.
After that we will update all installed packages via the ‘Update all installed packaged’ menu item. Once all of that is done we are ready to proceed.
Note: My splash screen stopped loading after this, so in order to fix that select “Configuration / tools” from the menu:
Then ‘splashscreen – Configure splashscreen’
The select “Choose Splashscreens” | “RetroPie Splashscreens” | “retropie-default.png”.
You can also update your splashscreen from within the RetroPie settings inside of EmulationStation.
As per the RetroResolution instructions the next step is to compile FFmpeg on the RetroPie. This is a relatively simple step since Retro Resolution has provided us with the complete script that we need to compile FFmpeg and it’s related codecs.
I recommend you read his article as it will walk you though all the why’s that I’m about to skip.
The first thing that we need to do is SSH into the RetroPie if you have not already (based on the above instructions). Now that we have logged in we need to create and execute a shell script that will install FFmpeg for us.
First we will create a “tools” directory in the “pi” user’s home directory and then create a script file within that directory:
$ mkdir /home/pi/tools
$ nano /home/pi/tools/ffmpeg-install.sh
The nano command: ‘$ nano /home/pi/tools/ffmpeg-install.sh’ will start the nano text editor and create the shell-script file “ffmpeg-install.sh” in the tools directory.
Then we need to copy the shell script from retro resolution into our nano editor.
Once you have pasted the script hit CTRL+O to save the file and CTRL+X to exit nano.
We are almost done with our script, we just need to make the script executable so that we can run it:
$ chmod +x /home/pi/tools/ffmpeg-install.sh
Now that we have our script, and it’s executable, we need to launch it as root:
$ sudo /home/pi/tools/ffmpeg-install.sh
Then we wait for a long time. I suggest having a beer while this compiles.
Fast-forward 1.5 hours on a Raspberry Pi 2 and the compilation and installation of FFmpeg is complete:
Now that we have FFmpeg on our Raspberry Pie we need to rebuild RetroArch to take advantage of FFmpeg. We’re going to create a script to enabled the FFmpeg headers in RetroArch and then rebuild RetroArch in a very similar way to what we did above with FFmpeg.
First we’ll create a build-retroarch-with-ffmpeg.sh script to do the work for us:
$ nano /home/pi/tools/build-retroarch-with-ffmpeg.sh
Then we will paste in the following script:
#!/bin/bash cd ~/RetroPie-Setup/ # remove the config that disables ffmpeg on the RPI sed -i "s/--disable-ffmpeg//" scriptmodules/emulators/retroarch.sh # build new retroarch from source sudo ./retropie_packages.sh retroarch # put the file back how it was git checkout scriptmodules/emulators/retroarch.sh
Then save (CTRL+O) and exit (CTRL+X).
Next we need to make the script executable:
$ chmod +x /home/pi/tools/build-retroarch-with-ffmpeg.sh
And finally execute it, but NOT as root:
It should finish after about 10 minutes.
We now need to see if it worked by restarting the raspberry pie and then starting a game. Once the game has started hit select+X on your controller to bring up the RetroArch menu. For me the RetroArch menu was now lacking icons, but you need to select ‘Driver’ from the menu and then look at the ‘recording’ entry and verify that it says ‘ffmpeg’ instead of ‘null’
Mount a USB Drive for Recording
We are going to save our videos onto a USB drive connected to the Raspberry Pie. RetroResolution says that this is a better, more efficient, way to record the videos. If you want you can record to the SD card and skip this step.
If we are going to save the videos on a USB drive we need to plug a USB drive into the Raspberry Pie and get the OS to mount it automatically at boot time. So plug the USB drive in, ssh into the Raspberry Pie, and then list all of the drives using the following command:
$ ls -l /dev/disk/by-uuid/
From my output I know that SDA1 is the drive that I want. So what I want to do is add the following line to my FSTAB file, using the UUID of the drive from the output to automatically mount my USB drive:
UUID=1BE2-9CBE /media/usb_video vfat nofail,user,umask=0000 0 2
Note: The above command is for a USB device that is using the FAT file system. If your USB drive is NTFS, HFS+, EXT3, or any other file system you will have to use a different command. This article on ubuntu.com should help.
We will edit the fstab file as root using the following command:
$ sudo nano /etc/fstab
Then make our mount directory as root;
$ sudo mkdir /media/usb_video
We can test to make sure that our drive can be mounted using the following command, which we execute not as root, to be sure that the default pi user can mount the drive:
$ mount /media/usb_video/
If we don’t see an error the drive will be mounted on boot going forward.
Enable the Recording
Now we have everything in place to start recording our games. The first step is to create a recording config file. This config file will tell FFmpeg which options we want during the recording.
Created the config file with the following command:
$ mkdir /home/pi/RetroPie/recording
$ nano /home/pi/RetroPie/recording/config.cfg
Paste the following into the config file (which come from RetroResolution)to start, you can play with the settings once your recording is working:
format = matroska threads = 3 vcodec = libx264rgb video_preset = ultrafast video_tune = animation pix_fmt = bgr24 video_qp = 0 acodec = flac
Now we need to tell RetroArch to record when we play the games from certain systems. To do so we need to edit the ’emulators.cfg’ file for each system. To start I’ll show you how to edit the NES config file.
Each system’s config file exists in the following path, where <
So for the original Nintendo we need to edit the following config file:
What we are going to do is add two entries that will launch an emulator and start a recording. Here is the command to edit the NES config file in nano:
$ nano /opt/retropie/configs/nes/emulators.cfg
We will add the following two config entries that will start a recording. The first will use the config file that we created above, and the second will record with the default FFmpeg settings:
lr-fceumm-record-hdd = "/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-fceumm/fceumm_libretro.so --config /opt/retropie/configs/nes/retroarch.cfg --record /media/usb_video/recording_NES_$(date +%Y-%m-%d-%H%M%S).mkv --recordconfig /home/pi/RetroPie/recording/config.cfg %ROM%"
lr-fceumm-record-hdd-no-config = "/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-fceumm/fceumm_libretro.so --config /opt/retropie/configs/nes/retroarch.cfg --record /media/usb_video/recording_NES_$(date +%Y-%m-%d-%H%M%S).mkv %ROM%"
The magic happens in this part of the command:
--record /media/usb_video/recording_NES_$(date +%Y-%m-%d-%H%M%S).mkv
Where we tell RetroArch to record a video and create a recording file on the USB drive that we mounted earlier. We use a timestamp in the file name: ‘$(date +%Y-%m-%d-%H%M%S)’ (which comes from a suggestion on the RetroPie forums) so that we don’t override any previous recordings.
This part of the first command tells FFmpeg to use our config file to configure itself:
Now launch an NES game and press ‘A’ while the game is loading. Then select ‘Select emulator for ROM’ (to make it ROM specific) or ‘Select default emulator for nes’ for all NES games, and pick one of the above options that we added. I suggest ‘lr-fceumm-record-hdd’. Play the game for a few seconds and then quit.
Now check the USB for the files:
$ ls /media/usb_video/
If all has gone well you should see one recordings from the game that you just played (I tested a few times so I have more that one recording):
That’s it. If everything has gone well you should have an updated RetroPie that can now create gameplay videos. If you have any questions or run into any issues please leave a comment.
Be sure to checkout RetroResolution.com without whom getting this done would have taken a lot longer than it did.
17 thoughts on “How To Record A GamePlay Video From A RetroPie”
Thank you for the tutorial, This is Almost working perfectly ^^
I have so really bad fps (in the nes emulator) and in ssh if i type the top command i am using 150% of the processor, any idea why ?
Does this work with DosBox? Looks like it’s only lr- cores, correct?
Honestly I don’t know. Have you given it a try? If you run it into problems let me know maybe I could poke around a bit.
The only issue i have is audio and video delay on my end. I’m able to stream to viewers, but i get the delay..about 1-2 secs. I’m using the elgato and obs. Tried changes the delay to 650ms 500ms etc as per those other tutorials out there. Any ideas?
How do you have the elgato configured with the RetroPie? Honestly I have no experience with it myself. I’m hoping to get one at some time though.
Done everything stated but when i load up a game it goes back to the game list. Haven’t done the USB feature. Any ideas on what to fix?
Same here. The log seems to identify an issue with the brackets in the video file name. If you remove the date stamp it works, but then you lose the full depth of journaling.
Brilliant post, thank you! I found some things I needed to change, and tried to simplify things a bit, and put the results on GitHub. The result is at https://www.artificialworlds.net/blog/2018/01/07/recording-gameplay-videos-on-retropie/ – comments welcome!
That’s awesome! Thanks for putting this stuff up on github.
Thanks for putting this together! Running into an issue though. I didn’t get any errors along the way running thru this tutorial, but in the moment of truth, the roms won’t run. I made the change to use the “lr-fceumm-record-hdd” and I get kicked back immediately to the games list.
When I looked at “/dev/shm/runcommand.log” I get the following:
Executing: /opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-fceumm/fceumm_libretro.so –config /opt/retropie/configs/nes/retroarch.cfg –record /media/usb_video/recording_NES_\$(date +%Y-%m-%d-%H%M%S).mkv –recordconfig /home/pi/RetroPie/recording/config.cfg “/home/pi/RetroPie/roms/nes/Batman.NES” –appendconfig /dev/shm/retroarch.cfg
/opt/retropie/supplementary/runcommand/runcommand.sh: eval: line 1007: syntax error near unexpected token `(‘
/opt/retropie/supplementary/runcommand/runcommand.sh: eval: line 1007: `/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-fceumm/fceumm_libretro.so –config /opt/retropie/configs/nes/retroarch.cfg –record /media/usb_video/recording_NES_\$(date +%Y-%m-%d-%H%M%S).mkv –recordconfig /home/pi/RetroPie/recording/config.cfg “/home/pi/RetroPie/roms/nes/Batman.NES” –appendconfig /dev/shm/retroarch.cfg’
I’m currently running the following:
Linux 4.14.79-v7+ armv7l GNU/Linux
I’ve also tried messing with the parens around “Date” and also did some testing around the PSX config as well, but can’t seem to get the rom to load either.
Any help would be greatly appreciated. Trying to get to that big streaming up in the sky step, but saw I had to get this working first.
P.S. Completely new at Linux and I had a hell of a time logging in to SSH initially. All the info I found was “try this command”, “this command”, etc. etc. And by accident, I realized the Pi uses a UK keyboard setting and my special character was coming out different when typed from my US keyboard remotely. Out of all the people who have issues, I wonder if this was it for them?
Hi, I can’t connect to RPi. I have Win10. I tried via PuTTy and Ubuntu but I still couldn’t. Please, give me an advice. Thx
Hi. It seems like everyone seems to be able to set up their RPI with this xcept moi!
I am stuck at the auto mounting the hdd.
The Pi recognizes the hdd cause I can see sum other shit that I got in there with the retroarch file explorer but it doesn’t play roms if its hooked up and obviously can’t record
Also I can’t get the video output file to go to the hdd. Its been 4 days and I can’t figure it out can anyone help.
Thank you very much. It helped me a lot