Raspberry Pi tricks and tips
Memory & CPU
Disable services you probably don't need, wpa_supplicant, triggerhappy and avahi
Especially on the older models with limited amount of memory available, disabling unnecessary services can free up a bit of that precious memory. For example if you don't have wireless hardware installed, running wpa_supplicant is a waste of resources. Also avahi is quite useless and so is the triggerhappy hotkey daemon (especially if you are running headless!).
Stop the services with:
systemctl stop wpa_supplicant avahi-daemon triggerhappy
And disable them so they don't start up
systemctl disablep wpa_supplicant avahi-daemon triggerhappy
Adjust CPU/GPU memory split
If you are using your system without X11 or don't have a camera plugged in, the memory set aside for the GPU is pretty much all just wasted. On the low memory models this can make a world of difference as the default is to set aside 64MB for the GPU. And on the low memory models (256MB/512MB) wasting 64MB is quite a lot. You can adjust the memory set aside for the GPU in /boot/config.txt, the values can be 16/32/64/128/256
For a CLI console system without GUI/X11 and no camera, set
Unfortunately, even if running otherwise headless, with camera the GPU needs at least 64MB of memory for still image capture and 128MB for video capture, so adjust accordingly. So if you know that you only make still capture you can save 64MB!
The memory split is setup at boot so remember to reboot after changing the settting. You can verify the amount of memory used for the GPU by running vcgencmd:
vcgencmd get_mem gpu
Hardware h264 video capture with gstreamer
Sure, you can always use raspivid to capture h264 video, but with gstreamer it is possible to save in various other container formats or for example stream over the network, depending on your needs.
Capture h264 Full HD, 1920x1080 video save in matroska container:
gst-launch-1.0 -e v4l2src ! video/x-h264,framerate=30/1,width=1920,height=1080 ! queue ! h264parse ! matroskamux ! filesink location=capture.mkv
Use your Raspberry Pi as video input to OBS
First, install GStreamer OBS pluging on your streaming computer.
Add a "GStreamer source" to your Scene with the following pipeline:
udpsrc ! application/x-rtp,payload=127 ! rtph264depay ! decodebin ! video/x-raw,width=1920,height=1080 ! videoscale ! video.
On the Raspberry Pi start the h264 streaming pipeline:
gst-launch-1.0 -e v4l2src ! video/x-h264,framerate=30/1,width=1920,height=1080 ! queue ! h264parse config-interval=1 ! rtph264pay ! queue ! udpsink host=IP-OF-YOUR-OBS-HOST
You can even stream and make a backup recording at the same time on your Pi. In that case try this pipeline:
gst-launch-1.0 -e v4l2src ! video/x-h264,framerate=25/1,width=1920,height=1080 ! queue ! h264parse config-interval=1 ! tee name=t ! queue ! rtph264pay ! udpsink host=IP-OF-YOUR-OBS-HOST t. ! queue ! matroskamux ! filesink location=backupcopy.mkv