ffmpeg not playing sound correctly

truckerDave

Active Member
Joined
Oct 7, 2023
Messages
242
Reaction score
225
Credits
2,055
The setup .... Linux Mint Virginia fresh install with Zoneminder (security camera program)

For my front door cam, I have created a simple bash script
Code:
#!/bin/bash
        inotifywait -m -r /var/cache/zoneminder/events/ -e create -e moved_to |
            while read -r directory action file; do
                if [[ "$file" =~ snapshot.jpg$ ]]; then 
                    ffplay -nodisp -hide_banner -autoexit usr/doorbell.wav
                fi
            done
which monitors the directory for the snapshot.jpg being added any time there is motion detected. Which does what it was intended.

Then I created a service ...
Code:
[Unit]
Description=My Test Bash Script
After=zoneminder.service
[Service]
Type=simple
ExecStart=/usr/doorbell.sh
[Install]
WantedBy=multi-user.target
to run the bash at startup.

The issue I am having is I can run ffplay -nodisp -hide_banner -autoexit usr/doorbell.wav in the terminal and the sound file plays perfectly. However, when triggered through the service/bash, it just plays a quiet short tone.

Is this a permissions issue? I've tried changing the files from dave to root.

I've, also, tried using an mp3. Both the wav and mp3 play fine from terminal. And I tried adding a sleep 5 to the bash thinking maybe it was exiting prior to the sound file fully playing.

Any ideas?????

Maybe a better way than ffmpeg to play an audio file for my purpose????
 


I would recommend adding some logging statements to your bash script to get a better understanding of what's happening when the script is triggered by the service. Specifically, you can log the output of ffplay -nodisp -hide_banner -autoexit usr/doorbell.wav and check if there are any error messages or warnings.

I tried scripting an audible login/logoff audio bit some time ago and ran into a similar issue but don't recall the solution.

Anyway, for example.

#!/bin/bash
inotifywait -m -r /var/cache/zoneminder/events/ -e create -e moved_to | while read -r directory action file; do
if [[ "$file" =~ snapshot.jpg$ ]]; then
echo "Playing doorbell sound..."
ffplay -nodisp -hide_banner -autoexit usr/doorbell.wav 2>&1 | tee -a /var/log/doorbell.log
fi
done

Script untested ofc, check for syntax errors; I haven't done much bash lately.
 
@truckerDave :-

Our Puppy Forum Admin, rockedge, is also a ZoneMinder afficionado. He's been using it for years. However, even he admits it takes a certain mindset to get the thing up-and-running correctly...

Have you explored any of the alternatives? One I often recommend in such a case is Xeoma, from an outfit called FelenaSoft:-

https://felenasoft.com/xeoma/en/

It comes as a pair of compiled binaries; one is the application itself, one is the updater. You can run these literally from anywhere, though it makes sense to place them in one of your /bins. Make sure to keep them together in the same place, so the updater can find the app itself to update (overwrite) it with the new binary.

It's simple enough to create a .desktop file to give yourself a Menu entry.

Just an idea; ffmpeg is NOT for the faint of heart.....the options are extensive, the permutations are endless, and if you don't write things "just-so", ffmpeg throws a tantrum & point-blank refuses to come out and play!

Up to you of course.


Mike. ;)
 
Have you explored any of the alternatives? One I often recommend in such a case is Xeoma, from an outfit called FelenaSoft:-
Can't say I have. Downloaded ZM and dove in. I've had it running for a few months now. I just didn't like the display it has. So, I built a page to display the streams the way I want them to be displayed using a fairly large TV. It has enough space that I've also incorporated the current weather, the 5 day forcast and the current radar. I'm also working on it sounding a siren to alert us of a tornado warning for our area. Where I'm at there has been an uptick in the amount of tornados and we have no warning system. Figuring out weather.org APIs was a treat for a non-programmer!
 
I would recommend adding some logging statements to your bash script to get a better understanding of what's happening when the script is triggered by the service
Not sure why I didn't think of that. I've been working on javascripts for my display page and have used console.log() so many times it isn't funny just to "see" what's happening.

Thanks!
 
Not sure why I didn't think of that. I've been working on javascripts for my display page and have used console.log() so many times it isn't funny just to "see" what's happening.

Thanks!

I get it man. It took me a while to make habit of logging things and even still forget most of the time. Only after I've lost about 30% of my hair (I don't have any anymore lol) do I recall that I can create logs lol
 
(I don't have any anymore lol)
I'm right there with ya! The whole change to Linux has helped with the loss of many a follicle that I can't afford to lose. But, I can, with a bunch of research and trial and error, make my computers do what I want them to do. And not what Bill Gates wants them to do.
 
I'm right there with ya! The whole change to Linux has helped with the loss of many a follicle that I can't afford to lose. But, I can, with a bunch of research and trial and error, make my computers do what I want them to do. And not what Bill Gates wants them to do.
Amen to that. I'm by no means an educated expert. But I'm glad to help with anything system side. I'm currently smashing my face against my keyboard trying to comprehend the networking side of hosting services off a server machine. Its something that appears to be so simple yet for the life of me I can't seem to make it work.

I suppose there's always the toupee!
 
@truckerDave , perhaps try:
Code:
ExecStart=/bin/bash -c /usr/doorbell.sh
That got the sound to play correctly! Thank you!

Now I just have to figure out how to get it to go to the correct speakers as it's coming from the "Speakers Built-in Audio" that this old Dell has in it. I need it to go to the HDMI Audio.
 
I think the issue I was having (since it reared it's ugly head again) is that playing the sound from bash causes whichever player I tried to clip the beginning of the sound file. I ended up adding 0.5 seconds of silence to the beginning of the wav file and switched to the following script to get the sound sent to the proper speakers.
Code:
#!/bin/bash
    inotifywait -m -r /var/cache/zoneminder/events/ -e create -e moved_to |
        while read -r directory action file; do
            if [[ "$file" =~ snapshot.jpg$ ]]; then
                aplay -D plughw:CARD=AUDIO,DEV=0 usr/doorbell.wav
                sleep 5
            fi
        done
It works like I need it to. Although, I could probably do away with the "sleep 5".
 
Last edited:

Members online


Top