Java源码示例:org.bytedeco.javacv.FFmpegFrameFilter

示例1
private void initFilter() {
    Camera.Size previewSize = CameraHelper.getFullScreenPreviewSize(mBuilder.mContext, mBuilder.mCamera);

    //根据定义的视频尺寸和预览的尺寸进行切割、旋转
    Float outputRatio = 1f * mBuilder.mOutputHeight / mBuilder.mOutputWidth;
    int cropWidth = (int) (outputRatio * previewSize.height);
    int cropHeight = previewSize.height;
    int startX = 0;
    int startY = 0;
    int rotation = 90;      //顺时针90度
    boolean hflip = false;
    rotation = (rotation + mBuilder.mMyOrientationDetector.getOrientation()) % 360;

    //如果是前置摄像头 改变旋转方向 修改裁剪位置 水平旋转
    if(mBuilder.mCameraFace == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        startX = previewSize.width - cropWidth;
        rotation = 270;        //270度
        rotation = (rotation - mBuilder.mMyOrientationDetector.getOrientation()) % 360;
        hflip = true;       //自拍水平旋转
    }

    String filters = generateFilters(cropWidth, cropHeight, startX, startY, rotation, hflip);
    mFFmpegFrameFilter = new FFmpegFrameFilter(filters, previewSize.width, previewSize.height);
    mFFmpegFrameFilter.setPixelFormat(org.bytedeco.javacpp.avutil.AV_PIX_FMT_NV21); // default camera format on Android
}
 
示例2
/**
 * Constructs a filtergraph out of the filter specification.
 *
 * @param filters  to use
 * @param width    of the input images
 * @param height   of the input images
 * @param channels of the input images
 */
public FilterImageTransform(@JsonProperty("filters") String filters, @JsonProperty("width") int width,
                @JsonProperty("height") int height, @JsonProperty("channels") int channels) {
    super(null);

    this.filters = filters;
    this.width = width;
    this.height = height;
    this.channels = channels;

    int pixelFormat = channels == 1 ? AV_PIX_FMT_GRAY8
                    : channels == 3 ? AV_PIX_FMT_BGR24 : channels == 4 ? AV_PIX_FMT_RGBA : AV_PIX_FMT_NONE;
    if (pixelFormat == AV_PIX_FMT_NONE) {
        throw new IllegalArgumentException("Unsupported number of channels: " + channels);
    }
    try {
        filter = new FFmpegFrameFilter(filters, width, height);
        filter.setPixelFormat(pixelFormat);
        filter.start();
    } catch (FrameFilter.Exception e) {
        throw new RuntimeException(e);
    }
}
 
示例3
/**
 * Constructs a filtergraph out of the filter specification.
 *
 * @param filters  to use
 * @param width    of the input images
 * @param height   of the input images
 * @param channels of the input images
 */
public FilterImageTransform(@JsonProperty("filters") String filters, @JsonProperty("width") int width,
                @JsonProperty("height") int height, @JsonProperty("channels") int channels) {
    super(null);

    this.filters = filters;
    this.width = width;
    this.height = height;
    this.channels = channels;

    int pixelFormat = channels == 1 ? AV_PIX_FMT_GRAY8
                    : channels == 3 ? AV_PIX_FMT_BGR24 : channels == 4 ? AV_PIX_FMT_RGBA : AV_PIX_FMT_NONE;
    if (pixelFormat == AV_PIX_FMT_NONE) {
        throw new IllegalArgumentException("Unsupported number of channels: " + channels);
    }
    try {
        filter = new FFmpegFrameFilter(filters, width, height);
        filter.setPixelFormat(pixelFormat);
        filter.start();
    } catch (FrameFilter.Exception e) {
        throw new RuntimeException(e);
    }
}