I want reduce the video size at Android Studio and for upload to PlayStore needs to be compatible for 64 bits arquitecture, I tried before with ffmpeg and it compress mp4 succefully but take longer time and this solution with 3gp not include the audio. Theres another option or library to compress mp4 and 3gp with audio and video?
Asked
Active
Viewed 1.4k times
3 Answers
3
Here is another library to compress videos. This library can compress videos in low, medium and high quality. Usage example:
VideoCompress.compressVideoMedium("/storage/emulated/0/Movies/source.mp4",
"/storage/emulated/0/Movies/Compressed/compressed.mp4",
new VideoCompress.CompressListener() {
@Override
public void onStart() {
// Compression is started.
}
@Override
public void onSuccess() {
// Compression is successfully finished.
}
@Override
public void onFail() {
// Compression is failed.
}
@Override
public void onProgress(float percent) {
// Compression is in progress.
}
});

Yamashiro Rion
- 1,778
- 1
- 20
- 31
-
1This library drops audio on conversion for me – Gibolt Jan 23 '20 at 01:04
-
1What is dependency of this video compressor. I am not getting dependency from the link you given – John dahat Jun 10 '20 at 12:34
-
1@Johndahat, unfortunately, this library is not in Maven or some else repository. But the project has a Gradle module named `videocompressor`, it's the library itself. You can just copy the source code from there. [Here is](https://github.com/fishwjy/VideoCompressor/tree/master/videocompressor/src/main/java/com/vincent/videocompressor) the path to the source code. – Yamashiro Rion Jun 10 '20 at 18:12
-
Any solution, why after compressing the video it drops the audio? – Prince Dholakiya Aug 09 '22 at 18:35
2
You may like to use the following library, right now it is actively maintained and may help with the latest android apis.
https://github.com/AbedElazizShe/LightCompressor
Usage as follows (Java)
implementation 'com.github.AbedElazizShe:LightCompressor:1.1.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
public static void compressVideo(Context context,
Activity activity,
ArrayList<Uri> videoUris) {
VideoCompressor.start(context,
// => This is required
videoUris,
// => Source can be provided as content uris
true,
// => isStreamable
Environment.DIRECTORY_MOVIES,
// => the directory to save the compressed video(s)
new CompressionListener() {
@Override
public void onSuccess(int i,
long l,
@org.jetbrains.annotations.Nullable String s) {
// On Compression success
Log.d("TAG",
"videoCompress i: " +i);
Log.d("TAG",
"videoCompress l: " +l);
Log.d("TAG",
"videoCompress s: " +s);
}
@Override
public void onStart(int i) {
// Compression start
}
@Override
public void onFailure(int index,
String failureMessage) {
// On Failure
}
@Override
public void onProgress(int index,
float progressPercent) {
// Update UI with progress value
activity.runOnUiThread(new Runnable() {
public void run() {
}
});
}
@Override
public void onCancelled(int index) {
// On Cancelled
}
},
new Configuration(VideoQuality.LOW,
24, /*frameRate: int, or null*/
false, /*isMinBitrateCheckEnabled*/
null, /*videoBitrate: int, or null*/
false, /*disableAudio: Boolean, or null*/
false, /*keepOriginalResolution: Boolean, or null*/
360.0, /*videoWidth: Double, or null*/
480.0 /*videoHeight: Double, or null*/));
}
Configuration values
VideoQuality: VERY_HIGH (original-bitrate * 0.6) , HIGH (original-bitrate * 0.4), MEDIUM (original-bitrate * 0.3), LOW (original-bitrate * 0.2), OR VERY_LOW (original-bitrate * 0.1)
isMinBitrateCheckEnabled: this means, don't compress if bitrate is less than 2mbps
frameRate: any fps value
videoBitrate: any custom bitrate value
disableAudio: true/false to generate a video without audio. False by default.
keepOriginalResolution: true/false to tell the library not to change the resolution.
videoWidth: custom video width.
videoHeight: custom video height.

DragonFire
- 3,722
- 2
- 38
- 51
1
You can do so using this library: https://github.com/tcking/GiraffeCompressor
GiraffeCompressor.init(context);
//step 4: using compressor
GiraffeCompressor.create() //two implementations: mediacodec and ffmpeg,default is mediacodec
.input(inputFile) //set video to be compressed
.output(outputFile) //set compressed video output
.bitRate(bitRate)//set bitrate 码率
.resizeFactor(Float.parseFloat($.id(R.id.et_resize_factor).text()))//set video resize factor 分辨率缩放,默认保持原分辨率
.watermark("/sdcard/videoCompressor/watermarker.png")//add watermark(take a long time) 水印图片(需要长时间处理)
.ready()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<GiraffeCompressor.Result>() {
@Override
public void onCompleted() {
$.id(R.id.btn_start).enabled(true).text("start compress");
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
$.id(R.id.btn_start).enabled(true).text("start compress");
$.id(R.id.tv_console).text("error:"+e.getMessage());
}
@Override
public void onNext(GiraffeCompressor.Result s) {
String msg = String.format("compress completed \ntake time:%s \nout put file:%s", s.getCostTime(), s.getOutput());
msg = msg + "\ninput file size:"+ Formatter.formatFileSize(getApplication(),inputFile.length());
msg = msg + "\nout file size:"+ Formatter.formatFileSize(getApplication(),new File(s.getOutput()).length());
System.out.println(msg);
$.id(R.id.tv_console).text(msg);
}
})

Jagar
- 777
- 9
- 24
-
1Hi. Thanks for comment, I tried with Giraffe Compressor before, but for upload to PlayStore needs to be compatible with 64 bits architecture. Now, I updated my ask, sorry. – Pablo DbSys Sep 17 '19 at 23:58
-
@PabloDbSys Did you try this: https://stackoverflow.com/a/40861147/12053756 – Jagar Sep 18 '19 at 00:03