【问题标题】:FFMPEG command issue for merging mp4 videos in android用于在 android 中合并 mp4 视频的 FFMPEG 命令问题
【发布时间】:2018-09-07 21:31:53
【问题描述】:

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

【问题讨论】:

  • 任何解决方案??我试过你的命令,但它给了我 java.io.IOException: No such file or directory
  • 检查文件路径是否正确。它没有获取您的视频文件。同样的命令在我的最后工作正常。
  • 在android中加载ffmpeg二进制文件之前我是直接执行命令
  • 那么现在,它工作正常吗?
  • 是的,它工作正常,但我使用不同的命令

标签: android video ffmpeg


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      这也是将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);
          }
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-08-11
        • 2019-10-24
        • 2023-03-05
        • 2012-05-24
        • 1970-01-01
        • 2016-05-19
        • 2012-05-22
        • 2012-12-28
        相关资源
        最近更新 更多