Android Open Source - Media-Pack Video Capture






From Project

Back to project page Media-Pack.

License

The source code is released under:

Apache License

If you think the Android project Media-Pack listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.intel.inde.mp.samples;
// www. jav  a  2 s. c  o m
import android.content.Context;
import com.intel.inde.mp.*;
import com.intel.inde.mp.android.AndroidMediaObjectFactory;
import com.intel.inde.mp.android.AudioFormatAndroid;
import com.intel.inde.mp.android.VideoFormatAndroid;

import java.io.IOException;

//
//               INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in accordance with the terms of that agreement.
//        Copyright (c) 2013-2014 Intel Corporation. All Rights Reserved.
//

public class VideoCapture {
    private static final String TAG = "VideoCapture";

    private static final int width = 1280;
    private static final int height = 720;
    private static final int frameRate = 30;
    private static final int iFrameInterval = 1;
    private static final int bitRate = 3000;
    private static final String codec = "video/avc";

    private static final Object syncObject = new Object();

    private VideoFormat videoFormat;
    private GLCapture capture;

    private boolean isStarted;
    private boolean isConfigured;
    private Context context;
    private IProgressListener progressListener;

    public VideoCapture(Context context, IProgressListener progressListener) {
        this.context = context;
        this.progressListener = progressListener;
        initVideoFormat();
    }

    public void start(String videoPath) throws IOException {
        if (isStarted()) {
            throw new IllegalStateException(TAG + " already started!");
        }

        capture = new GLCapture(new AndroidMediaObjectFactory(context), progressListener);

        capture.setTargetFile(videoPath);
        capture.setTargetVideoFormat(videoFormat);

        AudioFormat audioFormat = new AudioFormatAndroid("audio/mp4a-latm", 44100, 1);
        capture.setTargetAudioFormat(audioFormat);

        capture.start();

        isStarted = true;
        isConfigured = false;
    }

    public void start(StreamingParameters params) throws IOException {
        if (isStarted()) {
            throw new IllegalStateException(TAG + " already started!");
        }

        capture = new GLCapture(new AndroidMediaObjectFactory(context), progressListener);

        capture.setTargetConnection(params);
        capture.setTargetVideoFormat(videoFormat);

        capture.start();

        isStarted = true;
        isConfigured = false;
    }

    public void stop() {
        if (!isStarted()) {
            throw new IllegalStateException(TAG + " not started or already stopped!");
        }

        capture.stop();
        capture = null;
        isConfigured = false;
    }

    private boolean configure() {
        if (isConfigured()) {
            return true;
        }

        try {
            capture.setSurfaceSize(width, height);
            isConfigured = true;
        } catch (Exception ex) {

        }

        return isConfigured;
    }

    public boolean beginCaptureFrame() {
        if (!isStarted()) {
            return false;
        }

        if (!isConfigured()) {
            if (!configure()) {
                return false;
            }
        }

        capture.beginCaptureFrame();

        return true;
    }

    public void endCaptureFrame() {
        if (!isStarted()) {
            return;
        }

        if (!isConfigured()) {
            return;
        }

        capture.endCaptureFrame();
    }

    public boolean isStarted() {
        if (capture == null) {
            return false;
        }

        return isStarted;
    }

    public boolean isConfigured() {
        return isConfigured;
    }

    public int getFrameWidth() {
        return width;
    }

    public int getFrameHeight() {
        return height;
    }

    private void initVideoFormat() {
        videoFormat = new VideoFormatAndroid(codec, width, height);

        videoFormat.setVideoBitRateInKBytes(bitRate);
        videoFormat.setVideoFrameRate(frameRate);
        videoFormat.setVideoIFrameInterval(iFrameInterval);
    }
}




Java Source Code List

com.intel.inde.mp.android.graphics.EglUtil.java
com.intel.inde.mp.android.graphics.FrameBuffer.java
com.intel.inde.mp.android.graphics.FullFrameTexture.java
com.intel.inde.mp.android.graphics.ShaderProgram.java
com.intel.inde.mp.android.graphics.VideoEffect.java
com.intel.inde.mp.effects.AudioEffect.java
com.intel.inde.mp.effects.AudioReader.java
com.intel.inde.mp.effects.GrayScaleEffect.java
com.intel.inde.mp.effects.InverseEffect.java
com.intel.inde.mp.effects.JpegSubstituteEffect.java
com.intel.inde.mp.effects.OverlayEffect.java
com.intel.inde.mp.effects.RotateEffect.java
com.intel.inde.mp.effects.SepiaEffect.java
com.intel.inde.mp.effects.SubstituteAudioEffect.java
com.intel.inde.mp.effects.TextOverlayEffect.java
com.intel.inde.mp.samples.ActivityWithTimeline.java
com.intel.inde.mp.samples.CameraCapturerActivity.java
com.intel.inde.mp.samples.CameraStreamerActivity.java
com.intel.inde.mp.samples.ComposerAudioEffectActivity.java
com.intel.inde.mp.samples.ComposerAudioEffectCoreActivity.java
com.intel.inde.mp.samples.ComposerCutActivity.java
com.intel.inde.mp.samples.ComposerCutCoreActivity.java
com.intel.inde.mp.samples.ComposerJoinActivity.java
com.intel.inde.mp.samples.ComposerJoinCoreActivity.java
com.intel.inde.mp.samples.ComposerMediaFileInfoActivity.java
com.intel.inde.mp.samples.ComposerMediaFileInfoCoreActivity.java
com.intel.inde.mp.samples.ComposerTranscodeActivity.java
com.intel.inde.mp.samples.ComposerTranscodeCoreActivity.java
com.intel.inde.mp.samples.ComposerVideoEffectActivity.java
com.intel.inde.mp.samples.ComposerVideoEffectCoreActivity.java
com.intel.inde.mp.samples.DemoListAdapter.java
com.intel.inde.mp.samples.DemoListItem.java
com.intel.inde.mp.samples.ExpandableSamplesListAdapter.java
com.intel.inde.mp.samples.FPSCounter.java
com.intel.inde.mp.samples.Format.java
com.intel.inde.mp.samples.GameCapturing.java
com.intel.inde.mp.samples.GameRenderer.java
com.intel.inde.mp.samples.GameStreaming.java
com.intel.inde.mp.samples.MediaStreamerActivity.java
com.intel.inde.mp.samples.MediaStreamerCoreActivity.java
com.intel.inde.mp.samples.RecognitionActivity.java
com.intel.inde.mp.samples.SamplesMainActivity.java
com.intel.inde.mp.samples.VideoCapture.java
com.intel.inde.mp.samples.VideoPlayerActivity.java
com.intel.inde.mp.samples.VideoStreamPlayerActivity.java
com.intel.inde.mp.samples.controls.CameraCaptureSettingsPopup.java
com.intel.inde.mp.samples.controls.GameGLSurfaceView.java
com.intel.inde.mp.samples.controls.PlaybackToolbar.java
com.intel.inde.mp.samples.controls.PopupMessage.java
com.intel.inde.mp.samples.controls.Popup.java
com.intel.inde.mp.samples.controls.RangeSelector.java
com.intel.inde.mp.samples.controls.TimelineItem.java
com.intel.inde.mp.samples.controls.TranscodeSurfaceView.java
com.intel.inde.mp.samples.controls.VideoPlayer.java