This is a personal project and comes with no warranty.
This is an initiative, or Project, designed for streamlined video file transcoding—specifically, converting all video files in a directory and its subdirectories into the High Efficiency Video Coding (HEVC) codec. By consolidating your multimedia assets under this format, you can significantly optimize storage usage by potentially reducing gigabytes of space previously occupied by less efficient codecs.
-
Recursive Transcoding: The project traverses a specified directory and its subdirectories, targeting all video files for transcoding. This ensures no file is overlooked in the quest to maximize storage efficiency.
-
HEVC Conversion: Utilizes state-of-the-art HEVC codec for superior compression rates compared to many older standards like H.264 or AVCHD. As a result, you'll enjoy substantial space savings while maintaining excellent video quality.
-
Ease of Use: Leveraging the simplicity and power of bash scripting, this project is built with your convenience in mind. It's designed to be straightforward to install and run on compatible systems without requiring extensive setup or configuration beyond ensuring the necessary dependencies are installed (see the 'Dependencies' section below).
-
Modular and Extensible: The script components have been organized into modular, manageable chunks within
utils.sh, facilitating easy updates, bug fixes, and potentially integration with additional functionalities in the future.
- Storage Optimization: By converting video files to HEVC within your home server, you can dramatically decrease disk usage. This freed space enhances library capacity without sacrificing performance.
- Space Efficiency: Reduce storage footprint by transcoding older format videos into HEVC for your video archive. Keep high-quality content accessible while optimizing physical media.
- Efficient Backups: Optimize backup processes by minimizing space consumption for multimedia data, thanks to HEVC's superior compression efficiency.
- Enhanced Storage Utilization: Preserve extensive video collections on more compact media by converting them to HEVC. Maintain access while maximizing storage space.
In essence, this project empowers users to transform their digital repositories into leaner, cost-effective systems without compromising the superior viewing experience HEVC is known for.
- Disk Space Check: Monitors free space in specified directories before starting video conversion tasks.
- Command Validation: Ensures essential tools (awk, bc) are available on the system.
- Progress Tracking: Dynamically updates a progress bar based on conversion tasks using HEVC encoding.
- Device Detection for VAAPI: Validates the presence and read permissions of the VAAPI GPU device required for hardware acceleration.
- File Handling & Validation: Lists, compares, and processes video files recursively to ensure they are in a compatible format (HEVC) before conversion.
- Time Efficiency: Uses
ffprobefor quick duration estimation of input files without decoding them completely, minimizing processing time. - HEVC Codec Detection: Verifies if the target video files already utilize the HEVC codec and provides warnings otherwise.
- Incremental Logging & Reporting: Maintains a log file (
output) detailing script activities with appropriate error or warning messages for unsuccessful operations. - TUI Integration (Terminal User Interface): Provides an interactive terminal display to visualize conversion progress, durations, and space savings in real time.
This script is written primarily for Bash. However, if you prefer a different shell like Zsh, make sure it meets the requirements for the commands used.
FFmpeg is a powerful tool for handling multimedia files. To utilize video processing capabilities via VAAPI (Video Acceleration API), you must have:
- FFmpeg installed on your system. For Ubuntu/Debian, run
sudo apt install -y ffmpeg.
Gawk is required for processing the output of certain commands and for running scripts that make heavy use of pattern matching. It can usually be installed via package managers:
- On Ubuntu/Debian, run
sudo apt install -y gawk. - On CentOS/Fedora, use
sudo yum install -y gawk.
This is a powerful tool for converting video files from various formats (default: MP4) to the high-efficiency video coding (HEVC) format (-e mp4 or -e your_extension) while leveraging hardware acceleration via VAAPI devices (default: /dev/dri/renderD128).
You can customize several aspects of the conversion process through command-line options. Here's a detailed breakdown using ./main.sh:
./main.sh -e mp4 -b 3000 -m 1080 -a aac -d /mnt/your_hd -f 5 -l hevc_conversion.log-
-eor--extension: Sets the output video file extension (default:mp4).- Example:
-e mp4(or-e your_extension)
- Example:
-
-bor--bitrate: Specifies bitrates for VBR mode. Default is medium value (3).- Example:
-b 3000
- Example:
-
-mor--max_height: Defines the maximum height of converted videos in pixels, defaulting to 1080.- Example:
-m 720
- Example:
-
-aor--audio_codec: Chooses audio codec (default:aac).- Example:
-a he-ac3for Dolby Digital Plus. (Only tested withaac)
- Example:
-
-dor--input_directory: Points to the root directory containing input videos, defaulted to/mnt/your_hd.- Example:
-d /media/your_user
- Example:
-
-for--min_free_space: Sets the minimum free space on the drive in GB (default: 5).- Example:
-f 10for more ample storage conditions
- Example:
-
-lor--log_file: Specifies the path to a log file for recording process details. Defaults to$HOME/hevc_conversion.log.- Example:
-l /path/to/custom_logfile
- Example:
-
-vor--vaaapi_device: Identifies the device using VAAPI (e.g.,/dev/dri/renderD128).- Example: If your system uses a different VAAPI driver, use
-v /dev/xvmc-nvidia
- Example: If your system uses a different VAAPI driver, use
-
-nor--dry_run: Activates a "dry run" mode where the script simulates conversions without making actual changes.- Example: Use this for assessing options before executing conversion operations with
-nomitted.
- Example: Use this for assessing options before executing conversion operations with
If you want to verify how these settings would transform video files without modifying any files, use the dry_run mode by appending -n:
./main.sh -e mp4 -b 3000 -m 1080 -a aac -d /mnt/your_hd -f 5 -l hevc_conversion.log -nThis command will print out the steps that would have been taken for each input file without actually performing any conversions or logging them to a file.
Refer to the script's configuration section (config.sh) for further customization options, including setting up different audio coding modes and handling multiple files in parallel using threads. For now, this is the core functionality of hevc_converter when executed with ./main.sh.
- For more control and customization, modify the
utils.shfile for additional functionality like custom metrics or extended reporting. - Pull requests are welcome!
This project is licensed under the GNU 3 license; see the LICENSE file for details. Contributions are welcome! Feel free to create pull requests with new features or improvements. Please adhere to any coding standards and guidelines set forth in this repository.
Happy coding, and enjoy your smooth HEVC video conversion!