Created
September 6, 2024 05:20
-
-
Save vinesmsuic/4e8a671ef5ca1f6468e723c31f7ec599 to your computer and use it in GitHub Desktop.
convert all mp4 to gif
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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