Adding Audio to MotionEye Recordings

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!

Added:
Device: on_movie_start /data/motioneye/motioneye-audio.sh start %t %f
Storage: /data/motioneye/motioneye-audio.sh stop %t %f

Storage is going to my NAS successfully just no audio.

Any additional insight would be appreciated!

Hey

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/

  • good luck! -

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!

EDIT: Found the variables in the MotionEye site

Success! I’m an idiot and when I copied your new script from above I didn’t commit/save it right so it still had the original. Thanks for the insight!

is the .aac merging with the video file successfully? wasn’t sure if that got resolved or not.

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.

keep me posted. that’s the last step of my configuration that I haven’t been able to get to work.

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
  • Using a Eufy 2k Indoor Camera
  • Used script from above: Adding Audio to MotionEye Recordings (thanks to @Daniel_Duarte!)

Instructions:

  1. Install and Setup MotionEye Add-on in Supervisor
  2. 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)
  3. Install and setup the Portainer add-on in Supervisor and disable ‘Protection Mode’, START the add-on and then open the WEB UI.
  4. In the Portainer left side menu, select ‘Settings’ and scroll down to ‘Hidden Containers’
  5. Remove the ‘add-on’ filter and click on ‘Containers’ in the Portainer side menu
  6. Find the MotionEye container and select the the ‘console’ button and then click ‘Connect’
  7. Type in apk add nano (I prefer using it for text editing, but use what you want I am in no way a professional)
  8. Type in cd /data/motioneye/ and press ENTER
  9. Type nano motioneye-audio.sh and press ENTER; this will create a new file and open the nano editor
  10. 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
  11. Press CTRL + X, then press Y and then press ENTER
  12. 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
  13. 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
  14. Go back into the settings for your camera in MotionEye
  15. 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.
  16. 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)
  17. 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
image

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!

2 Likes

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.

1 Like

Unfortunately the reliability of this isn’t there. I see the audio file created in the folder, but for some reason it doesn’t merge.

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.

Good Luck and Enjoy!
Cheers!
DeadEnd

I want to thank you for your work on this and the help you’ve given me to help me set it up!

Are you using the free version of AgentDVR that supports those features?

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.

Cheers!
DeadEnd

Hi.

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?

Guys, tell me where should I put the plugin if I have a homeassistant generic x86-64?
I simply do not have the /etc/motioneye/ and /data/etc/ folders.

Ребята, подскажите куда мне положить плагин если у меня homeassistant generik x86-64?
Папок /etc/motioneye/ и /data/etc/ у меня просто нет.

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.

Any idea?

I fixed it changing those 2 lines:

camera_id="$(python3 -c 'import motioneye.motionctl; print(motioneye.motionctl.motion_camera_id_to_camera_id('${motion_thread_id}'))')"
ffmpeg -rtsp_transport tcp -y -i "${full_stream}" -c:a aac -map 0:a:0 "${file_path}.aac" 2>&1 1>/dev/null &

Someone can help with homeassistant and motioneye addons? I tried but without any success.

@StefanoGiu @TokarevSergey @Pegboy @smoysauce