Skip to content

Instantly share code, notes, and snippets.

@radimklaska
Created June 2, 2020 10:27
Show Gist options
  • Save radimklaska/043ec48a805c38ff7ccee0c9513d255e to your computer and use it in GitHub Desktop.
Save radimklaska/043ec48a805c38ff7ccee0c9513d255e to your computer and use it in GitHub Desktop.
#!/bin/bash
# https://stackoverflow.com/questions/9612090/how-TARGET-loop-through-file-names-returned-by-find
echo "============================="
echo "============================="
echo "====== Initial cleanup ======"
echo "============================="
echo "============================="
#echo "Find all zero size *.mov files (failed conversions)"
#find . -type f -name "*.mov" -size 0
#echo "and delete them."
#find . -type f -name "*.mov" -size 0 -delete
# Find failed GoPro conversions
shopt -s globstar
for TARGET in **/*.mov; do # Whitespace-safe and recursive
SOURCE="${TARGET%%.*}.MP4"
if [ -f "${SOURCE}" ]; then
echo ""
echo "============================="
echo "Checking $SOURCE"
SIZE_SOURCE=$(stat -c%s "$SOURCE")
SIZE_TARGET=$(stat -c%s "$TARGET")
echo "SOURCE: $SOURCE ($SIZE_SOURCE)"
echo "TARGET: $TARGET ($SIZE_TARGET)"
if [[ "$SIZE_SOURCE" -gt "$SIZE_TARGET" ]]; then
echo "Failed conversion of $SOURCE detected!"
echo "Removing $TARGET..."
rm -f $TARGET
fi
fi
done
# Find failed Caddx conversions
shopt -s globstar
for TARGET in **/*.mov; do # Whitespace-safe and recursive
SOURCE="${TARGET%%.*}.MOV"
if [ -f "${SOURCE}" ]; then
echo ""
echo "============================="
echo "Checking $SOURCE"
SIZE_SOURCE=$(stat -c%s "$SOURCE")
SIZE_TARGET=$(stat -c%s "$TARGET")
echo "SOURCE: $SOURCE ($SIZE_SOURCE)"
echo "TARGET: $TARGET ($SIZE_TARGET)"
if [[ "$SIZE_SOURCE" -gt "$SIZE_TARGET" ]]; then
echo "Failed conversion of $SOURCE detected!"
echo "Removing $TARGET..."
rm -f $TARGET
fi
fi
done
echo ""
echo "============================="
echo "============================="
echo "====== Initial cleanup ======"
echo "============DONE============="
echo "============================="
echo "============================="
# Find GoPro files and loop
shopt -s globstar
for SOURCE in **/*.MP4; do # Whitespace-safe and recursive
if [ -f "${SOURCE}" ]; then
if [ ! -f "${SOURCE%%.*}.mov" ]; then
echo ""
echo "============================="
echo "Processing GOPRO $SOURCE"
echo "SOURCE: $SOURCE"
echo "TARGET: ${SOURCE%%.*}.mov"
echo "============================="
nice -15 ffmpeg -y -i "$SOURCE" -c:v libxvid -c:v mpeg4 -force_key_frames "expr:gte(t,n_forced*1)" -b:v 250000k -c:a pcm_s16le "${SOURCE%%.*}.mov"
fi
fi
done
# Find Caddx files and loop
shopt -s globstar
for SOURCE in **/CADDX*.MOV; do # Whitespace-safe and recursive
if [ -f "${SOURCE}" ]; then
if [ ! -f "${SOURCE%%.*}.mov" ]; then
echo ""
echo "============================="
echo "Processing CADDX $SOURCE"
echo "SOURCE: $SOURCE"
echo "TARGET: ${SOURCE%%.*}.mov"
echo "============================="
nice -15 ffmpeg -y -i "$SOURCE" -c:v libxvid -c:v mpeg4 -force_key_frames "expr:gte(t,n_forced*1)" -b:v 250000k -c:a pcm_s16le "${SOURCE%%.*}.mov"
fi
fi
done
# Find Caddx files and loop
shopt -s globstar
for SOURCE in **/*.mp3; do # Whitespace-safe and recursive
if [ -f "${SOURCE}" ]; then
if [ ! -f "${SOURCE%%.*}.wav" ]; then
echo ""
echo "==========================="
echo "Processing mp3 $SOURCE"
echo "SOURCE: $SOURCE"
echo "TARGET: ${SOURCE%%.*}.wav"
echo "==========================="
nice -15 ffmpeg -y -i "$SOURCE" "${SOURCE%%.*}.wav"
fi
fi
done
#wait
echo ""
echo "====================================="
echo 'All background processes have exited.'
echo "====================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment