0

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.

I tried this command

    var highestVideoWidth: Int = 0
    var highestVideoHeight: Int = 0

    val mlisst: MutableList<String> = ArrayList()
    mlisst.clear()
    mlisst.add("-i")
    for (i in trimmedPaths.indices) {
        if (highestVideoWidth < editedVideosList[i].videoWidth && highestVideoHeight < editedVideosList[i].videoHeight) {
            highestVideoWidth = editedVideosList[i].videoWidth
            highestVideoHeight = editedVideosList[i].videoHeight
        }

        mlisst.add(trimmedPaths[i])
        if (i < trimmedPaths.size - 1)
            mlisst.add("-i")
    }
    mlisst.add("-filter_complex")
    val fc = StringBuilder()

    for (i in trimmedPaths.indices) {

        if (editedVideosList[i].videoWidth == highestVideoWidth && editedVideosList[i].videoHeight == highestVideoHeight){
            fc.append("[$i:v]scale=${editedVideosList[i].videoWidth}x${editedVideosList[i].videoHeight},setsar=1:1[v$i];")
        }else{
            fc.append("[$i:v]scale=iw*min($highestVideoWidth/iw,${highestVideoHeight}/ih):ih*min(${highestVideoWidth}/iw,${highestVideoHeight}/ih),")
            fc.append("pad=${highestVideoWidth}:${highestVideoHeight}")
            fc.append(":(${highestVideoWidth}-iw*min(${highestVideoWidth}/iw,${highestVideoHeight}/ih))/2")
            fc.append(":(${highestVideoHeight}-ih*min(${highestVideoWidth}/iw,${highestVideoHeight}/ih))/2,setsar1:1[v$i];")
        }
    }

    for (i in trimmedPaths.indices) {
        fc.append("[v$i][$i:a]")
    }
    fc.append("concat=unsafe=1:n=${trimmedPaths.size}:v=1:a=1")
    mlisst.add(fc.toString())
    mlisst.add("-r")
    mlisst.add("50")
    mlisst.add("-preset")
    mlisst.add("ultrafast")
    mlisst.add(finalMergedVideoPath)

but this gives me this error

Invalid size 'iw*min(1074/iw' I found the command some where i modified it to my use but now i am not sure. Here is the command: complexCommand = new String[]{"-y", "-i", file1.toString(), "-i", file2.toString(), "-strict", "experimental", "-filter_complex","[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","-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "1920x1080", "-vcodec", "libx264","-crf","27","-q","4","-preset", "ultrafast", rootPath + "/output.mp4"};

If anyone can help thanks in advance. Here is the link to the question i followed

  • As with many ffmpeg on Android issues on Stack Overflow it's a quoting/escaping issue. Not a problem with ffmpeg itself, but you are giving ffmpeg a bad command. – llogan Feb 12 '21 at 21:42
  • Yes, there is some issue with the command. Can you please help me with command? – Osama aman Feb 15 '21 at 09:04
  • No, sorry. I don't have any experience with Android. – llogan Feb 15 '21 at 20:09
  • No, can you help me about ffmpeg command to merge different resolution videos in a single one? – Osama aman Feb 16 '21 at 07:11
  • See [How to concatenate videos in ffmpeg with different attributes?](https://stackoverflow.com/a/57367243/) – llogan Feb 16 '21 at 17:49

0 Answers0