Skip to content

Instantly share code, notes, and snippets.

@dacr
Created December 15, 2025 17:29
Show Gist options
  • Select an option

  • Save dacr/9a27fa6b92decb8c413bc557ef4e539f to your computer and use it in GitHub Desktop.

Select an option

Save dacr/9a27fa6b92decb8c413bc557ef4e539f to your computer and use it in GitHub Desktop.
Optimize DJI drone videos to reduce file size while maintaining acceptable quality / published by https://github.com/dacr/code-examples-manager #dd1484da-3678-4dd1-8c4a-6706dfd83b88/483b12d17643b0835f7d0d1bf0aed75291389d92
## summary : Optimize DJI drone videos to reduce file size while maintaining acceptable quality
## keywords : bash, ffmpeg, dji, dji-air, dji-air-3s, air, ai3s
## publish : gist
## authors : David Crosson
## license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
## id : dd1484da-3678-4dd1-8c4a-6706dfd83b88
## created-on : 2025-07-07T19:18:17+02:00
## managed-by : https://github.com/dacr/code-examples-manager
## run-with : sh $file
# Optimization parameters:
# -c:v libx264 : Use H.264 video codec
# -crf 28 : Constant Rate Factor (18-28 is good, higher = smaller file, lower = better quality)
# -an : Disable audio (DJI videos have no sound)
# -movflags +faststart : Optimize for web streaming
# Enable case-insensitive globbing
shopt -s nocaseglob
for INPUT in *.mp4; do
# Extract the extension with its original case
EXT="${INPUT##*.}"
# Create output filename by replacing the original extension
OUTPUT=$(basename "$INPUT" ".$EXT")-optimized.mp4
echo "====================================================================="
echo "-- optimizing '$INPUT' to '$OUTPUT'"
echo "---------------------------------------------------------------------"
if [ ! -f "$OUTPUT" ]; then
ffmpeg \
-i "$INPUT" \
-c:v libx264 -crf 28 \
-an \
-movflags +faststart \
"$OUTPUT"
else
echo "Output file '$OUTPUT' already exists, skipping."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment