@maksim-vorontsov's answer for different aspect ratios was so good (and I needed to do this to a lot of videos with arbitrary inputs) that I made a bash script out of it to allow concatenation and resizing of arbitrary set of input videos into a final output:
https://gist.github.com/mkatychev/c1edf136ad36bc137134d098198903b3
the core ffmpeg argbuilder is the function below:
join_files() {
local input_n=()
local scale_to_n=("$SEP")
local concat_n=()
for i in $(seq $#); do
input_n+=("-i ${!i}")
((n = i - 1))
concat_n+=("[v${n}][${n}:a]")
local scale_to=""
scale_to+="[${n}:v]scale=$SCALE:force_original_aspect_ratio=decrease:eval=frame,"
scale_to+="pad=$SCALE:-1:-1:color=black[v${n}];$SEP"
scale_to_n+=("$scale_to")
done
local filter_complex=""
filter_complex+="${scale_to_n[*]}"
filter_complex+="${concat_n[*]}"
filter_complex+=" concat=n=$#:v=1:a=1 [v] [a]"
# shellcheck disable=SC2068
command $FFMPEG ${input_n[@]} -n -filter_complex "$filter_complex" \
-map "[v]" -map "[a]" -s hd480 -vcodec libx264 "$OUT_FILE"
}
Running with --debug flag:
$ ./ffmpeg_concat_and_scale.sh video_1.mp4 video_2.flv video_3.mp4 video_4.flv --scale 640:480 --debug --out video_1_to_4.mkv
ffmpeg -i video_1.mp4 -i video_2.flv -i video_3.mp4 -i video_4.flv -n -filter_complex
[0:v]scale=640:480:force_original_aspect_ratio=decrease:eval=frame,pad=640:480:-1:-1:color=black[v0];
[1:v]scale=640:480:force_original_aspect_ratio=decrease:eval=frame,pad=640:480:-1:-1:color=black[v1];
[2:v]scale=640:480:force_original_aspect_ratio=decrease:eval=frame,pad=640:480:-1:-1:color=black[v2];
[3:v]scale=640:480:force_original_aspect_ratio=decrease:eval=frame,pad=640:480:-1:-1:color=black[v3];
[v0][0:a] [v1][1:a] [v2][2:a] [v3][3:a] concat=n=4:v=1:a=1 [v] [a] -map [v] -map [a] -s hd480 -vcodec libx264 video_1_to_4.mkv
Remove --debug to create video_1_to_4.mkv:
./ffmpeg_concat_and_scale.sh video_1.mp4 video_2.flv video_3.mp4 video_4.flv --scale 640:480 --out video_1_to_4.mkv