1

I tried to create a video using multiple images having different scales or sizes or (height*widths) using Mobile-FFmpeg #
I am using this code script to get the required result:

val filterStringBuilder1 = StringBuilder()<br />
filterStringBuilder1.append(listOfImages)<br />
filterStringBuilder1.append("-filter_complex ")<br />
filterStringBuilder1.append(<br />
            "[0:v]scale=100:140:force_original_aspect_ratio=decrease,pad=100:140:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=out:st=4:d=1[v0];" +<br />
            "[1:v]scale=180:120:force_original_aspect_ratio=decrease,pad=180:120:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v1];" +<br />
            "[2:v]scale=120:180:force_original_aspect_ratio=decrease,pad=120:180:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2];" +<br />
            "[v0][v1][v2]concat=n=3:v=1:a=0,format=yuv420p[v]")<br />
    filterStringBuilder1.append(" -map")<br />
    filterStringBuilder1.append(" [v] ")<br />
    filterStringBuilder1.append("-aspect 16:9 ")<br />
    filterStringBuilder1.append(finalVideo.absolutePath)<br />
    FFmpeg.execute(filterStringBuilder1.toString())<br />

But finding following logcat error:

 E/mobile-ffmpeg: [Parsed_concat_14 @ 0x748fc98bc0] <br />
 E/mobile-ffmpeg: Input link in1:v0 parameters (size 180x120, SAR 1:1) do not match the corresponding <br />output link in0:v0 parameters (100x140, SAR 1:1)<br />
 E/mobile-ffmpeg: [Parsed_concat_14 @ 0x748fc98bc0] <br />
 E/mobile-ffmpeg: Failed to configure output pad on Parsed_concat_14<br />
 E/mobile-ffmpeg: Error reinitializing filters!<br />
 E/mobile-ffmpeg: Failed to inject frame into filter network: Invalid argument<br />
 E/mobile-ffmpeg: Error while processing the decoded data for stream #2:0<br />
Chinez
  • 551
  • 2
  • 6
  • 29

1 Answers1

0

All inputs to the concat filter must have the same size (width x height) and aspect ratio. You do not need to concatenate. You need to overlay. Use animated scale with overlay instead. Simplified ffmpeg command-line example of 3 images scaling from 0 to 100% overlaid over a background image.

ffmpeg -loop 1 -t 10 -i background.jpg -loop 1 -i img1.png -loop 1 -i img2.jpg -loop 1 -i img3.jpg -filter_complex "[1]scale=eval=frame:w='min(iw*t,iw)':h=-1[img1];[2]scale=eval=frame:w='min(iw*t,iw)':h=-1[img2];[3]scale=eval=frame:w='min(iw*t,iw)':h=-1[img3];[0][img1]overlay=(W-w)/2:(H-h)/2:shortest=1:format=auto[bg];[bg][img2]overlay=shortest=1:format=auto[bg2];[bg2][img3]overlay=W-w:H-h:shortest=1:format=auto,format=yuv420p" output.mp4
llogan
  • 121,796
  • 28
  • 232
  • 243
  • Then how can I achieves different scaling along with custom position. My Scenario is I have a background image of screen size and I want to pour text and images within that to create a video, i.e. we have invitation cards. – najam ulhassan Jan 22 '21 at 04:49
  • @najamulhassan I don't completely understand your description of what you are trying to do. If you have an example image or video then that will be helpful. – llogan Jan 22 '21 at 18:10
  • Thanks, I am sharing youtube link to explore my need, kindly let me is this solution possible with FFMPEG, or any other solution https://youtu.be/m_C0dN3kLnU – najam ulhassan Jan 23 '21 at 10:27
  • Thanks sir for corporation, I will let you know after impplementations – najam ulhassan Jan 23 '21 at 21:06
  • Its working for me, kindly let me what does param [iw] in scale filter here w='min(iw*t,iw)' – najam ulhassan Jan 24 '21 at 08:05
  • @najamulhassan `iw` is *input width*, as mentioned in the [scale filter documentation](https://ffmpeg.org/ffmpeg-filters.html#scale). – llogan Jan 24 '21 at 19:25
  • Sir kindly check this ffmpeg comand, it is not altering the imzges(only overlay single image) -y -loop 1 -t 6 -i /image.png -s 745x736 -loop 1 -i /image_0.png -loop 1 -i /image_1.png g -filter_complex [1]scale=eval=frame:w='iw*min(170/iw,170/ih)':h='ih*min(170/iw,170/ih)',fade=in:st=0:d=2:alpha=1[img1];[2]scale=eval=frame:w='iw*min(272/iw,86/ih)':h='ih*min(272/iw,86/ih)',fade=in:st=3:d=6:alpha=1[img2];[0][img1]overlay=75:75:shortest=1:format=auto[bg1];[bg1][img2]overlay=575:201:shortest=1:format=auto,format=yuv420p /video_2021_Feb_01_18_27_33.mp4 – najam ulhassan Feb 01 '21 at 13:40
  • @najamulhassan Continuous, unrelated follow-up questions are discouraged. Should be asked as a new question. – llogan Feb 01 '21 at 17:43
  • can you guide me in this question regarding ffmpeg athttps://stackoverflow.com/questions/66097654/rescalling-and-reposition-images-in-ffmpeg-in-a-video-2 – najam ulhassan Feb 08 '21 at 07:52
  • hi sir, I want some knowledge could I use a gif to start of command previously I had done with -loop 1 -t 10 -i background.jpg now want replacement with -y -ignore_loop 0 -t 30 -i background.gif.... I had tried it but it not scalling or overlaying properly... images going out od -s 600, 700... – najam ulhassan Jul 03 '21 at 10:26
  • @najamulhassan Need to see your command, complete log, and link to input files. – llogan Jul 03 '21 at 16:51
  • https://stackoverflow.com/questions/68114221/overlay-and-scalling-issue-in-while-creating-video-using-mobile-ffmpeg-android I had made a new question here... I am getting problem when I started input with -ignore-loop and gif. In mobile-ffmpeg-full 4.3 – najam ulhassan Jul 04 '21 at 18:20