Okay, so everyone - I’m a novice at best… I’ll do my best to fix issues that are found (PR always welcome!), but this is my first time trying to maintain anything… even if it is just a single script.
Here is the first (what I hope is) working draft of a script to add audio to MotionEye recordings. It has only been tested on continuous recording. It has not been tested on PI either… so feel free to give feedback. Basic instructions are in the repo.
I think this is something that has been highly requested for MotionEye, and although I know its a bit of a hack… if it works, it works .
Great work! A request for the future might be to make it, so it works with a default docker version of motioneye. Don’t know if that would be possible.
thank you for this. So i’m running motioneye on docker.
saved the script to the config file which is mapped to /etc/motioneye
added the options.
It’s saving on motion normally
downloaded the mp4, but no sound.
no error in the docker logs.
anything else to check?
thank you again
@frits1980 I am running motioneye in Docker and using this script. It should work.
I’m not sure if there is something else I am missing though…
@juan11perez check the folder where the MP4’s are at. You should see one WAV file of the current recording being generated. If you don’t see that, then the audio recording didn’t start.
Some things to check… the script expects there to be camera-#.conf in the config folder (default is /etc/motioneye). I think older systems might have used thread-#.conf instead… if you have thread files instead of camera files that would be a problem.
Otherwise, check your camera-#.conf file and make sure these variables are there:
netcam_url
netcam_userpass
and of course this all assumes your camera has audio on the stream .
After all that, you might need to use ffprobe to check the stream and see what it contains…
That should give you a good start though.
thank you very much for your response and recommendations.
camera labeling is correct and variables are in the conf files. all seems ok there
Looking at the script i thought the sound file was created in the tmp dir and then merged with the video file and subsequently deleted when the video recording stops.
I looked in the docker tmp file and I did find these files, which I thought were deleted after merging.
so I downloaded one of this files “motion-audio-ffmpeg-camera-4” and it seems to be a txt file.
I opened it and all it had was this:
1414
Yes, that is a temp file with PID of the audio recording.
The audio file should be in the same folder as the MP4 video files.
If you are using the default save locations I believe it is /var/lib/motioneye/Camera#/date/.....
And yes, it generates the sound file, and then when video stops, it merges the two and then deletes the audio file.
the storage location is correct. it is mapped in the docker to /var/lib/motioneye/Camera4/2020-05-23 in this example.
the sound file is not there as the recording already stopped.
are you running in docker? just thinking i may not have all the dependencies the script needs
Yes running in docker.
Since you saw the PID file, I would say the script is running.
Sounds like the audio stream is not being found possibly.
You might have to attached to the docker container and test some of the commands to see where it is failing.
the url of your camera stream.
This is camera specifc but is something like (this is my Dahua Camera): rtsp://user:[email protected]:554/cam/realmonitor?channel=1&subtype=00
What are the video lengths you are testing?
If they are very short (10-15 seconds) that hasn’t been tested…
60 second segments I did test - also are you doing continuous or on motion?
good day, so i found a problem, maybe specific to me:
had to modify
stream="$(grep ${netcam} ${motion_camera_conf} | sed -e 's/$'{netcam}'.//')"
with stream="$(grep ${netcam} ${motion_camera_conf} | sed -e "s/"${netcam}".//")"
the netcam var needs to be in in double quotes; this now creates the sound file in the corresponding dir. and it sounds fine.
next problem is that the files mp4 and wav are not merging or at least there’s no sound in the final file.
looking at the stop part of the script I understand it must kill and remove the file in the tmp dir ?
but it’s not doing that. The tmp file stays until it’s superseded by the next one
so i presume the recording goes on and cant merge?
Okay, looking into the single vs double quotes… need to read up on shell script to understand if its different than I thought…
For the second issue - I am thinking possible the second part of the script is not being called… Reviewing the instructions, I had a mistake…
Make sure your “run a command” has the correct text - I accidentally added on_movie_end which is actually what the box is for… so it was a duplicate and probably caused it to fail to be called. Repo instructions have been updated - here is the correct line:
Great to hear!
I am reading up on the sed command… I think the way it is written in the script it not ideal. I’ll do some testing (I think there is an extra set of quotes that can/should be removed). I’ll do testing this week and get it straightened out.
Hmm… so just for clarity the audio file will only exist during the video recording… once the video recording is complete, the two will be merged, and the audio file will be removed.
Yesterday I also made some updates to the script. Depending on when you pulled it it will either be a WAV (before update) or an AAC (after update). This change was to prevent codec compatibility issues.
Lastly I added some clarification to the ReadMe file on directories as it can get confusion. This is what your problem is. Let me see if I can clearly explain:
This is the HOST directory accessible from your OS (ubuntu): /home/luiscarlos/dockerdisco2/volumes/MotionEye/etc
This is the CONTAINER directory only accessible from within the MotionEye container: /etc/motioneye
These in reality are the same directory, but accessed from two different systems (this is what the volume map allows). Your host OS (ubuntu) can only see /home/luiscarlos/... it cannot see /etc/motioneye and vice versa, MotionEye can see /etc/motioneye but cannot see /home/luiscarlos...
So you need to fix your start and stop calls to use /etc/motioneye since this is happening inside the container (Steps 3 and 4 in repo). For whatever reason I don’t see the on_movie_start in your camera-1.conf either (step 3 from instructions). Make sure you have this entered.