Last active
April 29, 2026 03:47
-
-
Save keevee09/8160a8f26a39bc99ec4f21214c326edf to your computer and use it in GitHub Desktop.
This is a collection of ffmpeg scripts that have been useful.
This file contains hidden or 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
| #!/usr/bin/bash | |
| set -euo pipefail | |
| for video in *.avi; do | |
| ffmpeg -i "${video}" -c:v libx265 -crf 23 -c:a aac "${video%.avi}.mkv" | |
| done |
This file contains hidden or 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
| #!/usr/bin/bash | |
| set -euo pipefail | |
| for i in *.srt; do | |
| ffmpeg -v 8 -loglevel 99 -sub_charenc CP1252 -i "$i" "${i%.srt}_fix.srt" | |
| done |
This file contains hidden or 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 -euo pipefail | |
| # Directory containing the files (change this if needed) | |
| DIRECTORY="." | |
| # Function to find the corresponding subtitle file for a given mkv | |
| get_subtitle() { | |
| local mkv_file="$1" | |
| local subtitle_file | |
| # Extract the base name (e.g., Still Game S1EP1) | |
| local base_name=$(basename "$mkv_file" .mkv) | |
| # Construct the subtitle filename (e.g., Still Game S1EP1.srt) | |
| subtitle_file="${base_name}.ass" | |
| # Check if the subtitle file exists | |
| if [ -f "$DIRECTORY/$subtitle_file" ]; then | |
| echo "$DIRECTORY/$subtitle_file" | |
| else | |
| echo "" # Return an empty string if no subtitle is found | |
| fi | |
| } | |
| # Loop through all mkv files in the directory | |
| for mkv_file in "$DIRECTORY"/*.mkv; do | |
| echo "Processing mkv_file: $mkv_file" # Debugging: Print the mkv filename | |
| # Get the corresponding subtitle file | |
| subtitle_file=$(get_subtitle "$mkv_file") | |
| echo "subtitle_file: $subtitle_file" # Debugging: Print the subtitle filename | |
| # Check if a subtitle file was found | |
| if [ -n "$subtitle_file" ]; then | |
| # Construct the output filename (e.g., Still Game S1EP1_eng.mkv) | |
| output_file="${mkv_file%.mkv}_eng.mkv" | |
| echo "output_file: $output_file" # Debugging: Print the output filename | |
| # Run the ffmpeg command | |
| echo "Processing: $mkv_file and $subtitle_file -> $output_file" | |
| # ffmpeg -i "$mkv_file" -i "$subtitle_file" -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=eng "$output_file" | |
| ffmpeg -i "$mkv_file" -i "$subtitle_file" -c:v copy -c:a copy -c:s ass -map 0:0 -map 1:0 -metadata:s:s:0 language=eng "$output_file" | |
| # Check for errors | |
| if [ $? -ne 0 ]; then | |
| echo "Error processing $mkv_file and $subtitle_file" | |
| fi | |
| else | |
| echo "No subtitle found for $mkv_file" | |
| fi | |
| done | |
| echo "Finished processing all files." |
This file contains hidden or 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 -euo pipefail | |
| # Directory containing the files (change this if needed) | |
| DIRECTORY="." | |
| # Function to find the corresponding subtitle file for a given MP4 | |
| get_subtitle() { | |
| local mp4_file="$1" | |
| local subtitle_file | |
| # Extract the base name (e.g., Still Game S1EP1) | |
| local base_name=$(basename "$mp4_file" .mp4) | |
| # Construct the subtitle filename (e.g., Still Game S1EP1.srt) | |
| subtitle_file="${base_name}.srt" | |
| # Check if the subtitle file exists | |
| if [ -f "$DIRECTORY/$subtitle_file" ]; then | |
| echo "$DIRECTORY/$subtitle_file" | |
| else | |
| echo "" # Return an empty string if no subtitle is found | |
| fi | |
| } | |
| # Loop through all MP4 files in the directory | |
| for mp4_file in "$DIRECTORY"/*.mp4; do | |
| echo "Processing mp4_file: $mp4_file" # Debugging: Print the MP4 filename | |
| # Get the corresponding subtitle file | |
| subtitle_file=$(get_subtitle "$mp4_file") | |
| echo "subtitle_file: $subtitle_file" # Debugging: Print the subtitle filename | |
| # Check if a subtitle file was found | |
| if [ -n "$subtitle_file" ]; then | |
| # Construct the output filename (e.g., Still Game S1EP1_eng.mp4) | |
| output_file="${mp4_file%.mp4}_eng.mp4" | |
| echo "output_file: $output_file" # Debugging: Print the output filename | |
| # Run the ffmpeg command | |
| echo "Processing: $mp4_file and $subtitle_file -> $output_file" | |
| ffmpeg -i "$mp4_file" -i "$subtitle_file" -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=eng "$output_file" | |
| # Check for errors | |
| if [ $? -ne 0 ]; then | |
| echo "Error processing $mp4_file and $subtitle_file" | |
| fi | |
| else | |
| echo "No subtitle found for $mp4_file" | |
| fi | |
| done | |
| echo "Finished processing all files." |
This file contains hidden or 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 -euo pipefail | |
| # Directory containing the files (change this if needed) | |
| DIRECTORY="." | |
| # Function to find the corresponding subtitle file for a given mkv | |
| get_subtitle() { | |
| local mkv_file="$1" | |
| local subtitle_file | |
| # Extract the base name (e.g., Still Game S1EP1) | |
| local base_name=$(basename "$mkv_file" .mkv) | |
| # Construct the subtitle filename (e.g., Still Game S1EP1.srt) | |
| subtitle_file="${base_name}.srt" | |
| # Check if the subtitle file exists | |
| if [ -f "$DIRECTORY/$subtitle_file" ]; then | |
| echo "$DIRECTORY/$subtitle_file" | |
| else | |
| echo "" # Return an empty string if no subtitle is found | |
| fi | |
| } | |
| # Loop through all mkv files in the directory | |
| for mkv_file in "$DIRECTORY"/*.mkv; do | |
| echo "Processing mkv_file: $mkv_file" # Debugging: Print the mkv filename | |
| # Get the corresponding subtitle file | |
| subtitle_file=$(get_subtitle "$mkv_file") | |
| echo "subtitle_file: $subtitle_file" # Debugging: Print the subtitle filename | |
| # Check if a subtitle file was found | |
| if [ -n "$subtitle_file" ]; then | |
| # Construct the output filename (e.g., Still Game S1EP1_eng.mkv) | |
| output_file="${mkv_file%.mkv}_eng.mkv" | |
| echo "output_file: $output_file" # Debugging: Print the output filename | |
| # Run the ffmpeg command | |
| echo "Processing: $mkv_file and $subtitle_file -> $output_file" | |
| ffmpeg -i "$mkv_file" -i "$subtitle_file" -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=eng "$output_file" | |
| # Check for errors | |
| if [ $? -ne 0 ]; then | |
| echo "Error processing $mkv_file and $subtitle_file" | |
| fi | |
| else | |
| echo "No subtitle found for $mkv_file" | |
| fi | |
| done | |
| echo "Finished processing all files." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment