# MacOS Automator Workflow for Dash Cam Script



## atomitod (Nov 7, 2018)

Many thanks to eHendrix23 for the awesome script that merges the multiple dash cam video files into a single file for cohesive playback! If you haven't happened across that yet, find it here.

To compliment that script, I managed to piece together a workflow in the MacOS automator. The workflow automates running the (otherwise installed and functioning) eHendrix23 script on all the directories you select, eliminating the need to manually type and run the script from a terminal window.

*Installation*: Download and decompress/unzip the attached file (just double clicking should unzip it). Double click the unzipped file and you should get a prompt from the Quick Action Installer. Choose Install. The Quick Action Installer will place the workflow in your ~/Library/Services directory. This will make it available as a Quick Action on finder menus (the menu you see when you select one or more directories and use a "secondary click" (usually two finger tap on trackpad or right click of a mouse)).

Note that the automator workflow assumes that both the eHendrix23 tesla_dashcam python script AND the ffmpeg utility are resident in your top level user directory:









If you have the tesla_dashcam script or ffmpeg located somewhere else, that's fine but you'll have to use Automator to modify the workflow's shell script to point to the right places.

*Usage*: With your USB drive or SSD attached to your Mac, select the directories containing saved dash cam footage you want to run the eHendrix23 script on. Use a secondary click/tap and choose "Process Tesla Dash Cam Video" from the context menu:










The Automator workflow will do the following:

The selected directories get copied to the Downloads directory (a good working directory everyone usually has).
Once all selected directories are copied, the eHendrix23 script is invoked on them. One after another.
The eHendrix23 script will produce its output file(s) on the desktop. These will appear one after the other as each directory is processed.
Directories copied to the Downloads directory are removed. These are deleted one after the other as each is processed. Note that these will not appear in the trash can - they get permanently deleted. Files on your thumb drive or SSD attached to the Mac are left intact. You'll have to delete these yourself once satisfied that you've got what you want.
*Additional notes*: The eHendrix23 script allows several different options for merging video from the different cameras. The automator script doesn't give you choices. It's configured to use the fullscreen layout. Its doesn't use any other options (the time stamp is shown at bottom by default). If you want a different configuration, you'll have to use Automator to modify the workflow's shell script to invoke the options you want. Below is the shell script run by the Automator workflow is (f in "[email protected]" refers to each directory in the list supplied as input):

for f in "[email protected]"​do​~/tesla_dashcam --layout FULLSCREEN --ffmpeg ~/ffmpeg --output ~/Desktop/${f##*/} ~/Downloads/${f##*/}​rm -f ~/Downloads/${f##*/}/*​rmdir ~/Downloads/${f##*/}​done​
Depending on the video(s) you're processing, it could take a while to run. You can always tell it's running by a spinning gear icon in the menu bar at the top of the screen (near the clock and WiFi signal strength of those are shown on your system).

I built this intending to process the many sub-directories found under "TeslaCam\SavedClips" on my Dash Cam USB stick. Hopefully this helps some others efficiently look at their similar footage. Sorry its limited to MacOS users only....thats just what I have.


----------



## AB3DC (Apr 2, 2016)

Thanks for the Automator script. I will try this out later today.


----------



## GDN (Oct 30, 2017)

Very nice job - thanks !! I installed and actually duplicated it so that I could add "--speed 10" as an option. I first process the video at speed, if anything happens then I rerun the automator at normal speed to more closely evaluate anything I couldn't see the first time.


----------



## Artdept (Nov 6, 2017)

Damn!! Your like dan the Automator but with cameras! Hell yes!


----------



## SR22pilot (Aug 16, 2018)

atomitod said:


> Note that the automator workflow assumes that both the eHendrix23 tesla_dashcam python script AND the ffmpeg utility are resident in your top level user directory:


Any particular reason you didn't look for the ffmpeg and eHendrix23 script in Applications?

Oh yes, a big "Thank you" for the script.


----------



## MelindaV (Apr 2, 2016)

atomitod said:


> Many thanks to eHendrix23 for the awesome script that merges the multiple dash cam video files into a single file for cohesive playback! If you haven't happened across that yet, find it here.
> 
> To compliment that script, I managed to piece together a workflow in the MacOS automator. The workflow automates running the (otherwise installed and functioning) eHendrix23 script on all the directories you select, eliminating the need to manually type and run the script from a terminal window.
> 
> ...


first, thanks for sharing with everyone 

now, for my issue(s).... I'm sure this is an edge case, but thought I'd mention it. For a reason I can not remember, I have "main" as part of my user profile name, and this seems to muck up what automator is looking for (or the eHendrix23 script). Creating a new test profile, all works perfectly. (maybe that is my cue to clean things up....)

on my "Melinda main" profile, I am getting the following error after it copies the folder from the flash drive to the Downloads folder:

```
tesla_dashcam: error: unrecognized arguments: /Users/melindav main/Downloads/2019-04-12_20-49-11
rm: /Users/melindav: Permission denied
rmdir: /Users/melindav: Not a directory
rmdir: main/Downloads/2019-04-12_20-49-11: No such file or directory”
```
It appears in some areas it is looking for "melindav main", others just "melindav" and one "main".


----------



## GDN (Oct 30, 2017)

This is interesting, will learn from the linux experts here, but I believe you need some quotes around that directory so that it doesn't misinterpret the space between your name and main, but since it is being called in as a system variable not sure how you get the quotes around it. You sure as heck don't want it completing the command rm /users/melindav - that could be a disaster if it existed.


----------



## sduck (Nov 23, 2017)

I think you need to add an "_" or delete that space between melindav and main. That space is going to throw it off. Changing user directory names in mac os x isn't as straightforward as you'd think - see this https://support.apple.com/en-us/HT201548 - but it might be worth it to do so if you want to get this working. User folders aren't supposed to have spaces in them, so it got added somehow after the fact.

And I've got this running now, and it seems to work well! Thanks! And to GDN, if you use quicktime to play back the files, or just about any other player, you can easily speed up the playback by clicking the right facing arrow while playing back - no need to process twice. You get the choices of 2, 5 and 10 times normal.

Warning: it's not a very fast process, can take several minutes to glue everything together. Be patient! Especially if you use it on the recent clips folder, with an hour of driving on it - I typed all of this post while it was doing that. The saved clips sentry mode folders go quicker.


----------



## GDN (Oct 30, 2017)

sduck said:


> And I've got this running now, and it seems to work well! Thanks! And to GDN, if you use quicktime to play back the files, or just about any other player, you can easily speed up the playback by clicking the right facing arrow while playing back - no need to process twice. You get the choices of 2, 5 and 10 times normal.


Big brain fart there - never thought about using the play back controls in Quicktime to process the regular video, wasn't even on my mind. However there is a big advantage of combining the files with "--speed 10" as it truly takes a fraction of the time to combine and process as it takes to combine the full videos at normal speed. Over the years I figure there won't be that many videos I need to really combine at normal speed to see what happened to the car. So combining at speed and watching saves CPU and a lot of time and I get what I need for about 98% of the cases.


----------



## sduck (Nov 23, 2017)

SR22pilot said:


> Any particular reason you didn't look for the ffmpeg and eHendrix23 script in Applications?


It's pretty easy to modify the automator script to point it wherever to look for those files (as mentioned in the first post), if you feel the need to keep things neat (I will most likely do that at some point).


----------



## SR22pilot (Aug 16, 2018)

I am seeing a couple of issues. First, videos are flipped left to right. Just look at names on buildings. The read backwards but don't on the originals. Also, the video on the right side in the output files has issues. Besides getting very pixelated sometimes, it will go totally black. At first I was going to schedule a service appointment and have the camera looked at but so far the original video files seem fine.


----------



## GDN (Oct 30, 2017)

SR22pilot said:


> I am seeing a couple of issues. First, videos are flipped left to right. Just look at names on buildings. The read backwards but don't on the originals. Also, the video on the right side in the output files has issues. Besides getting very pixelated sometimes, it will go totally black. At first I was going to schedule a service appointment and have the camera looked at but so far the original video files seem fine.
> View attachment 24815


The automator does a lot to handle the video file, cleaning up the intermediate files and presenting you with a very cool put together file. However my files that are blank are blank in the original as well. I had no problems for a few days and then pulled the SSD and put it back in and now I'm having problems with video recorded from the right repeater. I figure it is just the version of SW the car is on and will improve with the next release or two.

If you want to flip video and speed it up or present it different you need to edit the automator which is just executing the script written by @ehendrix23. Go to this post to see all of the options and what you can add for making them look like you are looking out the mirror or rear or widescreen, the options are listed here - https://teslaownersonline.com/threads/dashcam-video-script.11481/post-222823

Go to the top of that thread to see some of the different options. To use them with the automator, open the automator and add the options to the execution that meet your needs. I added a speed setting and --rear in what I execute. You can play and make it combine the videos for just how you like them.


----------



## batzman (May 31, 2018)

I missed something somewhere and I am receiving an error.









As I am new to Automator, what am I missing from running the Automator from @atomitod?


----------



## GDN (Oct 30, 2017)

Did you download and install the meat behind the automator? You must have the python and ffmpeg tools from @ehendrix23 installed as well. Go to post 1 of this thread and click on the Link to read through his thread. On page 4 or 5 of his thread you will find the latest download. You'll need that for the automator to work.


----------



## batzman (May 31, 2018)

Ok, got it figured. I was asking to Automator to process two folders... one of which didn't have content (didn't know that). When I selected only one folder, which had content, everything worked fine. Nice set up.  Thank you all.


----------



## batzman (May 31, 2018)

Some items to note for my situation... although everything works... it only works when I select one folder that has content and then it saves the completed .mp4 in the same folder as the original files (on the thumbdrive) and not into the downloads folder. 

If I select more than one folder it doesn't work and errors out as before. 
If I select a folder that is not on my thumbdrive, then I do not have the ability (doesn't show up) to launch the automator

Thoughts?


----------



## garsh (Apr 4, 2016)

SR22pilot said:


> I am seeing a couple of issues. First, videos are flipped left to right. Just look at names on buildings. The read backwards but don't on the originals.


I had assumed that this was being done on-purpose, to simulate a view from a side-view mirror.


----------



## atomitod (Nov 7, 2018)

SR22pilot said:


> Any particular reason you didn't look for the ffmpeg and eHendrix23 script in Applications?
> 
> Oh yes, a big "Thank you" for the script.


No particular reason. Just not where I tend to put those kind of programs.


----------



## atomitod (Nov 7, 2018)

batzman said:


> Some items to note for my situation... although everything works... it only works when I select one folder that has content and then it saves the completed .mp4 in the same folder as the original files (on the thumbdrive) and not into the downloads folder.
> 
> If I select more than one folder it doesn't work and errors out as before.
> If I select a folder that is not on my thumbdrive, then I do not have the ability (doesn't show up) to launch the automator
> ...


@batzman Did you modify the script or Automator workflow when you installed? As initially written, it would only copy directories you selected from their source location to your Downloads directory. The ehendrix23 script would then be executed on the those copied directories in Downloads. The Automator workflow included explicit instruction to the script to put the final video on the Desktop. I know the current ehendrix23 script functionality also now puts temporary files in the output directory (Desktop) that get cleaned up after execution. I don't know of any reason the final video would end up anywhere other than the Desktop though, unless the Automator workflow's shell commands were changed. Same for any writing to your Thumb drive. That shouldn't be happening unless the Automator workflow or its shell commands changed somehow.


----------



## SR22pilot (Aug 16, 2018)

atomitod said:


> No particular reason. Just not where I tend to put those kind of programs.


I prefer to keep my top level directory clean and put executables in Applications but that is me. I haven't played with Automator before. I'll have a look.

I guess the rear view mirror comment made by someone makes some sense.

The blank screen I showed doesn't exist on the original. I'll check more files. I a only checked one. It is rather tedious to find the exact file to look at. It is always the right side image. It is also often noisy. I am doing this on a Macbook with a core i7 although 2 cores are assigned to Parallels. I'll run again and make sure Parallels isn't running.


----------



## SR22pilot (Aug 16, 2018)

What is the difference in the files in SAVED vs. the other files on the USB stick? I thought SAVED might be from Sentry but Saved, while having fewer files, has plenty where I am driving or walking away before putting Sentry on.


----------



## MelindaV (Apr 2, 2016)

"saved" is any time you tap the camera icon on the screen AND all the Sentry recordings. "recent' are the prior hour.


----------



## atomitod (Nov 7, 2018)

SR22pilot said:


> What is the difference in the files in SAVED vs. the other files on the USB stick? I thought SAVED might be from Sentry but Saved, while having fewer files, has plenty where I am driving or walking away before putting Sentry on.


I believe files in the SAVED directory are those associated with either Sentry mode reaching an ALERT/ALARM state or you tapped the Teslacam icon (that indicates it should save Dashcam footage) while driving. The other files in the Teslacam directory (outside of saved) should in theory roll off the drive and be deleted automatically in time. Files in SAVED will not be deleted automatically.


----------



## SR22pilot (Aug 16, 2018)

atomitod said:


> I believe files in the SAVED directory are those associated with either Sentry mode reaching an ALERT/ALARM state or you tapped the Teslacam icon (that indicates it should save Dashcam footage) while driving. The other files in the Teslacam directory (outside of saved) should in theory roll off the drive and be deleted automatically in time. Files in SAVED will not be deleted automatically.


I'll check. I rarely tape to save so I was surprised to see an entire trip to have dinner form parking in the lot and walking away to the drive home. There are definitely fewer files in SAVED. Maybe I am just confused since I can't look at them right now.


----------



## ehendrix23 (Jan 30, 2019)

SR22pilot said:


> I am seeing a couple of issues. First, videos are flipped left to right. Just look at names on buildings. The read backwards but don't on the originals. Also, the video on the right side in the output files has issues. Besides getting very pixelated sometimes, it will go totally black. At first I was going to schedule a service appointment and have the camera looked at but so far the original video files seem fine.
> View attachment 24815


That view is as if looking from the mirror. There are other options available to make it as if you're looking backwards. 

Normally speaking when you see the black for a video it means that the duration from that camera is not the same. Each file is normally 1 minute long, with 3 files / minute (left, front, right). Let's say that for some reason the right camera is only 45 seconds (I have seen this happen on mine). Then what happens is that for that minute it will show the left, front, and right video for 45 seconds and then left and front for the other 15 seconds with the right camera showing black.
Hope this helps.


----------



## SR22pilot (Aug 16, 2018)

ehendrix23 said:


> That view is as if looking from the mirror. There are other options available to make it as if you're looking backwards.
> 
> Normally speaking when you see the black for a video it means that the duration from that camera is not the same. Each file is normally 1 minute long, with 3 files / minute (left, front, right). Let's say that for some reason the right camera is only 45 seconds (I have seen this happen on mine). Then what happens is that for that minute it will show the left, front, and right video for 45 seconds and then left and front for the other 15 seconds with the right camera showing black.
> Hope this helps.


Thanks. That makes sense. It is weird that it is always the same camera that blacks out or I should say has the short video.


----------



## GDN (Oct 30, 2017)

SR22pilot said:


> Thanks. That makes sense. It is weird that it is always the same camera that blacks out or I should say has the short video.


My problems always seem to be the right repeater. I figure this is a software issue. For about a week I had almost perfect video from all cameras. I pulled the drive and cleaned it up and put it back in. The next two days I had a few zero byte (empty) files and some partial files, but they were all from the right repeater !


----------



## ehendrix23 (Jan 30, 2019)

GDN said:


> My problems always seem to be the right repeater. I figure this is a software issue. For about a week I had almost perfect video from all cameras. I pulled the drive and cleaned it up and put it back in. The next two days I had a few zero byte (empty) files and some partial files, but they were all from the right repeater !


If there is corruption in the video or shorter then normally it is the right one for me as well.


----------



## SR22pilot (Aug 16, 2018)

GDN said:


> My problems always seem to be the right repeater. I figure this is a software issue. For about a week I had almost perfect video from all cameras. I pulled the drive and cleaned it up and put it back in. The next two days I had a few zero byte (empty) files and some partial files, but they were all from the right repeater !


Good to know I'm not alone. Misery loving company and all that I guess.


----------



## batzman (May 31, 2018)

atomitod said:


> @batzman Did you modify the script or Automator workflow when you installed? As initially written, it would only copy directories you selected from their source location to your Downloads directory. The ehendrix23 script would then be executed on the those copied directories in Downloads. The Automator workflow included explicit instruction to the script to put the final video on the Desktop. I know the current ehendrix23 script functionality also now puts temporary files in the output directory (Desktop) that get cleaned up after execution. I don't know of any reason the final video would end up anywhere other than the Desktop though, unless the Automator workflow's shell commands were changed. Same for any writing to your Thumb drive. That shouldn't be happening unless the Automator workflow or its shell commands changed somehow.


Nope, I didn't alter any of of the scripts in any way. However I haven't looked at them in detail either.

I'll continue to look into it, although it doesn't bother me at the moment.


----------



## Toadmanor (Jul 23, 2018)

I have tried this, the process seems to run...I receive a process complete message but can not find the resulting files. What are they called and where I they stored?

The original message says on the desktop but i can not find them.

Any helpers?


----------



## sduck (Nov 23, 2017)

The files created from Saved Files are usually stored to the desktop. I've found the ones created from Recent Files are put back into the recent files folder for some reason.


----------



## Toadmanor (Jul 23, 2018)

Well something must be wrong because I receive message that process is complete but can find no output files.


----------



## sduck (Nov 23, 2017)

Have you edited the script in any way? And have all the pieces needed in the correct places? Any oddities in your mac's file structure? Have you looked at the desktop folder in finder?


----------



## Toadmanor (Jul 23, 2018)

sduck said:


> Have you edited the script in any way? And have all the pieces needed in the correct places? Any oddities in your mac's file structure? Have you looked at the desktop folder in finder?


I have not edited the script at all.
I have plaid the downloaded ffmpeg-4.1.3 folder inside the applications folder on my Mac. Tesla_Dashcam is also in the Applications folder.
I have looked in the desktop folder.

Perhaps if someone can tell me the name of an output file i could search for that and see if it exists anywhere.


----------



## sduck (Nov 23, 2017)

An example name is 2019-06-02_18-02-40.mp4.


----------



## RickO2018 (Mar 13, 2018)

atomitod said:


> Many thanks to eHendrix23 for the awesome script that merges the multiple dash cam video files into a single file for cohesive playback! If you haven't happened across that yet, find it here.
> 
> To compliment that script, I managed to piece together a workflow in the MacOS automator. The workflow automates running the (otherwise installed and functioning) eHendrix23 script on all the directories you select, eliminating the need to manually type and run the script from a terminal window.
> 
> ...


Thanks again eHendrix23 for the cam merging script. I used it fairly successfully about a week ago, but my thumb drive didn't have enough storage so I began to use a 64GB drive. This time around the script executed properly and I saw the new movie generate within the destination directory, but when the script finished, the resulting file vanished!

Any thoughts?

Thanks


----------



## sduck (Nov 23, 2017)

The ehendrix script has changed since this workflow was created, it's possible that this workflow needs to be updated. I still have mine set up as per this thread, but I updated the ehendrix script part, and it still works. I did notice that the ehendrix script page now has it's own mac way of running it, which differs from this version.


----------

