1

I have recently used ffmpeg library for android to compress the video of length 10 seconds and size nearly 25 MB. Following are the commands i tried to use:

ffmpeg -i /video.mp4 -vcodec h264 -b:v 1000k -acodec mp2 /output.mp4

OR

ffmpeg -i input.mp4 -vcodec h264 -crf 20 output.mp4

Both of the commands were too slow. I canceled the task before it completed because it was taking too much time. It took more than 8 minutes to process JUST 20% of the video. Time is really critical for me so i can't opt for ffmpeg. I have following question:

  • Is there something wrong with the command or ffmpeg is slow anyway?
  • If its slow then is there any other well documented and reliable way/library for video compression that i can use in android?
Qandeel Abbassi
  • 999
  • 7
  • 31
  • An MP4 is already compressed. – CommonsWare Apr 20 '17 at 20:43
  • Can't i reduce its size? – Qandeel Abbassi Apr 20 '17 at 20:44
  • You can reduce its resolution. You can reduce its frame rate. You can chop off part of it (e.g., trim its length to X seconds). None of those represent compression, any more than deleting files from a ZIP archive represent "compressing" that ZIP archive. Transcoding a video -- what you are doing with `ffmpeg`, and what would be involved in changing the resolution or frame rate -- is slow. – CommonsWare Apr 20 '17 at 20:50
  • So what should i do to achieve faster solution to reduce size of video? Is there any solution or i am stuck with ffmpeg? – Qandeel Abbassi Apr 20 '17 at 20:53
  • I do not know of a faster solution, other than to have a faster machine do the work. Ideally, record the video at a better resolution in the first place, if you are controlling the video recording process. **UPDATE**: if your `minSdkVersion` is 18 or higher, you could [try this library](https://github.com/ypresto/android-transcoder). – CommonsWare Apr 20 '17 at 20:56
  • I found this [project](https://github.com/lalongooo/VideoCompressor) for video compression. Its really fast, don't know how its works though. Its basically extracted from Telegram for Android app source code. Going to look into the code. – Qandeel Abbassi Apr 20 '17 at 21:11
  • Ok will try that library too – Qandeel Abbassi Apr 20 '17 at 21:14
  • Show the complete console output/log from the command that is using `-crf`. – llogan Apr 21 '17 at 01:28

1 Answers1

0

Your file is in mp4 container and already has its streams in some predefined codec. Now the size of any container(not specifically mp4) will depend upon what kind of compression(loosely codec) is used for compressing the data. This is why you will see different size for the same content in different formats. There are other parameters which can affect the size of the file i.e frame rate, resolution, audio bit rate etc. If you reduce them then the size of file becomes less. e.g. in youtube you can choose to play video at a lower rate when bandwidth is the issue.

However, if you choose to do this you will have to re-process the entire file again and its going to to take a lot of time since you are demuxing the container, decoding the codec, applying filter(reducing frame etc), then recording, and then again remuxing. This entire process if not worth few extra MB of saving unless you have some compelling use case.

One solution is to use a more powerful machine but again this is limited by the architecture/constraint of the application to utilize powerful machine. To answer specifically for ffmpeg it wont make much difference.

Russell
  • 361
  • 1
  • 8
  • 24