How to concat or merge two or more video files in Android?

前端 未结 3 1273
北海茫月
北海茫月 2020-12-05 08:45

I want to merge two or more video files (they may be two mp4 or two 3gp, or any other format).

3条回答
  •  一向
    一向 (楼主)
    2020-12-05 09:25

    I will share both Java & Kotlin Code

    Internally it uses FFmpeg but its lightweight.The easiest way to Add two videos of different types or codec, framerate, and bitrate is to use EpMedia librabry.

    Grade Dependency

    implementation 'com.github.yangjie10930:EpMedia:v0.9.5'
    

    Kotlin Code

        val epVideos = ArrayList()
        epVideos.add(EpVideo("/storage/emulated/0/Contact/1.mp4")) // Video 1 Example
        epVideos.add(EpVideo("/storage/emulated/0/Contact/2.mp4")) // Video 2 Exmaple
        val outputOption = EpEditor.OutputOption ("/storage/emulated/0/merge.mp4"); //Output
        outputOption.setWidth(720) // output video width, default 480
        outputOption.setHeight(1280)
        outputOption.frameRate =  25 ; // output video frame rate, default 30
    
        EpEditor.merge(epVideos,outputOption,object:OnEditorListener{
            override fun onSuccess() {
    
            }
    
            override fun onFailure() {
    
            }
    
    
            override fun onProgress(progress: Float) {
                Log.d("Progress","$progress")
            }
    
        })
    

    Java Code

     private void mergeVideos() {
        ArrayList epVideos =  new  ArrayList<>();
        epVideos.add(new EpVideo (file2)); // Video 1
        epVideos.add(new EpVideo (file1)); // Video 2
        EpEditor. OutputOption outputOption =new EpEditor.OutputOption(fileOutput);
        outputOption.setWidth(720);
        outputOption.setHeight(1280);
        outputOption.frameRate = 25 ;
        outputOption.bitRate = 10 ;
        EpEditor.merge(epVideos, outputOption, new  OnEditorListener() {
            @Override
            public  void  onSuccess () {
                Log.d("Status","Success");
    
            }
    
            @Override
            public  void  onFailure () {
    
            }
    
            @Override
            public  void  onProgress ( float  progress ) {
                // Get processing progress here
                Log.d("Progress",""+progress);
            }
        });
    
    }
    

提交回复
热议问题