Last active
September 14, 2023 20:11
-
-
Save jeffcasavant/53f7a1fc1deee17896dfbf856ff6e110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# LGD323 import script | |
# | |
# Takes 1- or 2-channel LGD323 dashcam video from ./input | |
# Renames video following below format and puts it in ./output | |
# If 2-channel: | |
# - horizontally flips rear channel | |
# - combines video horizontally, front channel on left | |
# Depends: basename bc cut ffmpeg | |
# output filename format | |
# YYYYMMDDThhmmss_<moving/parked>_<normal/motion/impact>.avi | |
# input filename format | |
# aaab_cccc_dddddddd_eeeeee_f.avi | |
# aaa -> inf normal | |
# moe motion | |
# evt impact | |
# b -> 0 1-channel | |
# 1 2-channel | |
# cccc -> index | |
# dddddddd -> YYYYMMDD | |
# eeeeee -> hhmmss (24-hour) | |
# f -> I normal | |
# P parking mode | |
source_dir="./input" | |
target_dir="./output" | |
used_dir="./processed" | |
declare -A modes=( ["I"]="moving" | |
["P"]="parked" ) | |
declare -A reasons=( ["inf"]="normal" | |
["moe"]="motion" | |
["evt"]="impact" ) | |
if [[ ! -d $target_dir ]] | |
then | |
mkdir -p $target_dir | |
fi | |
if [[ ! -d $used_dir ]] | |
then | |
mkdir -p $used_dir | |
fi | |
for f in ${source_dir}/*avi | |
do | |
name=`basename -s .avi $f` | |
why=`echo $name | cut -d'_' -f1 | cut -c -3` | |
why=${reasons[$why]} | |
chans=`echo $name | cut -d'_' -f1 | cut -c 4` | |
chans=`echo $chans + 1 | bc` | |
index=`echo $name | cut -d'_' -f2` | |
date=`echo $name | cut -d'_' -f3` | |
time=`echo $name | cut -d'_' -f4` | |
mode=`echo $name | cut -d'_' -f5` | |
mode=${modes[$mode]} | |
echo "Recording $index: $chans-channel at ${date}T$time $mode mode because $why." | |
new_filename="${date}T${time}_${mode}_${why}" | |
echo "New base filename: $new_filename" | |
if [[ $chans -eq "2" ]] | |
then | |
echo "Combining 2-channel video side-by-side" | |
ffmpeg -i $f -c:v libx264 -crf 18 -an -filter_complex "[0:v:1]hflip[rear];[0:v:0][rear]hstack=inputs=2[v]" -map "[v]" -an "${target_dir}/${new_filename}.avi" | |
#echo "Splitting 2-channel video" | |
#ffmpeg -i $f -map 0:0 -an -c copy "${target_dir}/${new_filename}_front.avi" | |
#ffmpeg -i $f -map 0:1 -an -c copy "${target_dir}/${new_filename}_rear.avi" | |
else | |
echo "Copying 1-channel video" | |
cp $f "${target_dir}/${new_filename}.avi" | |
fi | |
mv $f $used_dir | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment