用于在android中合并mp4视频的FFMPEG命令问题

问题描述 投票:4回答:3

我正在使用以下FFMPEG命令在android中合并mp4视频。但合并后视频旋转90度。

我被困了两天。如果有任何想法,我会非常感激。

提前致谢 !

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"};
android video ffmpeg
3个回答
2
投票

以下是合并两个视频并保持两者纵横比的工作命令

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"};

0
投票

        String sourceFilePath1 = Environment.getExternalStorageDirectory().getPath()+"/SampleVideo1.mp4";
        String sourceFilePath2 = Environment.getExternalStorageDirectory().getPath()+"/SampleVideo2.mp4";
//        destFilePath = mp3File.getAbsolutePath();
        String path = Environment.getExternalStorageDirectory().getPath() + "/"
                + getResources().getString(R.string.namevideo) + System.currentTimeMillis() + ".mp4";

        FFmpeg ffmpeg = FFmpeg.getInstance(FfmpegAnimationActivity.this);


        try {
            ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
                @Override
                public void onFailure() {
                    Log.e("gc", "onFailure command");
                }
            });
        } catch (FFmpegNotSupportedException e) {
            Log.e("gc", "onSuccess command");
        }


        try {

//            String cmd[] = new String[]{"-y", "-i", sourceFilePath,
//                    "-vn", "-ar", "44100", "-ac", "2", "-b:a", "256k", "-f", "mp3", path};

            String cmd[] = new String[]{
           "-i", sourceFilePath1, "-i", sourceFilePath2, "-i", sourceFilePath2 , "-preset", "ultrafast",
            "-filter_complex", "[0:v] [0:a] [1:v] [1:a] [2:v] [2:a] concat=n=3:v=1:a=1 [v] [a]","-map","[v]","-map","[a]",path};

            ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

                @Override
                public void onStart() {
                    Log.e("gc", "Command Started");
                }

                @Override
                public void onProgress(String message) {
                    Log.e("gc", "onProgress" + message);
                }

                @Override
                public void onFailure(String message) {
                    Log.e("gc", "onFailure command" + message);
                }

                @Override
                public void onSuccess(String message) {
                    Log.e("gc", "onSuccess command" + message);
                }

                @Override
                public void onFinish() {
                    Log.e("gc", "onFinish command");
                }
            });

        } catch (FFmpegCommandAlreadyRunningException e) {
            // Handle if FFmpeg is already running
            e.printStackTrace();
        }

0
投票

这也是使用FFMpegAndroid的方法。

FFmpeg ffmpeg = FFmpeg.getInstance(context);
File pcmtowavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_pcm.wav");

File anotherwavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_combined.wav");

File outputFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_outputFile.wav");

String[] cmd = { "-i" , pcmtowavTempFile.toString(), "-i", anotherwavTempFile.toString(), "-filter_complex", "amix=inputs=2:duration=first:dropout_transition=3", outputFile.toString()};
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

    @Override
    public void onSuccess(String message) {
        super.onSuccess(message);
        combiningSuccessful();
    }
    @Override
    public void onFailure(String message) {
        super.onFailure(message);
        onError(message);
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.