-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffreplace
More file actions
executable file
·58 lines (49 loc) · 1.31 KB
/
Copy pathffreplace
File metadata and controls
executable file
·58 lines (49 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Default subtitle language
SUBTITLE_LANG="deu"
# Parse command-line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--lang) SUBTITLE_LANG="$2"; shift; shift ;;
*) FILENAME="$1" ;;
esac
shift
done
# Check if a filename is provided
if [ -z "$FILENAME" ]; then
echo "Usage: replace_subtitles <filename> [--lang language_code]"
echo "Example: replace_subtitles video --lang deu"
exit 1
fi
# Define input and output files
INPUT_MP4="${FILENAME}.mp4"
BACKUP_MP4="${FILENAME}.backup.mp4"
INPUT_SRT="${FILENAME}.srt"
OUTPUT_MP4="${FILENAME}.mp4"
# Check if input MP4 file exists
if [ ! -f "$INPUT_MP4" ]; then
echo "Error: $INPUT_MP4 not found!"
exit 1
fi
# Check if input SRT file exists
if [ ! -f "$INPUT_SRT" ]; then
echo "Error: $INPUT_SRT not found!"
exit 1
fi
# Create a backup of the original MP4 file
cp "$INPUT_MP4" "$BACKUP_MP4"
# Run ffmpeg to replace subtitles using the backup as input
ffmpeg -i "$BACKUP_MP4" -i "$INPUT_SRT" \
-c:v copy -c:a copy \
-c:s mov_text \
-map 0:v -map 0:a -map 1:s \
-metadata:s:s:0 language="$SUBTITLE_LANG" \
"$OUTPUT_MP4"
# Check if ffmpeg succeeded
if [ $? -eq 0 ]; then
echo "Subtitles replaced successfully: $OUTPUT_MP4 created."
echo "Backup of the original file: $BACKUP_MP4"
else
echo "Subtitle replacement failed!"
exit 1
fi