且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

FFMPEG在Android中合并mp4视频的命令问题

更新时间:2023-01-25 16:58:40

下面是合并两个视频和维护的工作命令宽高比

  complexCommand = new String [] { -  y,-i,file1.toString() ,-i,file2.toString(),-strict,experimental,-filter_complex,
[0: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,setar = 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 *分钟(1920 / iw\\,1080 / 1H))/ 2,setsar = 1:1 [V1]; [V0] [0:一个] [V1] [1:一] concat = n = 2:v = 1:a = 1,
-ab,48000,-ac,2,-ar,22050 ,1920×1080,-vcodec,libx264,-crf,27,-q,4,-preset,ultrafast,rootPath +/output.mp4 };


I am using following FFMPEG command for merging mp4 videos in android. But video is rotated 90 degree after merging.

I am stuck from two days .If any idea it would be highly appriciated.

Thanks in Advance !

complexCommand = new String[] {
                "ffmpeg",
                "-y",
                "-i",
                recordpath + "Vid1.mp4",
                "-i",
                recordpath + "Vid2.mp4",
                "-strict",
                "experimental",
                "-filter_complex",
                "[0:v]scale=w=640:h=480[v1]; [1:v]scale=w=640:h=480[v2]; [v1][0:a][v2][1:a] concat=n=2:v=1:a=1 [v] [a]",
                "-map", "[v]", "-map", "[a]", "-b", "2097k", "-vcodec",
                "mpeg4","-ab","64k","-ac","2","-ar","22050", recordpath + "Outputnew.mp4"};

Below is the working command for merging two videos and maintaining aspect ratio of both

complexCommand = new String[]{"-y", "-i", file1.toString(), "-i", file2.toString(), "-strict", "experimental", "-filter_complex",
                "[0: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[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"};