【问题标题】:How to trim video with start and end pos of seekbar using FFmpeg android?如何使用FFmpeg android修剪带有seekbar的开始和结束位置的视频?
【发布时间】:2020-09-21 16:54:50
【问题描述】:

String[] cmd = new String[]{"-ss", startTrim + ".00", "-t", endTrim + ".00", "-noaccurate_seek", "-i", videoPath, " -codec", "copy", "-avoid_negative_ts", "1", outputAudioMux};

【问题讨论】:

    标签: ffmpeg video-editing


    【解决方案1】:
     private void trimVideo(ProgressDialog progressDialog) {
    
        outputAudioMux = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath()
                + "/VidEffectsFilter" + "/" + new SimpleDateFormat("ddMMyyyy_HHmmss").format(new Date())
                + "filter_apply.mp4";
    
        if (startTrim.equals("")) {
            startTrim = "00:00:00";
        }
    
        if (endTrim.equals("")) {
            endTrim = timeTrim(player.getDuration());
        }
    
        String[] cmd = new String[]{"-ss", startTrim + ".00", "-t", endTrim + ".00", "-noaccurate_seek", "-i", videoPath, "-codec", "copy", "-avoid_negative_ts", "1", outputAudioMux};
    
    
        execFFmpegBinary1(cmd, progressDialog);
    }
    
    
    
    
    
        private void execFFmpegBinary1(final String[] command, ProgressDialog prpg) {
    
        ProgressDialog progressDialog = prpg;
    
        try {
            ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
                @Override
                public void onFailure(String s) {
                    progressDialog.dismiss();
                    Toast.makeText(PlayerActivity.this, "Fail to generate video", Toast.LENGTH_SHORT).show();
                    Log.d(TAG, "FAILED with output : " + s);
                }
    
                @Override
                public void onSuccess(String s) {
                    Log.d(TAG, "SUCCESS wgith output : " + s);
    
    
                    String finalPath = outputAudioMux;
                    videoPath = outputAudioMux;
                    Toast.makeText(PlayerActivity.this, "Storage Path =" + finalPath, Toast.LENGTH_SHORT).show();
    
                    Intent intent = new Intent(PlayerActivity.this, ShareVideoActivity.class);
                    intent.putExtra("pathGPU", finalPath);
                    startActivity(intent);
                    finish();
                    MediaScannerConnection.scanFile(PlayerActivity.this, new String[]{finalPath}, new String[]{"mp4"}, null);
    
                }
    
                @Override
                public void onProgress(String s) {
                    Log.d(TAG, "Started gcommand : ffmpeg " + command);
                    progressDialog.setMessage("Please Wait video triming...");
                }
    
                @Override
                public void onStart() {
                    Log.d(TAG, "Startedf command : ffmpeg " + command);
    
                }
    
                @Override
                public void onFinish() {
                    Log.d(TAG, "Finished f command : ffmpeg " + command);
                    progressDialog.dismiss();
                }
            });
        } catch (FFmpegCommandAlreadyRunningException e) {
            // do nothing for now
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-02-20
      • 2013-08-28
      • 2018-11-03
      • 1970-01-01
      • 2013-09-17
      • 1970-01-01
      • 2016-08-19
      • 2015-10-11
      • 2020-01-30
      相关资源
      最近更新 更多