Skip to content

Instantly share code, notes, and snippets.

@SgtPooki
Last active March 26, 2022 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SgtPooki/cbd960145031c50d7a2a9cad0c146304 to your computer and use it in GitHub Desktop.
Save SgtPooki/cbd960145031c50d7a2a9cad0c146304 to your computer and use it in GitHub Desktop.
Comma.ai video+log downloading via sftp via the command line
#!/usr/bin/env bash
COMMA_AI_IP="192.168.1.11"
function comma-download {
local REMOTE_DIRECTORY="/data/media/0/realdata/$1" && shift
local LOCAL_DIRECTORY="${1:-}"
if [ -n "$LOCAL_DIRECTORY" ]; then
mkdir -p $LOCAL_DIRECTORY
fi
if comma-check-for-directory "$REMOTE_DIRECTORY"; then
sftp comma@$COMMA_AI_IP <<< "get -afR ${REMOTE_DIRECTORY} $LOCAL_DIRECTORY"
else
echo "Could not find '$REMOTE_DIRECTORY' on your comma device"
fi
}
function comma-check-for-directory {
local REMOTE_DIRECTORY="$1" && shift
sftp comma@$COMMA_AI_IP 2>&1 <<< "ls -la $REMOTE_DIRECTORY" | grep -v '^sftp>\|^Connected' | grep -Esv '^Can.t ls:.*not found.*$' 2>&1 >/dev/null
}
@SgtPooki
Copy link
Author

SgtPooki commented Mar 26, 2022

How-to

Prerequisites:

  1. You can sftp into your comma using something like sftp comma@$MY_COMMA_IP

Getting started

  1. Change the COMMA_AI_IP variable in the script to the IP address for your comma.ai device.
  2. Source the functions into your shell
    • Copy and paste, . filename.sh, etc..
  3. Run the command with the second half of route_name for the route you want to download as the first argument and the local directory where you want to save the files as the second argument.

Example:

comma-download "2022-03-22--18-50-33*" ~/Downloads/2022-03-22--18-50-33

@SgtPooki
Copy link
Author

And then to overlay the driver camera on the driving video.. something like this:

cat /Users/sgtpooki/Downloads/2022-03-22--18-50-33/*/ecamera.hevc > /Users/sgtpooki/Downloads/2022-03-22--18-50-33/ecamera-all.hevc
cat /Users/sgtpooki/Downloads/2022-03-22--18-50-33/*/dcamera.hevc > /Users/sgtpooki/Downloads/2022-03-22--18-50-33/dcamera-all.hevc
cat /Users/sgtpooki/Downloads/2022-03-22--18-50-33/*/fcamera.hevc > /Users/sgtpooki/Downloads/2022-03-22--18-50-33/fcamera-all.hevc

ffmpeg -r 20 -i /Users/sgtpooki/Downloads/2022-03-22--18-50-33/ecamera-all.hevc -c copy /Users/sgtpooki/Downloads/2022-03-22--18-50-33/ecamera-all.mp4
ffmpeg -r 20 -i /Users/sgtpooki/Downloads/2022-03-22--18-50-33/dcamera-all.hevc -c copy /Users/sgtpooki/Downloads/2022-03-22--18-50-33/dcamera-all.mp4
ffmpeg -r 20 -i /Users/sgtpooki/Downloads/2022-03-22--18-50-33/fcamera-all.hevc -c copy /Users/sgtpooki/Downloads/2022-03-22--18-50-33/fcamera-all.mp4

cd /Users/sgtpooki/Downloads/2022-03-22--18-50-33

ffmpeg -r 20 -thread_queue_size 64 -i ecamera-all.mp4 -vf 'movie=dcamera-all.mp4, scale=300:-1[inner];[in][inner]overlay=main_w-(overlay_w+10):main_h-(overlay_h+10) [out]' combined.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment