If you need to flip the video recording and save it into internal storage then you can use the Mp4Composer dependency in android studio.
First you need to add the dependency,
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.MasayukiSuda:Mp4Composer-android:v0.4.1'
}
The following is a sample code for the same with vertical flip. You can flip it by making flipVertical(true)
. Also you can flip it horizontally by flipHorizontal(true)
.
private void flipVideo(String path, String destinationPath) {
new Mp4Composer(sourcePath, destinationPath)
.size(1280, 720)
.fillMode(FillMode.PRESERVE_ASPECT_FIT)
//.flipHorizontal(true)
.flipVertical(true)
// .rotation(Rotation.ROTATION_270)
//.filter(glFilter)
//.mute(muteCheckBox.isChecked())
//.timeScale(2f)
//.changePitch(false)
//.trim(2000, 5000)
.listener(new Mp4Composer.Listener() {
@Override
public void onProgress(double progress) {
Log.d("app_log", "onProgress = " + progress);
runOnUiThread(() -> progressBar.setProgress((int) (progress * 100)));
}
@Override
public void onCompleted() {
Log.d("app_log", "onCompleted(): video conversion completed");
runOnUiThread(() -> {
Toast.makeText(CameraActivity.this, "video saved under " + destinationPath, Toast.LENGTH_SHORT).show();
});
}
@Override
public void onCanceled() {
}
@Override
public void onCurrentWrittenVideoTime(long timeUs) {
}
@Override
public void onFailed(Exception exception) {
Log.e("app_log", "onFailed() " + exception.getMessage());
}
})
.start();
}
Call the method like this,
flipVideo(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/video_input.mp4", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/video_output.mp4");
For more: Mp4Composer-android