mGBA Camera
This is a guide to set up the mGBA Camera plugin on a Raspberry Pi. It allows you to create a virtual camera device from a physical high-resolution camera that simulates the Game boy Camera, which can be used in the mGBA emulator to capture images and videos in the emulator.
Assuming you have already conntected a compatible camera to your Raspberry Pi (recommand using the offical Raspberry Pi Camera Module V3) and have mGBA installed, you can follow the steps below to set up the virtual camera and configure mGBA to use it.
Install Packages
First, you need to install the necessary packages. Open a terminal and run the following commands:
sudo apt-get update
sudo apt-get install v4l2loopback-dkms ffmpeg mGBA-qt
Setup Virtual Camera
We need to create a virtual camera device using the v4l2loopback kernel module. Run the following command to load the module:
sudo modprobe v4l2loopback video_nr=10 card_label="GameBoyCamera" exclusive_caps=1
This creates /dev/video10 as a new camera input. Now list the video devices to confirm:
v4l2-ctl --list-devices
You will be able to see the new “GameBoyCamera” device in the list.
GameBoyCamera (platform:v4l2loopback-010):
/dev/video10
This virtual camera does not persist after reboot, so you will need to run the modprobe command each time you want to use it. Or, you can add the following setting to the config:
sudo nano /etc/modprobe.d/v4l2loopback.conf
Add the following line to the file:
options v4l2loopback video_nr=10 card_label="GameBoyCamera" exclusive_caps=1
Stream Camera Feed to Virtual Device
Keep the terminal running, use ffmpeg to take the high-res feed from the Camera v3, crop/resize it, and feed it into the virtual device.
rpicam-vid -t 0 --width 640 --height 480 --inline --nopreview --codec yuv420 -o - | ffmpeg -f rawvideo -pixel_format yuv420p -video_size 640x480 -i - -c:v copy -f v4l2 /dev/video10
This will adjust resolution to 160:144 (Game Boy screen size) for best results in mGBA. You might want to save this command in a script for easier use.
mGBA Configuration
Open mGBA and go to the Menu -> Tools -> Settings. On the left sidebar, select “Game Boy”.
Change the Game Boy Camera settings to “Qt Multimedia”, then hit OK. Open this section again, and you should be able select the virtual device ‘GameBoyCamera’.
Start your favioute GBA game and open the camera app in the game. You should see the feed from your physical camera in the emulator, allowing you to capture images.