TMC is an independent, primarily volunteer organization that relies on ad revenue to cover its operating costs. Please consider whitelisting TMC on your ad blocker and becoming a Supporting Member. For more info: Support TMC

Blackvue 900 dashcam video script

Discussion in 'Technical' started by BigD0g, Jun 3, 2018.

  1. BigD0g

    BigD0g Active Member

    Joined:
    Jan 12, 2017
    Messages:
    1,510
    Location:
    Somewhere
    I installed a pair of BlackVue 900s in my car and wrote a script to download
    the files and store them on my array.

    The script will download all files to a root directory, the date and finally front or rear.

    Note this script is for a quad channel set up aka 2 dual blackvue dash cams. Each
    folder for the given location will have both dash cam channels for that camera.

    So, with my particular setup the front folder will have the front dashcam video and the passenger right video.
    The rear folder will have the rear dash cam and the passenger left video.

    I pieced this together from a few internet sources and mixed and matched between them to improve the solution and allow for better throughput and better storage arragement

    Sources:
    Dashcam file auto download script
    https://www.bjornsblog.nl/tips-and-tricks/download-all-files-from-blackvue-dashcam-to-your-synology-wifi/

    If you have any questions feel free to ask, just offering this back to the community and hope it helps others.

    I have this setup on a cronjob to run every night at 1am and 4am ( in case of broken connections), but the script will not duplicate files, so you can have this run more often if needed, it will also resume downloaded files that haven't finished automatically when run again for the same day in case the dash cam drops the connection which happens occasionally I found.

    Code:
    #!/bin/bash
    
    #################################################################################################
    #   This script is used to download blackvue dashcam files to the specified root storage directory.
    #   No warranty express or implied comes with this script, and improvements or bugs for this script
    #   please let the OP know so all can recieve the fix.
    #
    #    Files will be downloaded to the root directory then the date the file was captured and then a front
    #    and rear folder will be created if dual dashcasm's are installed.
    #
    #    This script ONLY works with blackvue dashcams (tested on 900S, but should work on 600 and later models)
    #
    #    -- BigD0g
    #################################################################################################
    
    #The top level directory of where to store your dashcam files
    DASHCAM_ROOT_STORAGE=~/jarvis-dashcam
    
    #The IP Address of the FRONT blackvue dashcam
    DASHCAM_FRONT_IP=192.168.0.21
    
    #The IP Address of the REAR blackvue dashcam if installed aka 4 channel install 2 seperate blackvues
    DASHCAM_REAR_IP=192.168.0.22
    
    export BVDATE=`date +%Y%m%d`
    echo $BVDATE
    
    function downloadTodaysFiles() {
        
        count=$(ping -c4 $1 | grep 'received' | awk -F',' '{ print $2}' | awk '{ print $1}')
    
        if [ $count -eq 4 ]; then
            echo "Successful connection! for " $1
            cd $DASHCAM_ROOT_STORAGE/$BVDATE/$2
            for file in `curl http://$1/blackvue_vod.cgi | sed 's/^n://' | sed 's/F.mp4//' | sed 's/R.mp4//' | sed 's/,s:1000000//' | sed $'s/\r//' | grep $BVDATE`; do
                wget -c http://$1$file\F.mp4;
                wget -c http://$1$file\R.mp4;
                wget -nc http://$1$file\F.thm;
                wget -nc http://$1$file\R.thm;
                wget -nc http://$1$file.gps;
                wget -nc http://$1$file.3gf;
            done
        fi
        
    }
    
    #Setup directories for todays files
    if [ ! -d "$DASHCAM_ROOT_STORAGE/$BVDATE" ]; then
      mkdir -p $DASHCAM_ROOT_STORAGE/$BVDATE/front
      mkdir $DASHCAM_ROOT_STORAGE/$BVDATE/rear
    fi
    
    #Set this one off into the background so we can do both cameras at the sametime.
    downloadTodaysFiles $DASHCAM_FRONT_IP front &
    
    #If you do not have a second blackvue installed delete this next line
    downloadTodaysFiles $DASHCAM_REAR_IP rear &
    
    exit 0
    
     
    • Helpful x 1
    • Love x 1
  2. kdday

    kdday Member

    Joined:
    Oct 29, 2016
    Messages:
    445
    Location:
    AZ
    Can you comment on the file sizes of your new 4k camera? Also, how long will you keep files on your array?

    Just curious why download them all instead of have the dashcam loop over the oldest recordings when it gets full?
     
  3. BigD0g

    BigD0g Active Member

    Joined:
    Jan 12, 2017
    Messages:
    1,510
    Location:
    Somewhere
    Apologies! found some bugs, new code, and now it's serialized, just use 2 crontab one for each dash cam less error prone.

    Code:
    #!/bin/bash
    
    #################################################################################################
    #   This script is used to download blackvue dashcam files to the specified root storage directory.
    #   No warranty express or implied comes with this script, and improvements or bugs for this script
    #   please let the OP know so all can recieve the fix.
    #
    #   The script will download yesterday and today's files and due to the use of wget will not duplicate
    #   file downloads.
    #
    #   Files will be downloaded to the root directory then the date the file was captured and then a front
    #   and rear folder will be created if dual dashcasm's are installed.
    #
    #   This script ONLY works with blackvue dashcams (tested on 900S, but should work on 600 and later models)
    #
    #    -- BigD0g
    #################################################################################################
    
    #The top level directory of where to store your dashcam files
    DASHCAM_ROOT_STORAGE=/media/shared/tesla/dashcam
    
    #The IP Address of the FRONT blackvue dashcam
    DASHCAM_FRONT_IP=192.168.0.21
    
    #The IP Address of the REAR blackvue dashcam if installed aka 4 channel install 2 seperate blackvues
    DASHCAM_REAR_IP=192.168.0.22
    
    export BVDATE=`date '+%Y%m%d'`
    echo $BVDATE
    
    export YESTERDAYDATE=`date -d "1 day ago" '+%Y%m%d'`
    echo $YESTERDAYDATE
    
    function downloadSpecifiedFileDates() {
    
        #Setup directories for files by date
        if [ ! -d "$DASHCAM_ROOT_STORAGE/$YESTERDAYDATE" ]; then
            mkdir -p $DASHCAM_ROOT_STORAGE/$YESTERDAYDATE/front
            mkdir $DASHCAM_ROOT_STORAGE/$YESTERDAYDATE/rear
        fi
    
        if [ ! -d "$DASHCAM_ROOT_STORAGE/$BVDATE" ]; then
            mkdir -p $DASHCAM_ROOT_STORAGE/$BVDATE/front
            mkdir $DASHCAM_ROOT_STORAGE/$BVDATE/rear
        fi
    
        count=$(ping -c4 $1 | grep 'received' | awk -F',' '{ print $2}' | awk '{ print $1}')
    
        if [ $count -eq 4 ]; then
            echo "Successful connection! for " $1
            for file in `curl http://$1/blackvue_vod.cgi | sed 's/^n://' | sed 's/F.mp4//' | sed 's/R.mp4//' | sed 's/,s:1000000//' | sed $'s/\r//' | grep $2`; do
                wget -P $DASHCAM_ROOT_STORAGE/$2/$3 -c http://$1$file\F.mp4;
                wget -P $DASHCAM_ROOT_STORAGE/$2/$3 -c http://$1$file\R.mp4;
                wget -P $DASHCAM_ROOT_STORAGE/$2/$3 -nc http://$1$file\F.thm;
                wget -P $DASHCAM_ROOT_STORAGE/$2/$3 -nc http://$1$file\R.thm;
    wget -P $DASHCAM_ROOT_STORAGE/$2/$3 -nc http://$1$file.gps;
                wget -P $DASHCAM_ROOT_STORAGE/$2/$3 -nc http://$1$file.3gf;
            done
        fi
    
    }
    
    #Set this one off into the background so we can do both cameras at the sametime.
    downloadSpecifiedFileDates $DASHCAM_FRONT_IP $YESTERDAYDATE front
    downloadSpecifiedFileDates $DASHCAM_FRONT_IP $BVDATE front
    
    #downloadSpecifiedFileDates $DASHCAM_REAR_IP $YESTERDAYDATE rear
    #downloadSpecifiedFileDates $DASHCAN_REAR_IP $BVDATE rear
    
    exit 0
    
     
    • Love x 1
  4. BigD0g

    BigD0g Active Member

    Joined:
    Jan 12, 2017
    Messages:
    1,510
    Location:
    Somewhere
    Roughly 237mb / 3 min segment

    I'm going to keep them for two weeks before the system auto deletes them unless I purposely move them to a save directory.

    I'm definitely letting the dash cam loop over them, but the blackvue cloud doesn't allow you to have a unified view of the dual dash cams without paying there subscription fee, so this allows me to have a central location to review the full 360 view of the car if needed.

    Hopefully, it will never be needed, but it was fun to geek out while folks were napping, hence the silly bugs that have gone unnoticed until I published this.... :D:eek:
     
    • Like x 1
    • Love x 1
  5. johndorian

    johndorian Member

    Joined:
    Mar 25, 2018
    Messages:
    155
    Location:
    GTA
    Thanks for this, just set up on my unRAID server.
     
    • Like x 1

Share This Page

  • About Us

    Formed in 2006, Tesla Motors Club (TMC) was the first independent online Tesla community. Today it remains the largest and most dynamic community of Tesla enthusiasts. Learn more.
  • Do you value your experience at TMC? Consider becoming a Supporting Member of Tesla Motors Club. As a thank you for your contribution, you'll get nearly no ads in the Community and Groups sections. Additional perks are available depending on the level of contribution. Please visit the Account Upgrades page for more details.


    SUPPORT TMC