3

I'm using ffmpeg library for video file compression in my Android project.

To implement ffmpeg I refereed this link, but ffmpeg is taking too much time just to compress the video (currently taking 1 min for 6 seconds video). I'm using below command for video compression--

ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -vf transpose=1 -s 160x120 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k /sdcard/videokit/out.mp4

Please let me know if it is possible to reduce compression time, may be by changing some setting or parameters in above command. Or is there any other way to compress the video faster than ffmpeg. Thank you.

Leo Wiki
  • 252
  • 3
  • 17
  • While there may be ways to make ffmpeg faster, I'd also look into not using the same disk for your in/out streams, and also trying the code on different devices with different sdcards. – n_b Sep 14 '16 at 10:08
  • 1
    See http://stackoverflow.com/q/39473434/5726027 – Gyan Sep 14 '16 at 11:25
  • @Leo Wiki did you find any solution over it? i am facing same issue video compression is very slow. – Piyush Mar 07 '17 at 11:07

1 Answers1

10

There aren't many things you can do, but there are certainly a few things worth considering:

  • you can set the -preset value to fast/veryfast/ultrafast
  • you can set the -crf value (usually 18 to 28).
  • The most important thing to note is that if you do not want to alter your audio/video codecs, you should retain the original settings using: -c copy (this can drastically improve the execution time, depending upon your use-case)

Refer this link for preset and crf settings

Community
  • 1
  • 1
Sarthak Mittal
  • 5,794
  • 2
  • 24
  • 44
  • As u suggested I rewrite my command from "ffmpeg -y -i %s -strict experimental -s 160x120 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k %s" TO "ffmpeg -y -i %s -crf 27 -preset veryfast -strict experimental -s 160x120 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k %s" But my app is getting crashed printing nothing in log. – Leo Wiki Sep 14 '16 at 12:38
  • can u plz help me to rewrite my Command – Leo Wiki Sep 14 '16 at 12:38
  • they have a sample app as well which prints the logs, did you tried to run your command from that? – Sarthak Mittal Sep 14 '16 at 12:54
  • 3
    `-c copy` decreased time from about to minute to several seconds for me! – King Julien Jun 30 '19 at 17:47
  • ```-c copy``` cannot be used with filtering, then try ```-c:a copy``` – MJ Studio Dec 23 '19 at 06:46
  • 1
    @SarthakMittal Man! you are a saviour! Thanks a ton :D – Dinesh Singh Nov 16 '20 at 10:37
  • If you're applying a video filter and thus cannot use `-c:v copy`, adding `-vsync passthrough` can save a lot of time. – bk138 Dec 23 '20 at 12:47
  • @bk138 It's kinda hard for me to try this, I would suggest posting it as an answer to help future readers. :D – Sarthak Mittal Dec 23 '20 at 13:51
  • From speed 0.175 SPS (seconds per second) to 80 SPS! However, compression didn't work, instead of that, it increases the size of the file. – Said Torres Sep 05 '22 at 17:02
  • @SaidTorres I am glad this answer is still useful as I no longer work on ffmpeg so I cant update it with more ideas, I would suggest posting your own answer if you find other things that helped you, this will help future readers who stumble upon this page. – Sarthak Mittal Sep 05 '22 at 18:04