title: How to Merge Multiple video files with different resolution, make padding for the low resolution video in android FFMPEG
body: <p>I want to merge multiple videos with different resolutions. if the resolution is low than any other video, it should make a black padding around the low resolution video.</p>
  <p>I tried this command</p>
  <pre><code>    var highestVideoWidth: Int = 0
      var highestVideoHeight: Int = 0
  
      val mlisst: MutableList&lt;String&gt; = ArrayList()
      mlisst.clear()
      mlisst.add(&quot;-i&quot;)
      for (i in trimmedPaths.indices) {
          if (highestVideoWidth &lt; editedVideosList[i].videoWidth &amp;&amp; highestVideoHeight &lt; editedVideosList[i].videoHeight) {
              highestVideoWidth = editedVideosList[i].videoWidth
              highestVideoHeight = editedVideosList[i].videoHeight
          }
  
          mlisst.add(trimmedPaths[i])
          if (i &lt; trimmedPaths.size - 1)
              mlisst.add(&quot;-i&quot;)
      }
      mlisst.add(&quot;-filter_complex&quot;)
      val fc = StringBuilder()
  
      for (i in trimmedPaths.indices) {
  
          if (editedVideosList[i].videoWidth == highestVideoWidth &amp;&amp; editedVideosList[i].videoHeight == highestVideoHeight){
              fc.append(&quot;[$i:v]scale=${editedVideosList[i].videoWidth}x${editedVideosList[i].videoHeight},setsar=1:1[v$i];&quot;)
          }else{
              fc.append(&quot;[$i:v]scale=iw*min($highestVideoWidth/iw,${highestVideoHeight}/ih):ih*min(${highestVideoWidth}/iw,${highestVideoHeight}/ih),&quot;)
              fc.append(&quot;pad=${highestVideoWidth}:${highestVideoHeight}&quot;)
              fc.append(&quot;:(${highestVideoWidth}-iw*min(${highestVideoWidth}/iw,${highestVideoHeight}/ih))/2&quot;)
              fc.append(&quot;:(${highestVideoHeight}-ih*min(${highestVideoWidth}/iw,${highestVideoHeight}/ih))/2,setsar1:1[v$i];&quot;)
          }
      }
  
      for (i in trimmedPaths.indices) {
          fc.append(&quot;[v$i][$i:a]&quot;)
      }
      fc.append(&quot;concat=unsafe=1:n=${trimmedPaths.size}:v=1:a=1&quot;)
      mlisst.add(fc.toString())
      mlisst.add(&quot;-r&quot;)
      mlisst.add(&quot;50&quot;)
      mlisst.add(&quot;-preset&quot;)
      mlisst.add(&quot;ultrafast&quot;)
      mlisst.add(finalMergedVideoPath)
  </code></pre>
  <p>but this gives me this error</p>
  <p><a href="https://i.stack.imgur.com/1zH33.png" rel="nofollow noreferrer">Invalid size 'iw*min(1074/iw'</a>
  I found the command some where i modified it to my use but now i am not sure. Here is the command:  <code>complexCommand = new String[]{&quot;-y&quot;, &quot;-i&quot;, file1.toString(), &quot;-i&quot;, file2.toString(), &quot;-strict&quot;, &quot;experimental&quot;, &quot;-filter_complex&quot;,&quot;[0:v]scale=1920x1080,setsar=1:1[v0];[1:v] scale=iw*min(1920/iw\\,1080/ih):ih*min(1920/iw\\,1080/ih), pad=1920:1080:(1920-iw*min(1920/iw\\,1080/ih))/2:(1080-ih*min(1920/iw\\,1080/ih))/2,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1&quot;,&quot;-ab&quot;, &quot;48000&quot;, &quot;-ac&quot;, &quot;2&quot;, &quot;-ar&quot;, &quot;22050&quot;, &quot;-s&quot;, &quot;1920x1080&quot;, &quot;-vcodec&quot;, &quot;libx264&quot;,&quot;-crf&quot;,&quot;27&quot;,&quot;-q&quot;,&quot;4&quot;,&quot;-preset&quot;, &quot;ultrafast&quot;, rootPath + &quot;/output.mp4&quot;};</code></p>
  <p>If anyone can help thanks in advance.
  <a href="https://video.stackexchange.com/q/21567">Here is the link to the question i followed</a></p>