Skip to content

Instantly share code, notes, and snippets.

@Torstein-Eide
Last active November 9, 2019 13:11
Show Gist options
  • Save Torstein-Eide/d82fa3767157fb4ccbf984a4a437fd5b to your computer and use it in GitHub Desktop.
Save Torstein-Eide/d82fa3767157fb4ccbf984a4a437fd5b to your computer and use it in GitHub Desktop.
SP=$PWD
for A in `ls -d $PWD/*`; do
cd $A
rename-video.sh
done
cd $SP
##Example: kamera.11-05-07_12-45.00.avi
# How to split one string into multiple variables in bash shell.
pat='(.*)[\._-]([0-9]{4})[\._-]([0-9]{2})[\._-]([0-9]{2})[\._-]([0-9]{2})[\._-]([0-9]{2})[\._-]([0-9]{2})[\._-](avi)'
for a in `ls`; do
#statements
if [[ "$a" =~ $pat ]]; then
NAVN=${BASH_REMATCH[1]}
YEAR=${BASH_REMATCH[2]}
MANE=${BASH_REMATCH[3]}
DAG=${BASH_REMATCH[4]}
TIME=${BASH_REMATCH[5]}
MINUTT=${BASH_REMATCH[6]}
SEKUND=${BASH_REMATCH[7]}
FORMAT=${BASH_REMATCH[8]}
mv -v $a ${YEAR}-${MANE}-${DAG}_${TIME}-${MINUTT}-${SEKUND}.${FORMAT}
#statements
fi
done
##"title"
##"author"
##"album_artist"
##"album"
##"grouping"
##"composer"
##"year"
##"track"
##"comment"
##"genre"
##"copyright"
##"description"
##"synopsis"
##"show"
##"episode_id"
##"network"
##"lyrics"
# https://wiki.multimedia.cx/index.php/FFmpeg_Metadata
find /home/user/videos-to-process/ -type f -iname '*.mp4' \
-exec ffmpeg \
-i "{}" \
-codec copy \
-metadata artist="John Smith" \
-metadata album="Foo Bar" \
"{}.new.mp4" \; \
-exec mv \
"{}.new.mp4" "{}" \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment