Search in sources :

Example 11 with MediaImageItem

use of android.media.videoeditor.MediaImageItem in project android_frameworks_base by ParanoidAndroid.

the class MediaItemThumbnailTest method testThumbnailForImage.

/**
     * Check the thumbnail / frame extraction on JPEG file
     */
@LargeTest
public void testThumbnailForImage() throws Exception {
    final String imageItemFilename = INPUT_FILE_PATH + "IMG_640x480.jpg";
    final int mediaDuration = 1000;
    final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    boolean flagForException = false;
    int outWidth = 0;
    int outHeight = 0;
    final MediaImageItem mii = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", imageItemFilename, mediaDuration, renderingMode);
    assertNotNull("Media Image Item is Null", mii);
    outWidth = mii.getWidth() / 2;
    outHeight = mii.getHeight() / 2;
    final Bitmap thumbNailBmp = mii.getThumbnail(outWidth, outHeight, mediaDuration);
    validateThumbnail(thumbNailBmp, outWidth, outHeight);
}
Also used : Bitmap(android.graphics.Bitmap) MediaImageItem(android.media.videoeditor.MediaImageItem) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 12 with MediaImageItem

use of android.media.videoeditor.MediaImageItem in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorAPITest method testMediaImageItemEffect.

/**
     * To Test the Media Image API : Get Effect, GetAllEffects, remove Effect
     */
@LargeTest
public void testMediaImageItemEffect() throws Exception {
    final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
    final int imageItemRenderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    final MediaImageItem mediaImageItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", imageItemFileName, 5000, imageItemRenderingMode);
    mVideoEditor.addMediaItem(mediaImageItem1);
    assertTrue("Effect List Size", (mediaImageItem1.getAllEffects().size() == 0) ? true : false);
    assertNull("Effect Item by ID", mediaImageItem1.getEffect("xyx"));
    final EffectColor effectColor = mVideoEditorHelper.createEffectItem(mediaImageItem1, "Effecton MVi1", 0, 4000, EffectColor.TYPE_GRADIENT, EffectColor.GRAY);
    mediaImageItem1.addEffect(effectColor);
    assertTrue("Effect List Size", (mediaImageItem1.getAllEffects().size() == 1) ? true : false);
    assertEquals("Effect Item by Valid ID", effectColor, mediaImageItem1.getEffect(effectColor.getId()));
    assertNull("Effect Item by Invalid ID", mediaImageItem1.getEffect("xyz"));
    assertNull("Effect Item by Invalid ID", mediaImageItem1.removeEffect("effectId"));
    assertTrue("Effect List Size", (mediaImageItem1.getAllEffects().size() == 1) ? true : false);
    assertEquals("Effect Removed", effectColor, mediaImageItem1.removeEffect(effectColor.getId()));
    assertTrue("Effect List Size", (mediaImageItem1.getAllEffects().size() == 0) ? true : false);
    assertNull("Effect Item by ID", mediaImageItem1.getEffect("effectId"));
}
Also used : EffectColor(android.media.videoeditor.EffectColor) MediaImageItem(android.media.videoeditor.MediaImageItem) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 13 with MediaImageItem

use of android.media.videoeditor.MediaImageItem in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorAPITest method testMediaImageItemScaledHeightWidth.

/**    This Test Case can be removed as this is already checked in TC 010 */
/**
     * To Test the Media Image API : Scaled Height and Scaled GetWidth
     */
@LargeTest
public void testMediaImageItemScaledHeightWidth() throws Exception {
    final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
    final int imageItemRenderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    final MediaImageItem mediaImageItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaImageItem1", imageItemFileName, imageItemRenderingMode, 5000);
    mVideoEditor.addMediaItem(mediaImageItem1);
    assertNotSame("Image Height = Image Scaled Height", mediaImageItem1.getScaledHeight(), mediaImageItem1.getHeight());
    assertNotSame("Image Width = Image Scaled Width", mediaImageItem1.getScaledWidth(), mediaImageItem1.getWidth());
}
Also used : MediaImageItem(android.media.videoeditor.MediaImageItem) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 14 with MediaImageItem

use of android.media.videoeditor.MediaImageItem in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorPreviewTest method testPreviewWithOverlayEffectKenBurn.

/**
     * To test Preview : Preview of current work having Overlay and Effect
     * applied
     */
@LargeTest
public void testPreviewWithOverlayEffectKenBurn() throws Exception {
    final String videoItemFileName = INPUT_FILE_PATH + "H264_BP_640x480_30fps_192kbps_1_5.mp4";
    final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg";
    final String videoItemFileName1 = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4";
    final String overlayFilename = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png";
    final Semaphore blockTillPreviewCompletes = new Semaphore(1);
    previewStart = false;
    previewStop = false;
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    final MediaImageItem mediaImageItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", imageItemFileName, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaImageItem2);
    final MediaVideoItem mediaVideoItem3 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem3);
    final EffectColor effectColor = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "Effect1", 1000, 3000, EffectColor.TYPE_COLOR, EffectColor.GREEN);
    mediaVideoItem1.addEffect(effectColor);
    final Rect startRect = new Rect((mediaImageItem2.getHeight() / 3), (mediaImageItem2.getWidth() / 3), (mediaImageItem2.getHeight() / 2), (mediaImageItem2.getWidth() / 2));
    final Rect endRect = new Rect(0, 0, mediaImageItem2.getWidth(), mediaImageItem2.getHeight());
    final EffectKenBurns kbeffectOnMI2 = new EffectKenBurns(mediaImageItem2, "KBOnM2", startRect, endRect, 0, 10000);
    assertNotNull("EffectKenBurns", kbeffectOnMI2);
    mediaImageItem2.addEffect(kbeffectOnMI2);
    final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFilename, 640, 480);
    final OverlayFrame overlayFrame = mVideoEditorHelper.createOverlay(mediaVideoItem3, "OverlayID", mBitmap, (mediaImageItem2.getDuration() / 4), (mediaVideoItem3.getDuration() / 3));
    mediaVideoItem3.addOverlay(overlayFrame);
    validatePreviewProgress(5000, -1, false, mVideoEditor.getDuration());
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) EffectColor(android.media.videoeditor.EffectColor) EffectKenBurns(android.media.videoeditor.EffectKenBurns) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaImageItem(android.media.videoeditor.MediaImageItem) OverlayFrame(android.media.videoeditor.OverlayFrame) Semaphore(java.util.concurrent.Semaphore) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 15 with MediaImageItem

use of android.media.videoeditor.MediaImageItem in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorPreviewTest method testPreviewWithTransition.

/**
     *To test Preview : Preview of current Transitions applied (with multiple
     * generatePreview)
     */
@LargeTest
public void testPreviewWithTransition() throws Exception {
    final String videoItemFileName1 = INPUT_FILE_PATH + "H263_profile0_176x144_10fps_96kbps_0_25.3gp";
    final String imageItemFileName1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
    final String videoItemFileName2 = INPUT_FILE_PATH + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4";
    final String maskFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg";
    previewStart = false;
    previewStop = false;
    previewError = false;
    final Semaphore blockTillPreviewCompletes = new Semaphore(1);
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem1.setExtractBoundaries(0, 10000);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    final MediaImageItem mediaImageItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", imageItemFileName1, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaImageItem1);
    final MediaVideoItem mediaVideoItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem2.setExtractBoundaries(0, 10000);
    mVideoEditor.addMediaItem(mediaVideoItem2);
    final TransitionCrossfade transition1And2CrossFade = mVideoEditorHelper.createTCrossFade("transition_1_2_CF", mediaVideoItem1, mediaImageItem1, 2000, Transition.BEHAVIOR_MIDDLE_FAST);
    mVideoEditor.addTransition(transition1And2CrossFade);
    final TransitionAlpha transition2And3Alpha = mVideoEditorHelper.createTAlpha("transition_2_3", mediaImageItem1, mediaVideoItem2, 4000, Transition.BEHAVIOR_SPEED_UP, maskFilename, 50, true);
    mVideoEditor.addTransition(transition2And3Alpha);
    final TransitionFadeBlack transition1FadeBlack = mVideoEditorHelper.createTFadeBlack("transition_1FB", null, mediaVideoItem1, 2000, Transition.BEHAVIOR_MIDDLE_FAST);
    mVideoEditor.addTransition(transition1FadeBlack);
    List<Transition> transitionList = mVideoEditor.getAllTransitions();
    assertEquals("Transition List Size", 3, transitionList.size());
    assertEquals("Transition 1", transition1And2CrossFade, transitionList.get(0));
    assertEquals("Transition 2", transition2And3Alpha, transitionList.get(1));
    assertEquals("Transition 3", transition1FadeBlack, transitionList.get(2));
    mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_3_2);
    final int[] progressValues = new int[300];
    mVideoEditor.generatePreview(new MediaProcessingProgressListener() {

        int i = 0;

        public void onProgress(Object item, int action, int progress) {
            if (item instanceof TransitionCrossfade) {
                progressValues[i] = progress;
                assertEquals("Object", item, transition1And2CrossFade);
                assertEquals("Action", action, MediaProcessingProgressListener.ACTION_ENCODE);
            } else if (item instanceof TransitionAlpha) {
                progressValues[i] = progress;
                assertEquals("Object", item, transition2And3Alpha);
                assertEquals("Action", action, MediaProcessingProgressListener.ACTION_ENCODE);
            } else if (item instanceof TransitionFadeBlack) {
                progressValues[i] = progress;
                assertEquals("Object", item, transition1FadeBlack);
                assertEquals("Action", action, MediaProcessingProgressListener.ACTION_ENCODE);
            }
            i++;
        }
    });
    mVideoEditorHelper.checkProgressCBValues(progressValues);
    final SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    /* As transition takes more time buffer of 10 sec is added */
    long waitingTime = minWaitingTime + 10000 + 10000;
    blockTillPreviewCompletes.acquire();
    try {
        mVideoEditor.startPreview(surfaceHolder, 0, 10000, false, 1, new PreviewProgressListener() {

            public void onProgress(VideoEditor videoEditor, long timeMs, OverlayData overlayData) {
            }

            public void onStart(VideoEditor videoEditor) {
                setPreviewStart();
            }

            public void onStop(VideoEditor videoEditor) {
                setPreviewStop();
                blockTillPreviewCompletes.release();
            }

            public void onError(VideoEditor videoEditor, int error) {
                setPreviewError();
                blockTillPreviewCompletes.release();
            }
        });
    } catch (Exception e) {
        blockTillPreviewCompletes.release();
    }
    blockTillPreviewCompletes.tryAcquire(waitingTime, TimeUnit.MILLISECONDS);
    mVideoEditor.stopPreview();
    blockTillPreviewCompletes.release();
    assertTrue("Preview Failed to start", previewStart);
    assertTrue("Preview Failed to stop", previewStop);
    assertFalse("Preview Error occurred", previewError);
    assertEquals("Removing Transition " + transition1And2CrossFade.getId(), transition1And2CrossFade, mVideoEditor.removeTransition(transition1And2CrossFade.getId()));
    transitionList = mVideoEditor.getAllTransitions();
    assertEquals("Transition List Size", 2, transitionList.size());
    assertEquals("Transition 1", transition2And3Alpha, transitionList.get(0));
    assertEquals("Transition 2", transition1FadeBlack, transitionList.get(1));
    validatePreviewProgress(0, -1, false, mVideoEditor.getDuration());
    final TransitionSliding transition1And2Sliding = mVideoEditorHelper.createTSliding("transition_1_2Sliding", mediaVideoItem1, mediaImageItem1, 4000, Transition.BEHAVIOR_MIDDLE_FAST, TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN);
    mVideoEditor.addTransition(transition1And2Sliding);
    transitionList = mVideoEditor.getAllTransitions();
    assertEquals("Transition List Size", 3, transitionList.size());
    assertEquals("Transition 1", transition2And3Alpha, transitionList.get(0));
    assertEquals("Transition 2", transition1FadeBlack, transitionList.get(1));
    assertEquals("Transition 3", transition1And2Sliding, transitionList.get(2));
    validatePreviewProgress(5000, -1, false, (mVideoEditor.getDuration()));
}
Also used : VideoEditor(android.media.videoeditor.VideoEditor) TransitionFadeBlack(android.media.videoeditor.TransitionFadeBlack) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) MediaImageItem(android.media.videoeditor.MediaImageItem) Semaphore(java.util.concurrent.Semaphore) TransitionCrossfade(android.media.videoeditor.TransitionCrossfade) IOException(java.io.IOException) TransitionAlpha(android.media.videoeditor.TransitionAlpha) SurfaceHolder(android.view.SurfaceHolder) PreviewProgressListener(android.media.videoeditor.VideoEditor.PreviewProgressListener) TransitionSliding(android.media.videoeditor.TransitionSliding) Transition(android.media.videoeditor.Transition) OverlayData(android.media.videoeditor.VideoEditor.OverlayData) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

MediaImageItem (android.media.videoeditor.MediaImageItem)59 LargeTest (android.test.suitebuilder.annotation.LargeTest)49 MediaVideoItem (android.media.videoeditor.MediaVideoItem)28 Bitmap (android.graphics.Bitmap)14 TransitionCrossfade (android.media.videoeditor.TransitionCrossfade)12 MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)12 MediaItem (android.media.videoeditor.MediaItem)11 VideoEditor (android.media.videoeditor.VideoEditor)11 Rect (android.graphics.Rect)10 AudioTrack (android.media.videoeditor.AudioTrack)10 EffectColor (android.media.videoeditor.EffectColor)10 OverlayFrame (android.media.videoeditor.OverlayFrame)9 TransitionAlpha (android.media.videoeditor.TransitionAlpha)9 EffectKenBurns (android.media.videoeditor.EffectKenBurns)8 ExportProgressListener (android.media.videoeditor.VideoEditor.ExportProgressListener)8 TransitionFadeBlack (android.media.videoeditor.TransitionFadeBlack)6 TransitionSliding (android.media.videoeditor.TransitionSliding)6 File (java.io.File)5 IOException (java.io.IOException)5 OverlayData (android.media.videoeditor.VideoEditor.OverlayData)3