Want to run a bash script start.sh with one command that executes tmux and ffmpeg at startup on my Raspberry Pi 4B.

The RPi OS loads the Desktop, but to interact with the process only need a terminal (SSH).

/usr/bin/ffmpeg -f pulse -i 0 -acodec: libmp3lame out.mp3

The script can run after the user pi logs in and everything else has loaded. The idea is for the RPi to continue working after a power outage.

Which autostart method is the most appropriate and could you provide fail-safe instructions for the newest RPi OS with Desktop?

  1. Edit ~./bashrc (no GUI)
  2. Edit /home/pi/.config/lxsession/LXDE-pi/autostart
  3. systemd
  4. Edit /etc/xdg/lxsession/LXDE-pi/autostart
  5. Place .desktop file in /home/pi/.config/autostart
  • 1
    Quick elimination: #1 is NOT an "autostart method" in the sense of "at boot". It unfortunately has proliferated amongst Pi users for some reason (the blind leading the blind type meme). It's for the bash shell, and this is probably NOT something you want to happen everytime you start a shell (something which is actually not guaranteed to happen at boot, either). WRT #2 or #3, I'd say if it doesn't require a GUI #3 is a much better option in terms of configurability, tweaking, monitoring and such. It has a slightly harder learning curve, but it is still fairly simple. – goldilocks Mar 29 at 16:13
  • The issue with #2 is that there are several folders for current user, all users, etc. Not doing that again without reliable instructions. – stocky Mar 29 at 16:21
  • There may be an issue with number #3 playing sound, as background processes generally cannot, unless eg. it is in a GUI context (there should be other ways if this is a problem). – goldilocks Mar 29 at 16:48
  • FFmpeg records from the microphone using PulseAudio. – stocky Mar 29 at 17:49
  • Same potential problem -- a mic, speaker, screen are sort of special devices in that unlike network adapters or storage devices, access to them can't simply be time sliced with normal scheduling. 10 processes can read/write to storage or a network "simulataneously" because each of them running for a dozen ms in a revolving queue works. But it would not work with playing or recording sound, hence accessing that is subject to more restrictions. – goldilocks Mar 29 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.