Add detailed header and comments in English

- Updated the script header with detailed information about its purpose, usage, dependencies, and notes.
- Added comments and descriptions in English for better code understanding.
- Replaced German error messages with English counterparts for consistency.
This commit is contained in:
Ratatoskr 2024-02-13 16:53:31 +01:00
parent e7d708fc29
commit 3965e9b190
Signed by: Ratatoskr
GPG Key ID: 28B77439A6D78F4E

View File

@ -1,62 +1,79 @@
#!/bin/bash
# split2components.sh
# Überprüfe, ob ffmpeg und pv installiert sind
################################################################################
# split2components.sh - Script for splitting video files into components
################################################################################
# This script processes video files, extracts video streams to MKV format,
# extracts subtitles to SRT format, and converts audio streams to separate FLAC files.
# It supports various video file formats like MP4, MKV, AVI, FLV, and MOV.
# The script requires ffmpeg and pv to be installed on the system.
#
# Usage: ./split2components.sh <target_path>
# - <target_path>: The path where the files will be processed and components stored.
#
# Dependencies:
# - ffmpeg: A multimedia processing tool (https://ffmpeg.org/)
# - pv: A terminal-based tool for processing data (https://www.ivarch.com/programs/pv.shtml)
#
# Note: Make sure to install the required dependencies before using this script.
################################################################################
# Check if ffmpeg and pv are installed
if ! command -v ffmpeg &> /dev/null || ! command -v pv &> /dev/null
then
echo "ffmpeg oder pv ist nicht installiert. Bitte installiere sie zuerst."
echo "Error: ffmpeg or pv is not installed. Please install them first."
exit
fi
# Überprüfe, ob ein Zielpfad angegeben wurde
# Check if a target path is provided
if [ "$#" -eq 0 ]
then
echo "Bitte gib den Zielpfad an, in dem die Dateien verarbeitet werden sollen."
echo "Error: Please provide the target path where the files will be processed."
exit
fi
target_path="$1"
# Überprüfe, ob der Zielpfad vorhanden ist
# Check if the target path exists
if [ ! -d "$target_path" ]
then
echo "Der angegebene Zielpfad existiert nicht."
echo "Error: The specified target path does not exist."
exit
fi
# Erstelle die benötigten Verzeichnisse
# Create the required directories
mkdir -p "$target_path/mkv" "$target_path/flac" "$target_path/srt"
# Erstelle ein temporäres Verzeichnis für Untertiteldateien
# Create a temporary directory for subtitle files
temp_dir="temp_subs"
mkdir -p "$temp_dir" || { echo "Fehler beim Erstellen von $temp_dir"; exit 1; }
mkdir -p "$temp_dir" || { echo "Error creating $temp_dir"; exit 1; }
# Schleife durch alle unterstützten Video-Dateiformate im angegebenen Verzeichnis
# Loop through all supported video file formats in the specified directory
find "$target_path" -type f \( -iname \*.mp4 -o -iname \*.mkv -o -iname \*.avi -o -iname \*.flv -o -iname \*.mov \) -print0 | while IFS= read -r -d '' video_file
do
# Prüfe, ob es eine passende Videodatei gibt
# Check if there is a suitable video file
if [ -e "$video_file" ]
then
# Extrahiere den Dateinamen ohne Erweiterung
# Extract the filename without extension
filename_no_ext=$(basename -- "$video_file" | cut -f 1 -d '.')
new_video_file="$target_path/mkv/$filename_no_ext.mkv"
srt_subtitle_file="$target_path/srt/$filename_no_ext.srt"
# Konvertiere Video in MKV-Format
# Convert video to MKV format
ffmpeg -fflags +genpts -i "$video_file" -c:v copy -pix_fmt yuv420p -an -sn -fflags +genpts -avoid_negative_ts make_zero "$new_video_file" -y < /dev/null
# Extrahiere Untertitel ins SRT-Format (falls vorhanden)
# Extract subtitles to SRT format (if available)
subtitle_file="$temp_dir/$filename_no_ext.srt"
ffmpeg -i "$video_file" -map 0:s:0 "$subtitle_file"
# Konvertiere Untertitel ins SRT-Format, wenn vorhanden
# Convert subtitles to SRT format if available
if [ -e "$subtitle_file" ]
then
mv "$subtitle_file" "$srt_subtitle_file"
fi
# Schleife durch alle Audio-Streams und konvertiere sie in separate FLAC-Dateien
# Loop through all audio streams and convert them to separate FLAC files
audio_stream_index=0
while true
do
@ -65,13 +82,13 @@ do
then
break
fi
echo "Audio-Stream $audio_stream_index konvertiert."
echo "Audio Stream $audio_stream_index converted."
((audio_stream_index++))
done
echo "Verarbeitung von $filename_no_ext abgeschlossen."
echo "Processing of $filename_no_ext completed."
fi
done
# Lösche temporäres Verzeichnis
# Delete temporary directory
rm -r "$temp_dir"