Gotcha. I wasn’t quite following what you meant about the camera id assignment issue but now I understand. When I hardcode the camera ID it works. For me, it’s writing:
12-08-21.avi.aac
I wonder if there’s an issue with the .avi and .aac file extensions causing the merge to fail?
This has been informative! I am trying to learn all this as I go, for my information, what do the variables %t, %f, '%$'? (Probably a dumb question I know). I have copied the new script by @Daniel_Duarte and put the file in /data/motioneye/ in the actual MotionEye add-on container in HASSIO and I have tried the suggestions above, but no audio. I am sure I should be able to figure it out, just need a little push!
yup so this is what i have :
on_movie_start /data/motioneye/motioneye-audio.sh start %t %f ‘%$’
try entering some of the variables manually - so for instead %t enter the actual camera id assigned in motion eye - it seems the variable setting seems to be a bit buggy in that i believe it doesnt take from the same value you see in motion eye front end…
if you arent seeing the AAC file the start script portion is where you want to look - check the motioneye log file and it should be generating some pid file in /tmp/
Thanks for the response! The log shows ignoring start event…is that weird? I don’t see any errors so am stumped. Tried replacing %t with the CamID which is 1…and just curious, what do the other 2 variables stand for (%f ‘%$’)?
2020-12-22T02:14:54.076745000Z DEBUG: ignoring start event for camera with id 1 and motion detection disabled,
2020-12-22T02:14:54.077214000Z DEBUG: 200 POST /_relay_event/?_username=admin&event=start&motion_camera_id=1&_signature=1287370d05023c55b8f0c0edf2fce3cf95209b8b (127.0.0.1) 1.57ms,
2020-12-22T02:14:54.103648000Z DEBUG: received relayed event stop for motion camera id 1 (camera id 1)
I’ll keep doing some digging and working with trial and error!
So yes and no. I have noticed it will do it for a couple and then stop. I figured it was because I was doing some config work and needing to restart HA. It seems when I restart HA it stops, but then if I actually use Restart on the MotionEye add-on it will start merging again, but I haven’t paid super close attention. Now that I am done doing my config changes I will let it sit and see what happens.
To hopefully outline things for people who find this down the road. These are the steps I followed to get it working for me. YMMV. I provide no guarantee. IMPORTANT: You will need to get into the back-end container for the add-ons in Docker this can completely mess up your HA install, MAKE A BACKUP, ideally of your entire VM and of course you do this at your own risk!
My setup:
On most recent version of HomeAssistant as of this post (running on a VirtualBox VM)
Using the MotionEye add-on in the Supervisor section
I use continuous recording with 900 second movies
Store my video/stills on a Synology NAS using Movie Passthrough
Configure your camera per the MotionEye instructions and ensure you can see your feed, that your recordings save where you set them to and all that good stuff and ensure it’s working reliably (this setup is outside the scope of these instructions and well documented elsewhere anyway)
Install and setup the Portainer add-on in Supervisor and disable ‘Protection Mode’, START the add-on and then open the WEB UI.
In the Portainer left side menu, select ‘Settings’ and scroll down to ‘Hidden Containers’
Type in apk add nano (I prefer using it for text editing, but use what you want I am in no way a professional)
Type in cd /data/motioneye/ and press ENTER
Type nano motioneye-audio.sh and press ENTER; this will create a new file and open the nano editor
Copy the script from @Daniel_Duarte above and then right click and paste it into the console. Ensure things match up, particularly the beginning and end, should be 41 lines
Press CTRL + X, then press Y and then press ENTER
Type chmod +x motioneye-audio.sh and press ENTER
12a. To ensure things saved you can type nano motioneye-audio.sh to open the file again and ensure the script was saved, if it’s all there, then press CTRL + X to close the nano editor
Type exit and press ENTER; you can then close that window and enable “Protection Mode” for the Portainer add-on; and/or stop it if you want
Go back into the settings for your camera in MotionEye
Under ‘Video Device’ in the ‘Extra Motion Options’ type or copy/paste: on_movie_start /data/motioneye/motioneye-audio.sh start 1 %f
15a. The original instruction says to use %t %f '%$', (place holders for: Camera ID, File Path and Camera Name, respectively) but apparently there is a bug that causes issues with the camera name vs. ID, so instead of %t I put the actual ID of the camera at the suggestion of @Daniel_Duarte. Camera ID can be found under Video Device. Obviously, if you add more cameras substitute that camera’s ID.
Under File Storage turn “Run a Command” on and type or copy/paste: /data/motioneye/motioneye-audio.sh stop 1 %f
into the box. (Again, adjust for your actual camera ID)
Click “Apply” at the top and I would recommend restarting the MotionEye add-on under Supervisor.
When everything starts up after a few seconds, if you look at your storage location, you should see 3 files: The MP4, the ACC and a Thumb file
As mentioned above, if you don’t see the ACC file but you see the others created, then you need to check your steps or maybe try some other options. I found it easier to set my Movie length to 30 seconds while testing things out and once I was happy and now have it set to 900 second movies.
Also as mentioned above, the merging of the ACC file can be a little hit or miss, but I haven’t had time to really test this to find any consistencies with what causes it to and not to merge.
Hopefully this helps someone in the future as I know there is really good info on this page as well as a few other places but it’s all fragmented and I like to consolidate things together! Let me know of changes/updates!
So I have been letting it run at 15 minute movies. I’d say it merges successfully about 80% of the time. Just seems to be random. I’m going to let it run tonight and check tomorrow, then maybe try some different settings.
I just wanted to let everyone know… I am no longer using this script with MotionEye.
I revisited a software that came out a while back (AgentDVR) and it has made some great improvements - and it has now become my daily driver. It supports audio, MQTT, Deekstack.AI for object detection, and overall I am very happy with it.
So, I switched over and no longer use MotionEye.
I am happy others have been able to get this script working, and will leave the repo up - but I likely won’t be making any future code changes. Feel free to fork it and post it here if you want to maintain it.
Yes, I am (although maybe not for much longer) using the free version of Agent DVR.
I see nothing I need the paid version for… ONVIF from cameras to Agent, local DeepStack container for object detection, and for Alerts I set up a connection to the MQTT broker and use Node-Red to automate on Alert MQTT messages. Worked very well.
The DEV has been very responsive on the ISkyConnect Reddit thread… he made multiple bug fixes and improvements I requested.
I pasted the script and it produces an .mp4 file with audio. However, the sound is recorded offset to the video or a few seconds are missing at the beginning so that the sound is not synchronous. Does anyone have the same problem and can help?
Thanks for your script. I added the configuration and the shell file, but the wav file is not generated at all. I’m running motioneye as native service under Linux Mint installation.