Motion is a great software for streaming USB webcam, video capture or network camera input to Motion JPEG Video (MJPG). However when using this software on my Raspberry PI to monitor water level on an industrial plant I have found the video to stutter and slow down a lot when there was lots of action happening in the picture or something was moving.
The way Motion works is by capturing snapshots from the camera at every frame per second, and saving them to the working directory defined in the config. By default this directory is in /tmp/motion, however this quickly filled up my Raspberry Pi disk and slowed down the video feed due to the increased disk access times. Motion also fails to delete files from this directory whenever the feed slows down – it can’t keep up!
To resolve this we must move the working directory to a RAM disk, I used a 256MB RAM disk using tmpfs.
1. Open the file /etc/fstab, and add the following line. This can be done using nano, for example “sudo nano /etc/fstab”, paste the following line and press CTRL + X, then Y to save and close.
tmpfs /motion tmpfs defaults,noatime,nosuid,mode=0755,size=256m 0 0
In the end your /etc/fstab file should look something like this:
2. Create the directory to mount this using the following command:
3. Mount this directory from fstab:
mount /motion chown motion:motion /motion/
4. Open the configuration file for motion (nano /etc/motion/motion.conf), find the line target_dir (CTRL + W, target_dir), and change it to the following:
Your file should look something like this:
If needed, save and exit with Nano using CTRL + X, then press Y.
5. You should now be able to restart Motion with the command “service motion restart”, and enjoy faster FPS!