55 lines
1.2 KiB
Bash
Executable File
55 lines
1.2 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"
|
|
|
|
video_files=( "$INPUT_DIR"/*.{mp4,mov,avi,m4v} )
|
|
|
|
if [ "${#video_files[@]}" -lt 2 ]; then
|
|
echo "Need at least two video files to concatenate vertically."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Found ${#video_files[@]} video files to concatenate vertically."
|
|
|
|
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+="vstack=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
|