org.bytedeco.javacv.FFmpegFrameFilter Java Examples

The following examples show how to use org.bytedeco.javacv.FFmpegFrameFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Recorder.java    From VideoAndroid with Apache License 2.0 6 votes vote down vote up
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
}
 
Example #2
Source File: FilterImageTransform.java    From DataVec with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #3
Source File: FilterImageTransform.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}