Concatenate a list of files with different resolutions

0

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

hacker red

Posted 2016-03-13T09:49:15.993

Reputation: 33

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

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

llogan

Posted 2016-03-13T09:49:15.993

Reputation: 31 929

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 – 2016-03-13T19:31:08.007

In short i would like to do all of this for files in a bulk if that would be possible – hacker red – 2016-03-13T19:52:56.990

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 – 2016-03-14T04:36:47.953

@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 – 2016-03-14T12:41:32.320

Sorry, it's a vf so remove [out] and -map "[out]" – Gyan – 2016-03-14T12:52:34.083

Update: @Mulvya added -filter_complex but now its saying it can't find a suitable format for output – hacker red – 2016-03-14T12:53:35.827

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 – 2016-03-14T13:01:58.343

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 – 2016-03-14T13:07:24.753

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 – 2016-03-14T13:23:19.433

@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 – 2016-03-14T15:18:09.953

Which command? 1st or 2nd? – Gyan – 2016-03-14T15:21:07.317

@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 – 2016-03-15T20:19:14.130

If you have 100+ videos, it will take time. Is the ffmpeg console output showing the fps counter increasing? – Gyan – 2016-03-15T20:41:38.380