Skip to content

Instantly share code, notes, and snippets.

@Akczht
Created October 11, 2024 17:20
Show Gist options
  • Save Akczht/dcf0e2f0a979b0f8d819bda0dba64a3f to your computer and use it in GitHub Desktop.
Save Akczht/dcf0e2f0a979b0f8d819bda0dba64a3f to your computer and use it in GitHub Desktop.
trims videos from start for a few seconds
#!/bin/bash
# Set default values for input and output formats
input_format="mkv"
output_format="mkv"
# Folder containing the video files
input_folder="./" # Change this if needed
# Create a directory for processed files
output_folder="./dir"
# Ensure the output folder exists
mkdir -p "$output_folder"
# Define the time duration for the first chapter (11 seconds in this case)
cut_time="0.01"
# Optional: allow users to specify input and output formats as arguments
if [ ! -z "$1" ]; then
input_format="$1"
fi
if [ ! -z "$2" ]; then
output_format="$2"
fi
# Loop through each video file in the folder with the specified input format
for file in "$input_folder"*."$input_format"; do
# Generate the output file name by replacing the extension with the desired output format
output_file="$output_folder/$(basename "${file%.*}").$output_format"
# Trim the first 11 seconds (which is the first chapter) without re-encoding
ffmpeg -ss "$cut_time" -i "$file" -map 0 -c copy "$output_file"
echo "Processed $file, removed first $cut_time seconds (first chapter), and saved to $output_file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment