簡體   English   中英

用於在android中合並mp4視頻的FFMPEG命令問題

[英]FFMPEG command issue for merging mp4 videos in android

我正在使用以下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"};

以下是合並兩個視頻並保持兩者縱橫比的工作命令

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

  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(); } 

這也是一種在Android上使用FFMpeg的方法。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM