This shell script merges two .ass subtitle files, aligning the timing of the second subtitle file to match the timing of the first one. It also adjusts the alignment of the subtitles to display them at the top of the screen.
- This script requires
ffmpeg
to be installed on your system.
./merge_subtitles.sh file1.ass file2.ass
file1.ass
: The reference subtitle file.file2.ass
: The subtitle file to be merged and aligned withfile1.ass
.
The merged subtitle file will be created with the name file2.merged.ass
in the same directory as the script.
- Checks if exactly two arguments are provided.
- Identifies the Alignment field in the subtitle files and modifies it to display subtitles at the top of the screen.
- Extracts the dialogues from both files.
- Determines the time difference between the start times of the two subtitle files.
- Adjusts the timing of the second subtitle file using
ffmpeg
. - Merges the modified second file with the first file, adjusting the alignment and timing.
- Cleans up temporary files.
- This script assumes the subtitle files are in Advanced SubStation Alpha (.ass) format. You can convert subtitle files to the
.ass
format usingffmpeg
. For example:ffmpeg -i input.srt output.ass
- If
ffmpeg
is not available, the script will not be able to adjust the timing of the subtitles.