ultimate
ultimate

Reputation: 727

How to trim, crop and add overlay in a single command using FFmpeg

I am using FFmpeg for video editing in android. I am able to trim, crop and add overlay using below commands:

For trim:

command = new String[]{"-i",inputVideoFilePath,"-ss","00:00:30.0","-c","copy","-t","00:00:10.0",outputVideoFilePath};

For crop:

command = new String[]{"-i",inputVideoFilePath,"-preset", "ultrafast","-filter:v","crop=400:400:0:0","-c:a","copy", outputVideoFilePath};

For overlay:

command = new String[]{"-i",inputVideoFilePath, "-i",overlayImagePath,"-preset", "ultrafast","-filter_complex", "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2", "-codec:a", "copy", outputVideoFilePath};

but I'm unable to merge these commands into a single command. Please help me.

Upvotes: 2

Views: 3500

Answers (1)

Gyan
Gyan

Reputation: 93018

Use

command = new String[]{"-ss", "00:00:30.0", "-t", "00:00:10.0", "-i",inputVideoFilePath, 
          "-i",overlayImagePath, "-filter_complex",
          "[0]crop=400:400:0:0[a];[a][1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2",
          "-preset", "ultrafast", "-codec:a", "copy", outputVideoFilePath};

A filter_complex allows one to perform multiple filtering operations on different inputs in series or in parallel.

Upvotes: 8

Related Questions