I have a list of mp4 files which are of kb's or of at max 4 MB (they were actually gifs but downloaded as mp4).So when I concatenate them using a list of them the video don't work as all of them are of different sizes (resolution wise ) and all of not are in vertical order.So any help with that matter and also I f someone would be kind enough to tell me the FFmpeg command to convert this mp4 list to gif 's without losing quality.Thanks in advance
Asked
Active
Viewed 2,780 times
0
-
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 Mar 13 '16 at 12:23
1 Answers
3
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
-
thanks for great and brief answer but as of input 1,2,3 and so on it would be a very hard job as I have over 100 files.Is there any way I can use mylist.txt file containing all files information like in this example `FFmpeg -f concat -i mylist.txt -c copy output.mp4` – hacker red Mar 13 '16 at 19:31
-
In short i would like to do all of this for files in a bulk if that would be possible – hacker red Mar 13 '16 at 19:52
-
Use `ffmpeg -f concat -i mylist.txt -vf "fps=10,scale=320:240,setsar=1,palettegen[out]" -map "[out]" palette.png` for first command. And `ffmpeg -f concat -i mylist.txt -i palette.png -filter_complex "[0:v]fps=10,scale=320:240,setsar=1[v0];[v0][1:v],palettegen[out]" -map "[out]" -fflags +genpts output.gif` – Gyan Mar 14 '16 at 04:36
-
@mulvya error for your 1st command `Output with label 'out' does not exist in any defined filter graph, or was already used elsewhere.` – hacker red Mar 14 '16 at 12:41
-
-
Update: @Mulvya added `-filter_complex` but now its saying it can't find a suitable format for output – hacker red Mar 14 '16 at 12:53
-
to me it seems even if it worked it would generate a single file named pallete.png...What I would do with that @Mulvya – hacker red Mar 14 '16 at 13:01
-
As guessed output is a single palette file of 2kb and this `[Parsed_palettegen_3 @ 05e73ba0] 255(+1) colors generated out of 319259 colors; ratio=0.000799 frame= 1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.03 bitrate=N/A speed=0.000728x video:1kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown ` – hacker red Mar 14 '16 at 13:07
-
Use `ffmpeg -f concat -i mylist.txt -i palette.png -filter_complex "[0:v]fps=10,scale=320:240,setsar=1[v0];[v0][1:v]paletteuse[out]" -map "[out]" -fflags +genpts output.gif` – Gyan Mar 14 '16 at 13:23
-
@Mulvya I really appreciate all of your help but none of this is seem to be working but thanks anyway...Last command just is going on and on and not producing any result – hacker red Mar 14 '16 at 15:18
-
-
@Mulvya the last one `Use ffmpeg -f concat -i mylist.txt -i palette.png -filter_complex "[0:v]fps=10,scale=320:240,setsar=1[v0];[v0][1:v]paletteuse[out]" -map "[out]" -fflags +genpts output.gif` – hacker red Mar 15 '16 at 20:19
-
If you have 100+ videos, it will take time. Is the ffmpeg console output showing the fps counter increasing? – Gyan Mar 15 '16 at 20:41