diff --git a/src/org/ffmpeg/android/filters/CropVideoFilter.java b/src/org/ffmpeg/android/filters/CropVideoFilter.java new file mode 100644 index 0000000..ab725cf --- /dev/null +++ b/src/org/ffmpeg/android/filters/CropVideoFilter.java @@ -0,0 +1,134 @@ +package org.ffmpeg.android.filters; + +public class CropVideoFilter extends VideoFilter { + + private String mOutWidth; + private String mOutHeight; + private String mX; + private String mY; + + public CropVideoFilter (String width, String height, String x, String y) + { + mOutWidth = width; + mOutHeight = height; + mX = x; + mY = y; + } + + @Override + public String getFilterString() { + + StringBuffer result = new StringBuffer(); + + result.append("crop="); + + if (mOutWidth != null) + result.append(mOutWidth).append(":"); + + if (mOutHeight != null) + result.append(mOutHeight).append(":"); + + if (mX != null) + result.append(mX).append(":"); + + if (mY != null) + result.append(mY).append(":"); + + result.deleteCharAt(result.length()-1); //remove the last semicolon! + + return result.toString(); + } + +} + +/* +Crop the input video to out_w:out_h:x:y:keep_aspect + +The keep_aspect parameter is optional, if specified and set to a non-zero value will force the output display aspect ratio to be the same of the input, by changing the output sample aspect ratio. + +The out_w, out_h, x, y parameters are expressions containing the following constants: + +‘x, y’ +the computed values for x and y. They are evaluated for each new frame. + +‘in_w, in_h’ +the input width and height + +‘iw, ih’ +same as in_w and in_h + +‘out_w, out_h’ +the output (cropped) width and height + +‘ow, oh’ +same as out_w and out_h + +‘a’ +same as iw / ih + +‘sar’ +input sample aspect ratio + +‘dar’ +input display aspect ratio, it is the same as (iw / ih) * sar + +‘hsub, vsub’ +horizontal and vertical chroma subsample values. For example for the pixel format "yuv422p" hsub is 2 and vsub is 1. + +‘n’ +the number of input frame, starting from 0 + +‘pos’ +the position in the file of the input frame, NAN if unknown + +‘t’ +timestamp expressed in seconds, NAN if the input timestamp is unknown + +The out_w and out_h parameters specify the expressions for the width and height of the output (cropped) video. They are evaluated just at the configuration of the filter. + +The default value of out_w is "in_w", and the default value of out_h is "in_h". + +The expression for out_w may depend on the value of out_h, and the expression for out_h may depend on out_w, but they cannot depend on x and y, as x and y are evaluated after out_w and out_h. + +The x and y parameters specify the expressions for the position of the top-left corner of the output (non-cropped) area. They are evaluated for each frame. If the evaluated value is not valid, it is approximated to the nearest valid value. + +The default value of x is "(in_w-out_w)/2", and the default value for y is "(in_h-out_h)/2", which set the cropped area at the center of the input image. + +The expression for x may depend on y, and the expression for y may depend on x. + +Follow some examples: + + +# crop the central input area with size 100x100 +crop=100:100 + +# crop the central input area with size 2/3 of the input video +"crop=2/3*in_w:2/3*in_h" + +# crop the input video central square +crop=in_h + +# delimit the rectangle with the top-left corner placed at position +# 100:100 and the right-bottom corner corresponding to the right-bottom +# corner of the input image. +crop=in_w-100:in_h-100:100:100 + +# crop 10 pixels from the left and right borders, and 20 pixels from +# the top and bottom borders +"crop=in_w-2*10:in_h-2*20" + +# keep only the bottom right quarter of the input image +"crop=in_w/2:in_h/2:in_w/2:in_h/2" + +# crop height for getting Greek harmony +"crop=in_w:1/PHI*in_w" + +# trembling effect +"crop=in_w/2:in_h/2:(in_w-out_w)/2+((in_w-out_w)/2)*sin(n/10):(in_h-out_h)/2 +((in_h-out_h)/2)*sin(n/7)" + +# erratic camera effect depending on timestamp +"crop=in_w/2:in_h/2:(in_w-out_w)/2+((in_w-out_w)/2)*sin(t*10):(in_h-out_h)/2 +((in_h-out_h)/2)*sin(t*13)" + +# set x depending on the value of y +"crop=in_w/2:in_h/2:y:10+10*sin(n/10)" +*/ \ No newline at end of file diff --git a/src/org/ffmpeg/android/filters/TransposeVideoFilter.java b/src/org/ffmpeg/android/filters/TransposeVideoFilter.java new file mode 100644 index 0000000..d69012a --- /dev/null +++ b/src/org/ffmpeg/android/filters/TransposeVideoFilter.java @@ -0,0 +1,30 @@ +package org.ffmpeg.android.filters; + +/* + * works for video and images + * 0 = 90CounterCLockwise and Vertical Flip (default) +1 = 90Clockwise +2 = 90CounterClockwise +3 = 90Clockwise and Vertical Flip + */ +public class TransposeVideoFilter extends VideoFilter { + + private int mTranspose = -1; + + public final static int NINETY_COUNTER_CLOCKWISE_AND_VERTICAL_FLIP = 0; + public final static int NINETY_CLOCKWISE = 1; + public final static int NINETY_COUNTER_CLOCKWISE = 2; + public final static int NINETY_CLOCKWISE_AND_VERTICAL_FLIP = 3; + + public TransposeVideoFilter (int transpose) + { + mTranspose = transpose; + } + + @Override + public String getFilterString() { + + return "transpose=" + mTranspose; + } + +} diff --git a/src/org/ffmpeg/android/test/FilterTest.java b/src/org/ffmpeg/android/test/FilterTest.java index 99d3dd7..dee1072 100644 --- a/src/org/ffmpeg/android/test/FilterTest.java +++ b/src/org/ffmpeg/android/test/FilterTest.java @@ -3,9 +3,11 @@ import java.io.File; import java.util.ArrayList; +import org.ffmpeg.android.filters.CropVideoFilter; import org.ffmpeg.android.filters.DrawBoxVideoFilter; import org.ffmpeg.android.filters.DrawTextVideoFilter; import org.ffmpeg.android.filters.FadeVideoFilter; +import org.ffmpeg.android.filters.TransposeVideoFilter; import org.ffmpeg.android.filters.VideoFilter; import android.app.Activity; @@ -33,13 +35,24 @@ public void test (Context context) "yellow", "0.5"); - FadeVideoFilter vfFadeIn = new FadeVideoFilter("in",0,50); + float fps = 29.97f; + int fadeTime = (int)(fps*3); + //fades in first 3 seconds + FadeVideoFilter vfFadeIn = new FadeVideoFilter("in",0,fadeTime); + //fades out last 50 frames int totalFrames = (int)(14.37*29.97); + FadeVideoFilter vfFadeOut = new FadeVideoFilter("out",totalFrames-fadeTime,fadeTime); - FadeVideoFilter vfFadeOut = new FadeVideoFilter("out",totalFrames-50,50); + //crops video in 100 pixels on each side + CropVideoFilter vfCrop = new CropVideoFilter("in_w-100","in_h-100","100","100"); - //listFilters.add(vfTitle); + //rotates video 90 degress clockwise + TransposeVideoFilter vfTranspose = new TransposeVideoFilter(TransposeVideoFilter.NINETY_CLOCKWISE); + + listFilters.add(vfTranspose); + listFilters.add(vfCrop); + listFilters.add(vfTitle); listFilters.add(vfFadeIn); listFilters.add(vfFadeOut);