58 lines
1.4 KiB
Bash
Executable File
58 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
if [ "$#" -ne 1 ]; then
|
|
echo "Usage: $0 <output_name>"
|
|
exit 1
|
|
fi
|
|
|
|
OUTPUT_FILE=$1
|
|
INPUT_DIR="./2-looped"
|
|
OUTPUT_DIR="./3-output"
|
|
|
|
mkdir -p $OUTPUT_DIR
|
|
|
|
mapfile -t video_files < <(
|
|
find "$INPUT_DIR" -maxdepth 1 -type f \( \
|
|
-iname "*.mp4" -o -iname "*.mov" -o -iname "*.avi" -o -iname "*.m4v" -o -iname "*.mkv" -o -iname "*.webm" \
|
|
\) -printf "%f\n" |
|
|
sort -t. -k1,1V |
|
|
sed "s|^|$INPUT_DIR/|"
|
|
)
|
|
|
|
if [ "${#video_files[@]}" -lt 2 ]; then
|
|
echo "Need at least two video files to concatenate."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Found ${#video_files[@]} video files to concatenate."
|
|
|
|
ffmpeg_cmd="ffmpeg -y"
|
|
filter_complex=""
|
|
input_count=0
|
|
|
|
for video_file in "${video_files[@]}"; do
|
|
if [[ -f $video_file ]]; then
|
|
ffmpeg_cmd+=" -i \"$video_file\""
|
|
filter_complex+="[${input_count}:v:0] "
|
|
input_count=$((input_count+1))
|
|
fi
|
|
done
|
|
|
|
filter_complex+="hstack=inputs=$input_count [v]"
|
|
ffmpeg_cmd+=" -filter_complex \"$filter_complex\" -map \"[v]\" \"$OUTPUT_DIR/$OUTPUT_FILE\""
|
|
|
|
eval $ffmpeg_cmd
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "---->>>> Generated concatenated video: $OUTPUT_DIR/$OUTPUT_FILE"
|
|
|
|
for video_file in "${video_files[@]}"; do
|
|
if [ -f "$video_file" ]; then
|
|
rm "$video_file"
|
|
echo "---->>>> Removed video file: $video_file"
|
|
fi
|
|
done
|
|
else
|
|
echo "---->>>> FFmpeg command failed. Video files have not been removed."
|
|
fi
|