Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jcayzac/253de1f08d06da64a9e2dcba28c4b034 to your computer and use it in GitHub Desktop.
Save jcayzac/253de1f08d06da64a9e2dcba28c4b034 to your computer and use it in GitHub Desktop.
Photo and video command-line editing

Photo and video command-line editing

Dependencies

All the scripts assume Bash 4.4+

brew install bash exiftool trash
brew install ffmpeg --with-fdk-aac --with-webp
brew install mozjpeg --with-libpng

Aliases

alias ffm='ffmpeg -hide_banner -nostats -loglevel panic'
alias exif='exiftool -q -s'
# Example
ffm -i video.mov -map_metadata 0 -map 0 -c:v copy -c:a copy -c:s copy -c:d copy -c:t copy -f mp4 video.mp4
# Convert one file
# $1: video.mov
convert-mov-to-mp4() {
(
set -e -u -o pipefail
! [[ "$1" =~ ^(.+)\.[mM][oO][vV]$ ]] || {
local D="${BASH_REMATCH[1]}.mp4" T="${BASH_REMATCH[1]}.tmp.mp4"
ffm -i "$1" -map_metadata 0 -map 0 -c:v copy -c:a copy -c:s copy -c:d copy -c:t copy -f mp4 "$T"
mv -f "$T" "$D"
rm -f "$1"
}
)
}
# Convert many files
# $@: paths
convert-many-mov-to-mp4() {
(
set -e -u -o pipefail
export -f convert-mov-to-mp4
xargs -0 -P $(sysctl -n hw.ncpu) -I {} bash -c 'convert-mov-to-mp4 "$@"' _ {} < <(find ${1+"$@"} -iname \*.mov -print0)
)
}
foo() (
set -u -o pipefail -x
E='exiftool -m -r -P -progress -overwrite_original -api QuickTimeUTC'
$E -if '$CreateDate' -if 'not $DateTimeOriginal' '-CreateDate>DateTimeOriginal' ${1+"$@"}
$E -if '$DateTimeOriginal' -if 'not $CreateDate' '-DateTimeOriginal>CreateDate' ${1+"$@"}
$E -if 'not $CreateDate' '-FileModifyDate>CreateDate' ${1+"$@"}
$E -if '$CreateDate' '-FileModifyDate<CreateDate' '-FileName<${CreateDate}${model;s/^/ /}.%e' -d '%Y%m%dT%H%M%S%z.%%.5c' ${1+"$@"}
)
exif -rotation=90 image.jpg
exif -rotation=90 video.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment