Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to make image compression and saving faster on Android?

The situation

I should show 200-350 frames animation in my application. Images have 500x300ish resolution. If user wants to share animation, i have to convert it to Video. For convertion i am using ffmpeg command.

ffmpeg -y -r 1 -i /sdcard/videokit/pic00%d.jpg -i /sdcard/videokit/in.mp3 -strict experimental -ar 44100 -ac 2 -ab 256k -b 2097152 -ar 22050 -vcodec mpeg4 -b 2097152 -s 320x240 /sdcard/videokit/out.mp4

To convert images to video ffmpeg wants actual files not Bitmap or byte[].

Problem

Compressing bitmaps to image files taking to much time. 210 image convertion takes about 1 minute to finish on average device(HTC ONE m7). Converting image files to mp4 takes about 15 seconds on the same device. All together user have to wait about 1.5 minutes.

What i have tried

  1. I changed comrpession format form PNG to JPEG(1.5 minute result is achieved with JPEG compression(quality=80),with PNG it takes about 2-2.5 minutes) success
  2. Tried to find how pass byte[] or bitmap to ffmpeg - no succes.

QUESTION

  1. Is there any way(library (even native)) to make saving process faster.
  2. Is there any way to pass byte[] or Bitmap objects (i mean png file decompressed to Android Bitmap Class Object) to ffmpeg library video creating method
  3. Is there any other working library which will create mp4(or any supported format(supported by main Social Networks)) from byte[] or Bitmap objects in about 30 seconds(for 200 frames).
like image 957
Arsen Sench Avatar asked Oct 30 '22 18:10

Arsen Sench


1 Answers

You can convert Bitmap (or byte[]) to YUV format quickly, using renderscript (see https://stackoverflow.com/a/39877029/192373). You can pass these YUV frames to ffmpeg library (as suggests halfelf), or use the built-in native MediaCodec which uses dedicated hardware on modt devices (but compression options are less flexible than all-software ffmpeg).

like image 71
Alex Cohn Avatar answered Nov 15 '22 04:11

Alex Cohn