Skip to content

Instantly share code, notes, and snippets.

@vinesmsuic
Created September 6, 2024 05:20
Show Gist options
  • Select an option

  • Save vinesmsuic/4e8a671ef5ca1f6468e723c31f7ec599 to your computer and use it in GitHub Desktop.

Select an option

Save vinesmsuic/4e8a671ef5ca1f6468e723c31f7ec599 to your computer and use it in GitHub Desktop.
convert all mp4 to gif
#!/bin/bash
# Check if an argument was provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 SEARCH_DIR"
exit 1
fi
# Use the first argument as the directory to search for MP4 files.
SEARCH_DIR=$1
# Use the find command with -exec to handle each file found by running a bash command.
find "$SEARCH_DIR" -type f -name "*.mp4" -exec bash -c 'file="{}"; dir=$(dirname "$file"); filename=$(basename -- "$file"); base=${filename%.mp4}; output="$dir/${base}.gif"; echo "Converting $file to $output (overwriting if exists)"; ffmpeg -y -i "$file" -vf "fps=8" -gifflags +transdiff -c:v gif -f gif "$output"' \;
echo "All conversions are complete."
# Optional: Delete the mp4 files
#find "$SEARCH_DIR" -type f -name "*.mp4" -exec rm -f {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment