如何在Android中混合.mp3和.mp4文件并获取mp4视频。以及如何管理视频和添加的音乐.mp3文件的音量

时间:2019-06-22 11:52:47

标签: android video-editing

我现在正在用android java制作视频编辑应用程序,我无法将视频和音频,.mp3和.mp4文件混合在一起,我已经阅读了很多堆栈溢出和github的答案,但我无法获得正确的答案, 我想混合mp3和mp4文件并获取mp4视频并控制两者的音量,我想添加背景音乐,请帮助

先谢谢您

我已经阅读了很多有关堆栈溢出和github的答案,但我无法获得正确的答案

private void audiomix() {

        File moviesDir = Environment.getExternalStorageDirectory();
        String filePrefix = "mixur_video";
        String fileExtn = ".mp4";
        yourRealPath = videopath;

        File dest = new File(moviesDir, filePrefix + fileExtn);
        int fileNo = 0;
        while (dest.exists()) {
            fileNo++;
            dest = new File(moviesDir, filePrefix + fileNo + fileExtn);
        }

        mixerpath = dest.getAbsolutePath();
        String[] cmd1 = {"-i " + yourRealPath + " -i " + audiopath + " -shortest -threads 0 -preset ultrafast -strict -2 " + mixerpath};
        Log.d(TAG, "audiomix: " + cmd1);
        execFFmpegBinary(cmd1);

    }
 private void loadFFMpegBinary() {
        try {
            if (ffmpeg == null) {
                Log.d(TAG, "ffmpeg : era nulo");
                ffmpeg = FFmpeg.getInstance(this);
            }
            ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
                @Override
                public void onFailure() {
                    showUnsupportedExceptionDialog();
                }

                @Override
                public void onSuccess() {
                    Log.d(TAG, "ffmpeg : correct Loaded");
                }
            });
        } catch (FFmpegNotSupportedException e) {
            showUnsupportedExceptionDialog();
        } catch (Exception e) {
            Log.d(TAG, "EXception no controlada : " + e);
        }
    }

    private void showUnsupportedExceptionDialog() {
        new AlertDialog.Builder(MainActivity.this)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle("Not Supported")
                .setMessage("Device Not Supported")
                .setCancelable(false)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        MainActivity.this.finish();
                    }
                })
                .create()
                .show();

    }

    private void execFFmpegBinary(final String[] command) {
        try {
            ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
                @Override
                public void onFailure(String s) {
                    Log.d(TAG, "FAILED with output : " + s);
                }

                @Override
                public void onSuccess(String s) {
                    Log.d(TAG, "SUCCESS with output : " + s);

                        Intent intent = new Intent(MainActivity.this, VideoResult.class);
                        startActivity(intent);
                }

                @Override
                public void onProgress(String s) {
                    Log.d(TAG, "Started command : ffmpeg " + command);

                    progressDialog.setMessage("Please Wait Proccessing the video");
                    Log.d(TAG, "progress : " + s);
                }

                @Override
                public void onStart() {
                    Log.d(TAG, "Started command : ffmpeg " + command);
                    progressDialog.setMessage("Processing...");
                    progressDialog.show();
                }

                @Override
                public void onFinish() {
                    Log.d(TAG, "Finished command : ffmpeg " + command);

                    progressDialog.dismiss();
                }
            });
        } catch (FFmpegCommandAlreadyRunningException e) {
            // do nothing for now
        }
    }

我想混合mp3和mp4文件并获取mp4视频并控制两者的音量,我想添加背景音乐,请帮助

0 个答案:

没有答案
相关问题