10

I'm using ffmpeg in android to crop video. To do it I use command:

ffmpeg -i movie.mp4 -vf "crop=640:256:0:400" -strict -2 YourCroppedMovie.mp4

My problem is that it is incredible slow. Cropping 10sec movie taking some about 30sec. Is there any way to speed it up?

Sayaki
  • 769
  • 14
  • 36

1 Answers1

22

Ok try to make the change to your command like this:

ffmpeg -i movie.mp4 -vf "crop=640:256:0:400" -threads 5 -preset ultrafast -strict -2 YourCroppedMovie.mp4

I tried this and reduce execution time from 46 secs to 4 secs. It's too fast now... :-)

Kalpesh
  • 1,767
  • 19
  • 29
  • 2
    The default behavior for threads automatically selects an optimal value, so forcing a specific value may be sub-optimal. – llogan Sep 15 '15 at 16:15
  • hi @kalpesh I am Doing as you metioned but not much effect can you help me pls I am doing zoom out on Images like this stringBuilder .append("zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125"); stringBuilder.append(" -threads 10 -preset ultrafast "); – Sunil Chaudhary Sep 23 '15 at 07:17
  • @Sunil Can you please share me your complete command which you are using now? – Kalpesh Sep 23 '15 at 09:54
  • ffmpeg -loop 1 -i folder.getAbsolutePath()/IMG%d.jpg -i songfolder.getAbsolutePath() -strict -2 -vf "zoompan=z='if(lte(zoom,1.0), 1.5,max(1.001,zoom-0.0015))':d=125" -c:v libx264 -t 5 -s "800x450" zoomout.mp4 – Sunil Chaudhary Sep 23 '15 at 10:27
  • @Kalpesh getting `Unrecognized option 'threads 5 -preset ultrafast'.` Here is Command `String[] cmd = {"-i", tempPath, "-vf", "scale=640:ih*640/iw, crop=" + cropParams, "-threads 5 -preset ultrafast","-strict","experimental","-vcodec","libx264","-preset","ultrafast",outPath};` – Kishore Jethava Sep 14 '16 at 07:52
  • @Anton can you help me please for fast long duration video cropping? – Kishore Jethava Sep 29 '16 at 10:15
  • @LordNeckbeard please help me on above comment!! – Kishore Jethava Sep 29 '16 at 10:23
  • @kishorejethava Make a new question. Show your command and the complete console output/log. – llogan Sep 29 '16 at 19:34
  • @LordNeckbeard [here](http://stackoverflow.com/questions/39866438/ffmpeg-android-video-cropping-speed-and-perfomance) is question and thank you!! – Kishore Jethava Oct 05 '16 at 06:03
  • @KishoreJethava use this String[] cmd = {"-i", tempPath, "-vf", "scale=640:ih*640/iw, crop=" + cropParams, "-threads", "5", "-preset" ,"ultrafast","-strict","experimental","-vcodec","libx264","-pr‌​eset","ultrafast",ou‌​tPath}; – Karthik K M Mar 21 '17 at 17:38
  • Hi All Guys, Sorry for later reply. I hadn't used ffmpeg since long time, so I don't know what the issue now. – Kalpesh Sep 22 '17 at 10:13
  • Doesn't work for my command. `ffmpeg -y -ss 0 -i /storage/emulated/0/DCIM/Camera/20180918_175730.mp4 -to 30 -s 640*640 -metadata:s:v rotate=90 -pix_fmt yuv420p -vf colorchannelmixer=.6:0:0:0:0:.6:0:0:0:0:.8:0:0:0:0:.1 -threads 5 -preset ultrafast -strict 2 /storage/emulated/0/temp/1539139020234.mp4` – Stony Oct 10 '18 at 02:50