This repository contains a Bash script (find_duplicates.sh) that finds and lists duplicate video files in a specified directory. It also calculates a quality score for each video and determines the best version to keep based on video resolution, bitrate, duration, and codec type.
- Scans a directory for video files (
.mkv,.mp4,.avi,.ts) - Identifies potential duplicate files based on filename
- Calculates a quality score for each video to determine the best version to keep
- Logs actions and errors to a log file
- Outputs a summary of duplicate video files
- Bash (Linux/macOS)
ffprobe(part of FFmpeg, used to extract video properties)
-
Clone the repository:
git clone https://github.com/sftech13/find-duplicates.git cd find-duplicates -
Make the script executable:
chmod +x find_duplicates.sh
-
Install FFmpeg if it's not already installed:
sudo apt-get install ffmpeg
Or for macOS:
brew install ffmpeg
- Log File Path: The script saves logs to
$HOME/logs/duplicates_log.txt. You can modify this path as needed. - Search Directory: By default, the script searches the
/mnt/Mediadirectory for video files. Update thesearch_dirvariable to change this directory. - Output Directory: Results are saved in your home directory by default (
$HOME). Update theoutput_dirvariable to change the output location.
Run the script with the following command:
./find_duplicates.sh- The script will search for video files in the specified
search_dir. - It will identify duplicate filenames, calculate a quality score for each video, and write the results to a text file (
Duplicates.txt) in theoutput_dir.
- The script logs its actions and any errors to a log file located at
$HOME/logs/duplicates_log.txt. - The log file records:
- Files found in the search directory
- Potential duplicate filenames
- The results of the duplicate detection process
- Duplicates.txt: This file is saved in the
output_dirand contains a summary of the duplicate video files found. The summary includes:- Count: Number of duplicates found for a filename
- Name: Filename of the duplicate video
- Group: Paths to all duplicates
- Best Quality: The file with the highest quality score
- Best Quality Score: The calculated score of the best-quality file
This project is licensed under the MIT License. See LICENSE for details.