You can use the fps, scale, setsar, setpts, concat, palettegen, and paletteuse filters.
1. Make all inputs uniform, concatenate, then generate the palette
ffmpeg -i input0 -i input1 -i input2 -filter_complex \
"[0:v]fps=10,scale=320:240,setsar=1/1,setpts=PTS-STARTPTS[v0]; \
[1:v]fps=10,scale=320:240,setsar=1/1,setpts=PTS-STARTPTS[v1]; \
[2:v]fps=10,scale=320:240,setsar=1/1,setpts=PTS-STARTPTS[v2]; \
[v0][v1][v2]concat=n=3:v=1:a=0,palettegen[out]" \
-map "[out]" palette.png
- You may not need fps but you did not show any info about your inputs so I had to make assumptions.
2. Encode to GIF
ffmpeg -i input0 -i input1 -i input2 -i palette.png -filter_complex \
"[0:v]fps=10,scale=320:240,setsar=1/1,setpts=PTS-STARTPTS[v0]; \
[1:v]fps=10,scale=320:240,setsar=1/1,setpts=PTS-STARTPTS[v1]; \
[2:v]fps=10,scale=320:240,setsar=1/1,setpts=PTS-STARTPTS[v2]; \
[v0][v1][v2]concat=n=3:v=1:a=0[vv]; \
[vv][3:v]paletteuse[out]" \
-map "[out]" output.gif
- You can't "convert MP4 to GIF without losing quality", but there is a small chance you may not notice much of a difference since you said the MP4 were created from GIF. It all depends on what your inputs look like and how many colors there are.
Also see
You'll have to re-encode once, while specifying a fixed resolution and frame rate. Then you generate a palette, and then the GIF. – Gyan – 2016-03-13T12:23:50.850