-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch-av1
More file actions
executable file
·154 lines (134 loc) · 4.06 KB
/
batch-av1
File metadata and controls
executable file
·154 lines (134 loc) · 4.06 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
# https://github.com/Jaded-Encoding-Thaumaturgy/JET-guide/blob/master/docs/encoding/svtav1.md
# TODO: check if anime mode is necessary
# Default values
CRF=25
PRESET=4
ANIME_MODE=false
DRY_RUN=false
USE_OPUS=false
FILES=()
# Display help message
show_help() {
echo "Usage: $(basename "$0") [OPTIONS] [FILES...]"
echo ""
echo "Batch convert video files to AV1 using SVT-AV1."
echo ""
echo "Options:"
echo " -a, --anime Enable anime mode (adds more film-grain), TODO: check if this is necessary"
echo " -c, --crf VALUE Set CRF value (default: $CRF)"
echo " -p, --preset VALUE Set SVT-AV1 preset (default: $PRESET)"
echo " -o, --opus Transcode audio to Opus (default: copy)"
echo " -d, --dry-run Show what would be done without encoding"
echo " -h, --help Show this help message"
echo ""
echo "If no files are provided, common video files (.mp4, .mkv, .webm, .mov, .avi) in the current directory will be processed."
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-a|--anime)
ANIME_MODE=true
shift
;;
-c|--crf)
CRF="$2"
shift 2
;;
-p|--preset)
PRESET="$2"
shift 2
;;
-o|--opus)
USE_OPUS=true
shift
;;
-d|--dry-run)
DRY_RUN=true
shift
;;
-h|--help)
show_help
exit 0
;;
-*)
echo "Unknown option: $1"
show_help
exit 1
;;
*)
FILES+=("$1")
shift
;;
esac
done
# Check for ffmpeg and libsvtav1
if ! command -v ffmpeg &> /dev/null; then
echo "Error: ffmpeg is not installed."
exit 1
fi
if ! ffmpeg -encoders 2>/dev/null | grep -q libsvtav1; then
echo "Error: ffmpeg does not support libsvtav1. Please install a compatible version."
exit 1
fi
# If no files provided, default to common video formats
if [ ${#FILES[@]} -eq 0 ]; then
shopt -s nullglob
FILES=(*.mp4 *.mkv *.webm *.mov *.avi)
fi
if [ ${#FILES[@]} -eq 0 ]; then
echo "Error: No files to process."
exit 1
fi
# Construct SVT-AV1 parameters
SVTAV1_PARAMS="tune=1:enable-variance-boost=1:tf-strength=1:sharpness=1:tile-columns=1:film-grain=4:luminance-qp-bias=25"
if [ "$ANIME_MODE" = true ]; then
SVTAV1_PARAMS="${SVTAV1_PARAMS/film-grain=4/film-grain=8}"
fi
AUDIO_OPTS=(-c:a copy)
if [ "$USE_OPUS" = true ]; then
AUDIO_OPTS=(-c:a libopus -b:a 128k)
fi
FFMPEG_OPTIONS=(
-map 0
-c:v libsvtav1
-crf "$CRF"
-preset "$PRESET"
-pix_fmt yuv420p10le
-svtav1-params "$SVTAV1_PARAMS"
"${AUDIO_OPTS[@]}"
-c:s copy
)
echo "--- Starting AV1 Batch Conversion ---"
echo "--- CRF: $CRF, Preset: $PRESET, Anime: $ANIME_MODE, Opus: $USE_OPUS"
[ "$DRY_RUN" = true ] && echo "--- DRY RUN MODE ENABLED ---"
for INPUT_FILE in "${FILES[@]}"; do
if [[ ! -f "$INPUT_FILE" ]]; then
echo "--- Skipping: $INPUT_FILE (Not a file)"
continue
fi
# Determine output filename in the same directory as input
DIR=$(dirname "$INPUT_FILE")
BASE=$(basename "$INPUT_FILE")
NAME="${BASE%.*}"
OUTPUT_FILE="${DIR}/${NAME}_AV1.mkv"
# Avoid self-overwrite (e.g. if input is already _AV1.mkv)
if [[ "$INPUT_FILE" == "$OUTPUT_FILE" ]]; then
OUTPUT_FILE="${DIR}/${NAME}_AV1_new.mkv"
fi
echo "--- Processing: $INPUT_FILE"
echo "--- Output: $OUTPUT_FILE"
if [ "$DRY_RUN" = true ]; then
echo "ffmpeg -i \"$INPUT_FILE\" ${FFMPEG_OPTIONS[*]} \"$OUTPUT_FILE\""
else
ffmpeg -i "$INPUT_FILE" "${FFMPEG_OPTIONS[@]}" "$OUTPUT_FILE" -y
if [ $? -eq 0 ]; then
echo "--- Finished: $INPUT_FILE (Success)"
else
echo "--- Error: $INPUT_FILE (FFmpeg failed)"
echo "$(date): Error processing $INPUT_FILE" >> ./ffmpeg-error-log.txt
fi
fi
echo "-------------------------------------"
done
echo "--- Batch processing complete! ---"