How to reduce video size with java/kotlin on Android?

55
September 18, 2019, at 09:30 AM

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?

Answer 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);
                      }
                  })
READ ALSO
Google sheets to salesforce

Google sheets to salesforce

Im trying to connect data in google sheet to salesforce

17
How to retrieve data from my java code to html?

How to retrieve data from my java code to html?

I am working on a small webpage projectI wrote my functions code with java, and now I am having problems to display the data I got to HTML to display it in a webpage

43
Bootrap-Select can&#39;t be selected on multiple value

Bootrap-Select can't be selected on multiple value

I have a modal with input like this:

46