Skip to content

Instantly share code, notes, and snippets.

@xianlin
Last active November 13, 2023 13:12
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 xianlin/7f3907404d221f1e45d16c3a1f13ad96 to your computer and use it in GitHub Desktop.
Save xianlin/7f3907404d221f1e45d16c3a1f13ad96 to your computer and use it in GitHub Desktop.
Rename photo file names according to the photo taken date and time
#!/bin/bash
rename_file() {
j=`jhead "$1" | grep "Date/Time" | sed 's/Date\/Time[ ]*: /IMG_/' | \
sed 's/://1' | sed 's/://1' | sed 's/\ /\_/1' | sed 's/://g'`.jpg
echo "Renaming ""$1"" to ""$j"
#mv -i "$1" "$j"
mv --backup=numbered "$1" "$j"
}
for f in IMG_*.jpg; do
if [[ "$f" =~ IMG_[0-9]{4}(-[0-9])*.(jpg|JPG)$ ]]; then
rename_file "$f"
# elif [[ "$f" =~ "$REGEX_F" ]]; then
# echo "$f file name match 'IMG_YYYYMMDD_HHMMSS_N.jpg', skip renaming"
else
echo "$f file name not match 'IMG_XXXX.jpg', skip renaming."
fi
done
echo ""
echo "####################################################"
echo "rename backup file when duplicated timestamp occures"
echo "####################################################"
echo ""
# 20201021_153518_2.jpg
REGEX_F="^IMG_[0-9]{4}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])_[0-2][0-9][0-5][0-9][0-5][0-9].jpg.~[0-9]+~"
for f in *; do
if [[ "$f" =~ $REGEX_F ]]; then
base_n=`echo $f | cut -d'.' -f1`
n=`echo $f | cut -d'~' -f2`
echo "mv $f to $base_n"_"$n".jpg""
mv -i $f $base_n"_"$n".jpg"
fi
done
#!/usr/bin/env bash
#
# Check the orientation of the video file.
for file in $1*.mp4; do
video_info=$(mediainfo --Inform="Video; %Format% %Width%x%Height% %Codec/String% %FrameRate/String% %Rotation/String%\"" "$file")
audio_info=$(mediainfo --Inform="Audio; %Format%\"" "$file")
echo "$file: $video_info $audio_info"
done
#!/usr/bin/env bash
#
# merge all videos files into one file without decoding.
echo "merging all videos ..."
echo "" >concat.txt
ls $1*.mp4 | awk '{ printf "file '\''%s'\''\n", $1}' > concat.txt
ffmpeg -f concat -safe 0 -i concat.txt -c copy output.mp4
rm -f concat.txt
#!/usr/bin/env bash
#
# merge all videos files into one file without decoding.
echo "merging all videos ..."
echo "" >concat.txt
ls $1*.MP4 | awk '{ printf "file '\''%s'\''\n", $1}' > concat.txt
ffmpeg -f concat -safe 0 -i concat.txt -c:v copy -c:a libmp3lame output.mp4
rm -f concat.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment