如何合并多个不同分辨率的视频文件,为android FFMPEG中的低分辨率视频进行填充

问题描述

我想合并多个不同分辨率的视频。如果分辨率低于任何其他视频,则应在低分辨率视频周围制作黑色填充。

我试过这个命令

    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)

但这给了我这个错误

Invalid size 'iw*min(1074/iw' 我在某些地方找到了该命令,我将其修改为我的用途,但现在我不确定。这是命令:complexCommand = new String[]{"-y","-i",file1.toString(),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"};

如果有人可以提供帮助,请提前致谢。 Here is the link to the question i followed

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)