Created
April 21, 2024 13:21
-
-
Save imesut/c571674fc38866a69fc71a5bf04fd803 to your computer and use it in GitHub Desktop.
Deletes repeating frames ifexist more than 2 times. Then it can be merged as a video file.
This file contains 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 | |
# BEFORE THE SCRIPT RUN | |
# mkdir frame | |
# ffmpeg -i video.mp4 -r 30 frame/$filename%04d.jpg | |
# cd frame | |
# AFTER THE SCRIPT RUN | |
# ffmpeg -framerate 30 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p ../out.mp4 | |
# Create an associative array to store checksums and corresponding file names | |
declare -A checksums | |
# Create an associative array to store the count of each checksum | |
declare -A counts | |
# Iterate over all JPEG files in the current directory | |
for file in *.jpg; do | |
# Get the MD5 checksum of the current file | |
checksum=$(md5 -q "$file") | |
# Increment the count for this checksum | |
((counts[$checksum]++)) | |
# Check if the checksum already exists in the array | |
if [[ ${checksums[$checksum]} ]]; then | |
# If the count is 3 or more, remove the file | |
if (( ${counts[$checksum]} >= 3 )); then | |
echo "Deleting duplicate image: $file" | |
rm "$file" | |
else | |
echo "Duplicate image found (count: ${counts[$checksum]}): $file" | |
fi | |
else | |
# Store the checksum and filename in the array | |
checksums[$checksum]=$file | |
echo "Checksum for $file: $checksum" | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment