Make Android Video editing App using Phoenix SDK

If you want to make video Android editing App then you can use Phoenix to make video Editing App

The selection, editing and compression of pictures/videos are common requirements in daily development. Phoenix fully implements these functions and provides elegant calling methods. Phoenix’s core functions are implemented based on Kotlin, and the outer interface is implemented based on Java, which facilitates the call between Kotlin and Java.

Features

  • The functions are independent of each other, and the realization of each function depends on the agreed interface, and is independent of each other. Developers do not need to bring in a bunch of dependencies in order to introduce a certain function.
  • A high degree of UI customization, with four built-in color schemes, developers can also customize their own UI through simple configuration of simple style files.
  • Convenience of calling, only need to call the enableXXX(true) method to enable a certain function, and the result is uniformly obtained in MediaEntity.
  • The library is light and small in size, and the video compression is implemented based on the system’s MediaCodec, with fast compression speed and no additional dependencies.
  • RxJava is well supported. Each function provides synchronous and asynchronous realization, which is convenient for developers to use RxJava to combine and nest functions.
  • ImageLoader can be configured to customize the image loading scheme required by the project.
  • Good version compatibility, runtime permissions and other content have been processed for compatibility.

Function

  • Photograph
  • Record video
  • Picture selection
  • Picture Preview
  • Picture compression
  • Picture marking, mapping, smearing and cropping
  • Video selection
  • Video preview
  • Video compression

theme

  • Default theme
  • Orange main image
  • Red theme
  • Blue theme

Express start

Add dependency


implementation 'com.github.guoxiaoxing:phoenix:1.0.15'

implementation 'com.github.guoxiaoxing:phoenix-compress-picture:1.0.15'

implementation 'com.github.guoxiaoxing:phoenix-compress-video:1.0.15'

Call function

initialization

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        Phoenix.config()
                .imageLoader(new ImageLoader() {
                    @Override
                    public void loadImage(Context mContext, ImageView imageView
                                                , String imagePath, int type) {
                        Glide.with(mContext)
                                .load(imagePath)
                                .into(imageView);
                    }
                });
    }
}

Turn on function

Phoenix.with()
        .theme ( PhoenixOption . theme_default ) // theme 
        .filetype ( MimeType . ofall ()) // display the file type pictures, videos, pictures and videos 
        .maxPickNumber ( 10 ) // maximum number of selected 
        .minPickNumber ( 0 ) // Minimum Select the 
        number.spanCount( 4 ) // Display the number per line. 
        enablePreview( true ) // Whether to enable preview. 
        enableCamera( true ) // Whether to enable taking pictures. 
        enableAnimation( true )// Select the interface picture click effect. 
        enableCompress( true ) // Whether to enable compression.compressPictureFilterSize 
        ( 1024 ) // How many kb pictures are not compressed.compressVideoFilterSize 
        ( 2018 ) // How many kb videos are not compressed.thumbnailHeight 
        ( 160 ) // select interface picture height 
        .thumbnailWidth ( 160 ) // selection screen image width 
        .enableClickSound ( false ) // whether to open the clicking sound 
        .pickedMediaList (mMediaAdapter . getData ()) // selected picture data
        .videoFilterTime( 0 ) // How many seconds to display the 
        video.mediaFilterSize( 10000 ) // How many pictures/videos below kb to display, the default is 0, which means there is no limit. 
         // If it is used in Activity, then pass Activity, if it is Use it in Fragment to pass Fragment.start 
        ( MainActivity . This , PhoenixOption . TYPE_PICK_MEDIA , REQUEST_CODE );

Get results

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
     
        List<MediaEntity> result = Phoenix.result(data);
        mMediaAdapter.setData(result);
    }
}

In addition, Phoenix has built-in image compression library and video compression library, both of which can be called separately.

Picture compression

Synchronization method

File file = new File(localPath);
try {
    File compressFIle = PictureCompressor.with(mContext)
            .savePath(mContext.getCacheDir().getAbsolutePath())
            .load(file)
            .get();
    if (compressFIle != null) {
        String compressPath = compressFIle.getAbsolutePath();
    }
} catch (IOException e) {
    e . printStackTrace ();
}

Asynchronous method

File file = new File(localPath);
PictureCompressor.with(mContext)
        .load(file)
        .setCompressListener(new OnCompressListener() {
            @Override
            public void onStart() {
            }

            @Override
            public void onSuccess(File file) {
                String compressPath = file.getAbsolutePath();
            }

            @Override
            public void onError(Throwable e) {
            }
        }).launch();

Video compression

Synchronization method

final File compressFile;
try {
    File compressCachePath = new File(mContext.getCacheDir(), "outputs");
    compressCachePath.mkdir();
    compressFile = File.createTempFile("compress", ".mp4", compressCachePath);
} catch (IOException e) {
    Toast.makeText(mContext, "Failed to create temporary file.", Toast.LENGTH_LONG).show();
    return null;
}

try {
   String compressPath =  VideoCompressor.with().syncTranscodeVideo(mediaEntity.getLocalPath(), compressFile.getAbsolutePath(),
            MediaFormatStrategyPresets.createAndroid480pFormatStrategy());
} catch (IOException e) {
    e . printStackTrace ();
}

Asynchronous method

final File compressFile;
try {
    File compressCachePath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "phoenix");
    compressCachePath.mkdir();
    compressFile = File.createTempFile("compress", ".mp4", compressCachePath);
} catch (IOException e) {
    Toast.makeText(mContext, "Failed to create temporary file.", Toast.LENGTH_LONG).show();
    return;
}
VideoCompressor.Listener listener = new VideoCompressor.Listener() {
    @Override
    public void onTranscodeProgress(double progress) {
    }

    @Override
    public void onTranscodeCompleted() {
        String compressPath = compressFile.getAbsolutePath();
    }

    @Override
    public void onTranscodeCanceled() {

    }

    @Override
    public void onTranscodeFailed(Exception exception) {
        
    }
};
try {
    VideoCompressor.with().asyncTranscodeVideo(mediaEntity.getLocalPath(), compressFile.getAbsolutePath(),
            MediaFormatStrategyPresets.createAndroid480pFormatStrategy(), listener);
} catch (IOException e) {
    e . printStackTrace ();
}

Video compression test data

Phone modelSource video durationSource video sizeCompressed video sizeCompression takes time
Mi 460s55.67MB5.56MB20.17s
Glory 760s68.37MB6.22MB18.83s
oppo r960s55.57MB5.35MB38.27s
Video compression test data

It can be seen that for 60s video, the compression time is controlled between 18s~22s, and the time for mobile phones with good performance is shorter. In addition, the compression provides 480p, 720p and other specifications of compression parameters.

Leave a Comment