Java Code Examples for org.bytedeco.javacv.FrameFilter#Exception

The following examples show how to use org.bytedeco.javacv.FrameFilter#Exception . 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: RecorderActivity.java    From VideoAndroid with Apache License 2.0 6 votes vote down vote up
private void stopRecorder() {
    if(mRecorder == null || !mRecorder.isRecording()) {
        return;
    }

    if(mMyHandler.hasMessages(MSG_STOP)) {
        mMyHandler.removeMessages(MSG_STOP);
    }

    try {
        mRecorderCircleView.stop();
        long recordingTime = mRecorder.getRecordingTime();
        mRecorder.stop();
        if(recordingTime < MIN_RECORDER_TIME) {         //少于最少录制时间
            Toast.makeText(getApplicationContext(), "录制时间至少" + MIN_RECORDER_TIME / 1000 + "s", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(getApplicationContext(), "录制完成", Toast.LENGTH_SHORT).show();
            startActivity(RecoderPlayerActivity.createIntent(this, mRecorder.getOutputPath()));
            finish();
        }
    } catch (FrameRecorder.Exception|FrameFilter.Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: Recorder.java    From VideoAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 开始录制
 * @throws FrameRecorder.Exception
 * @throws FrameFilter.Exception
 */
public void start() throws FrameRecorder.Exception, FrameFilter.Exception {
    if(mRecording) {
        return;
    }

    int rotation = mBuilder.mMyOrientationDetector.getOrientation();
    if(rotation == 0 || rotation == 180) {
        mFFmpegFrameRecorder = mFFmpegFrameRecorderV;
    } else {
        mFFmpegFrameRecorder = mFFmpegFrameRecorderL;
    }

    initFilter();
    mBuilder.mCamera.setPreviewCallback(this);
    mFFmpegFrameRecorder.start();
    mFFmpegFrameFilter.start();
    mRecording = true;
    mRunAudioThread = true;
    mAudioThread = new Thread(mAudioRecordRunnable);
    mAudioThread.start();
    mStartTime = System.currentTimeMillis();
}
 
Example 3
Source File: Recorder.java    From VideoAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 暂停视频
 * @throws FrameRecorder.Exception
 * @throws FrameFilter.Exception
 */
public void stop() throws FrameRecorder.Exception, FrameFilter.Exception {
    if(!mRecording) {
        return;
    }

    mStartTime = 0L;
    mRunAudioThread = false;
    try {
        mAudioThread.join();
    } catch (InterruptedException e) {
        // reset interrupt to be nice
        Thread.currentThread().interrupt();
        return;
    }
    mAudioThread = null;

    if (mFFmpegFrameRecorder != null && mRecording) {
        mRecording = false;
        mFFmpegFrameRecorder.stop();
        mFFmpegFrameRecorder.release();
        mFFmpegFrameFilter.stop();
        mFFmpegFrameFilter.release();
    }
}
 
Example 4
Source File: Recorder.java    From VideoAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
    if (mFrame != null && mRecording) {
        ((ByteBuffer)mFrame.image[0].position(0)).put(data);

        try {
            long t = 1000 * (System.currentTimeMillis() - mStartTime);
            if (t > mFFmpegFrameRecorder.getTimestamp()) {
                mFFmpegFrameRecorder.setTimestamp(t);
            }

            mFFmpegFrameFilter.push(mFrame);
            Frame frame2;
            while ((frame2 = mFFmpegFrameFilter.pull()) != null) {
                mFFmpegFrameRecorder.record(frame2);            //录制该图片
            }
        } catch (FFmpegFrameRecorder.Exception | FrameFilter.Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 5
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 6
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);
    }
}
 
Example 7
Source File: RecorderActivity.java    From VideoAndroid with Apache License 2.0 5 votes vote down vote up
private void startRecorder() {
    if(mRecorder == null || mRecorder.isRecording()) {
        return;
    }

    try {
        mRecorder.start();
        mRecorderCircleView.start();
        mMyHandler.sendEmptyMessageDelayed(MSG_STOP, MAX_RECORDER_TIME);        //MAX_RECORDER_TIME后自动停止
    } catch (FrameRecorder.Exception|FrameFilter.Exception e) {
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), "录制失败", Toast.LENGTH_SHORT).show();
    }
}
 
Example 8
Source File: RecorderActivity.java    From VideoAndroid with Apache License 2.0 5 votes vote down vote up
private void releaseRecoder() {
    if(mRecorder != null) {
        if(mRecorder.isRecording()) {
            try {
                mRecorder.stop();
            } catch (FrameRecorder.Exception|FrameFilter.Exception e) {
                e.printStackTrace();
            }
        }
        mRecorder = null;
    }
}