Created
October 30, 2024 21:24
-
-
Save Akczht/836edd4744ce1dc1e4416594da8d6a5e to your computer and use it in GitHub Desktop.
A script to run ffmpeg on all the files in a folder and remux videos
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 | |
# Set input and output extensions | |
input_ext="mkv" # Default input extension is .mkv | |
output_ext="mkv" # Default output extension is .mp4 | |
arguments="-codec copy -map 0:v -map 0:a:2 -map 0:s -map 0:t" | |
# Create output directory | |
output_dir="$PWD/dir" | |
mkdir -p "$output_dir" | |
# Loop through all files with the specified input extension in the current directory | |
for file in *."$input_ext"; do | |
# Check if there are files with the specified input extension | |
if [ ! -f "$file" ]; then | |
echo "No files with .$input_ext extension found." | |
exit 1 | |
fi | |
# Get the base file name (without extension) | |
base_name="${file%.*}" | |
# Define the output file path | |
output_file="$output_dir/$base_name.$output_ext" | |
# Convert file using ffmpeg with specified arguments | |
ffmpeg -i "$file" $arguments "$output_file" -y | |
# Check if conversion was successful | |
if [ $? -eq 0 ]; then | |
echo "Converted $file to $output_file" | |
else | |
echo "Failed to convert $file" | |
fi | |
done | |
echo "Conversion completed. All files moved to $output_dir." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment