Search in sources :

Example 1 with TransitionFadeBlack

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

the class VideoEditorHelper method createTFadeBlack.

/**
     *This Method creates object of Type TransitionFadeBlack
     *
     * @return TransitionFadeBlack object
     */
public TransitionFadeBlack createTFadeBlack(String transitionId, MediaItem afterMediaItem, MediaItem beforeMediaItem, long durationMs, int behavior) {
    TransitionFadeBlack transitionFB = null;
    transitionFB = new TransitionFadeBlack(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior);
    return transitionFB;
}
Also used : TransitionFadeBlack(android.media.videoeditor.TransitionFadeBlack)

Example 2 with TransitionFadeBlack

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

the class VideoEditorAPITest method testTransitionFadeBlack.

/**
     * To test Transition : Fade To Black with all behavior
     * SPEED_UP/SPEED_DOWN/LINEAR/MIDDLE_SLOW/MIDDLE_FAST
     */
@LargeTest
public void testTransitionFadeBlack() throws Exception {
    final String videoItemFilename1 = INPUT_FILE_PATH + "H264_BP_640x480_30fps_256kbps_1_17.mp4";
    final String videoItemFilename2 = INPUT_FILE_PATH + "H263_profile0_176x144_15fps_128kbps_1_35.3gp";
    final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
    final String videoItemFilename3 = INPUT_FILE_PATH + "H264_BP_640x480_30fps_192kbps_1_5.mp4";
    final String videoItemFilename4 = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4";
    final String videoItemFilename5 = INPUT_FILE_PATH + "H263_profile0_176x144_10fps_96kbps_0_25.3gp";
    boolean flagForException = false;
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem1.setExtractBoundaries(0, 15000);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    final MediaVideoItem mediaVideoItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem2.setExtractBoundaries(0, 15000);
    mVideoEditor.addMediaItem(mediaVideoItem2);
    final TransitionFadeBlack transition1And2 = mVideoEditorHelper.createTFadeBlack("transition1And2", mediaVideoItem1, mediaVideoItem2, 3000, Transition.BEHAVIOR_SPEED_UP);
    mVideoEditor.addTransition(transition1And2);
    assertTrue("Transition ID", transition1And2.getId().equals("transition1And2"));
    assertEquals("Transtion After Media item", mediaVideoItem1, transition1And2.getAfterMediaItem());
    assertEquals("Transtion Before Media item", mediaVideoItem2, transition1And2.getBeforeMediaItem());
    assertEquals("Transtion Duration", 3000, transition1And2.getDuration());
    assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_UP, transition1And2.getBehavior());
    final MediaImageItem mediaImageItem3 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaImageItem3);
    final TransitionFadeBlack transition2And3 = mVideoEditorHelper.createTFadeBlack("transition2And3", mediaVideoItem2, mediaImageItem3, 1000, Transition.BEHAVIOR_SPEED_DOWN);
    mVideoEditor.addTransition(transition2And3);
    assertTrue("Transition ID", transition2And3.getId().equals("transition2And3"));
    assertEquals("Transtion After Media item", mediaVideoItem2, transition2And3.getAfterMediaItem());
    assertEquals("Transtion Before Media item", mediaImageItem3, transition2And3.getBeforeMediaItem());
    assertEquals("Transtion Duration", 1000, transition2And3.getDuration());
    assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_DOWN, transition2And3.getBehavior());
    final MediaVideoItem mediaVideoItem4 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem4.setExtractBoundaries(0, 20000);
    mVideoEditor.addMediaItem(mediaVideoItem4);
    final TransitionFadeBlack transition3And4 = mVideoEditorHelper.createTFadeBlack("transition3And4", mediaImageItem3, mediaVideoItem4, 5000, Transition.BEHAVIOR_LINEAR);
    mVideoEditor.addTransition(transition3And4);
    assertTrue("Transition ID", transition3And4.getId().equals("transition3And4"));
    assertEquals("Transtion After Media item", mediaImageItem3, transition3And4.getAfterMediaItem());
    assertEquals("Transtion Before Media item", mediaVideoItem4, transition3And4.getBeforeMediaItem());
    assertEquals("Transtion Duration", 5000, transition3And4.getDuration());
    assertEquals("Transtion Behavior", Transition.BEHAVIOR_LINEAR, transition3And4.getBehavior());
    final MediaVideoItem mediaVideoItem5 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", videoItemFilename4, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem5);
    final TransitionFadeBlack transition4And5 = mVideoEditorHelper.createTFadeBlack("transition4And5", mediaVideoItem4, mediaVideoItem5, 8000, Transition.BEHAVIOR_MIDDLE_FAST);
    mVideoEditor.addTransition(transition4And5);
    assertTrue("Transition ID", transition4And5.getId().equals("transition4And5"));
    assertEquals("Transtion After Media item", mediaVideoItem4, transition4And5.getAfterMediaItem());
    assertEquals("Transtion Before Media item", mediaVideoItem5, transition4And5.getBeforeMediaItem());
    assertEquals("Transtion Duration", 8000, transition4And5.getDuration());
    assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_FAST, transition4And5.getBehavior());
    final MediaVideoItem mediaVideoItem6 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", videoItemFilename5, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem6.setExtractBoundaries(0, 20000);
    mVideoEditor.addMediaItem(mediaVideoItem6);
    final TransitionFadeBlack transition5And6 = mVideoEditorHelper.createTFadeBlack("transition5And6", mediaVideoItem5, mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW);
    mVideoEditor.addTransition(transition5And6);
    assertTrue("Transition ID", transition5And6.getId().equals("transition5And6"));
    assertEquals("Transtion After Media item", mediaVideoItem5, transition5And6.getAfterMediaItem());
    assertEquals("Transtion Before Media item", mediaVideoItem6, transition5And6.getBeforeMediaItem());
    assertEquals("Transtion Duration", 2000, transition5And6.getDuration());
    assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_SLOW, transition5And6.getBehavior());
    flagForException = false;
    try {
        mVideoEditorHelper.createTFadeBlack("transitiond6", mediaVideoItem5, mediaVideoItem6, 2000, Transition.BEHAVIOR_SPEED_UP - 1);
    } catch (IllegalArgumentException e) {
        flagForException = true;
    }
    assertTrue("Transition FadeBlack with Invalid behavior", flagForException);
    flagForException = false;
    try {
        mVideoEditorHelper.createTFadeBlack("transitiond6", mediaVideoItem5, mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1);
    } catch (IllegalArgumentException e) {
        flagForException = true;
    }
    assertTrue("Transition FadeBlack with Invalid behavior", flagForException);
}
Also used : TransitionFadeBlack(android.media.videoeditor.TransitionFadeBlack) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaImageItem(android.media.videoeditor.MediaImageItem) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 3 with TransitionFadeBlack

use of android.media.videoeditor.TransitionFadeBlack 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)

Example 4 with TransitionFadeBlack

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

the class VideoEditorStressTest method testStressAddRemoveTransition.

/**
     * To stress test transition
     *
     * @throws Exception
     */
@LargeTest
public void testStressAddRemoveTransition() throws Exception {
    final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    final String VideoItemFileName1 = INPUT_FILE_PATH + "H264_BP_800x480_15fps_512kbps_1_17.mp4";
    final String ImageItemFileName2 = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
    final String VideoItemFileName3 = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4";
    final String maskFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg";
    final String[] loggingInfo = new String[1];
    int i = 0;
    writeTestCaseHeader("testStressAddRemoveTransition");
    getBeginMemory();
    for (i = 0; i < 50; i++) {
        if (i % 4 == 0) {
            final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, "m1" + i, VideoItemFileName1, renderingMode);
            mVideoEditor.addMediaItem(mediaItem1);
            mediaItem1.setExtractBoundaries(0, 10000);
            final TransitionCrossfade tranCrossfade = new TransitionCrossfade("transCF" + i, null, mediaItem1, 5000, Transition.BEHAVIOR_MIDDLE_FAST);
            mVideoEditor.addTransition(tranCrossfade);
        }
        if (i % 4 == 1) {
            final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, "m1" + i, VideoItemFileName1, renderingMode);
            mVideoEditor.addMediaItem(mediaItem1);
            mediaItem1.setExtractBoundaries(0, 10000);
            final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor, "m2" + i, ImageItemFileName2, 10000, renderingMode);
            mVideoEditor.addMediaItem(mediaItem2);
            final TransitionAlpha transitionAlpha = mVideoEditorHelper.createTAlpha("transAlpha" + i, mediaItem1, mediaItem2, 5000, Transition.BEHAVIOR_SPEED_UP, maskFilename, 10, false);
            transitionAlpha.setDuration(4000);
            mVideoEditor.addTransition(transitionAlpha);
        }
        if (i % 4 == 2) {
            final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor, "m2" + i, ImageItemFileName2, 10000, renderingMode);
            mVideoEditor.addMediaItem(mediaItem2);
            final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor, "m3" + i, VideoItemFileName3, renderingMode);
            mVideoEditor.addMediaItem(mediaItem3);
            mediaItem3.setExtractBoundaries(0, 10000);
            final TransitionAlpha transitionAlpha = mVideoEditorHelper.createTAlpha("transAlpha" + i, mediaItem2, mediaItem3, 5000, Transition.BEHAVIOR_SPEED_UP, maskFilename, 10, false);
            transitionAlpha.setDuration(4000);
            mVideoEditor.addTransition(transitionAlpha);
            mediaItem3.setExtractBoundaries(0, 6000);
            final TransitionSliding transition2And3 = mVideoEditorHelper.createTSliding("transSlide" + i, mediaItem2, mediaItem3, 3000, Transition.BEHAVIOR_MIDDLE_FAST, TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN);
            mVideoEditor.addTransition(transition2And3);
        }
        if (i % 4 == 3) {
            final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor, "m3" + i, VideoItemFileName3, renderingMode);
            mVideoEditor.addMediaItem(mediaItem3);
            mediaItem3.setExtractBoundaries(0, 5000);
            final TransitionFadeBlack transition3 = mVideoEditorHelper.createTFadeBlack("transFB" + i, mediaItem3, null, 2500, Transition.BEHAVIOR_SPEED_UP);
            transition3.setDuration(500);
            mVideoEditor.addTransition(transition3);
        }
        if (i % 10 == 0) {
            getAfterMemory_updateLog(loggingInfo, false, i);
        }
    }
    getAfterMemory_updateLog(loggingInfo, false, i);
    /** Remove items and check for memory leak if any */
    for (i = 0; i < 50; i++) {
        if (i % 4 == 0) {
            mVideoEditor.removeTransition("transCF" + i);
            mVideoEditor.removeMediaItem("m1" + i);
        }
        if (i % 4 == 1) {
            mVideoEditor.removeTransition("transAlpha" + i);
            mVideoEditor.removeMediaItem("m1" + i);
            mVideoEditor.removeMediaItem("m2" + i);
        }
        if (i % 4 == 2) {
            mVideoEditor.removeTransition("transSlide" + i);
            mVideoEditor.removeMediaItem("m2" + i);
            mVideoEditor.removeMediaItem("m3" + i);
        }
        if (i % 4 == 3) {
            mVideoEditor.removeMediaItem("m3" + i);
        }
        if (i % 10 == 0) {
            getAfterMemory_updateLog(loggingInfo, true, i);
        }
    }
    getAfterMemory_updateLog(loggingInfo, true, i);
}
Also used : TransitionFadeBlack(android.media.videoeditor.TransitionFadeBlack) TransitionSliding(android.media.videoeditor.TransitionSliding) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaImageItem(android.media.videoeditor.MediaImageItem) TransitionCrossfade(android.media.videoeditor.TransitionCrossfade) TransitionAlpha(android.media.videoeditor.TransitionAlpha) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 5 with TransitionFadeBlack

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

the class VideoEditorPerformance method testPerformanceExport.

/**
     * To test performance of Export
     *
     * @throws Exception
     */
@LargeTest
public void testPerformanceExport() throws Exception {
    final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    final int outHeight = MediaProperties.HEIGHT_480;
    final int outBitrate = MediaProperties.BITRATE_256K;
    final int outVcodec = MediaProperties.VCODEC_H264;
    final String[] loggingInfo = new String[1];
    final String outFilename = mVideoEditorHelper.createRandomFile(mVideoEditor.getPath() + "/") + ".3gp";
    final String videoItemFileName1 = INPUT_FILE_PATH + "H264_BP_1080x720_30fps_12Mbps_AACLC_44.1khz_64kbps_s_1_17.mp4";
    final String imageItemFileName1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
    final String videoItemFileName2 = INPUT_FILE_PATH + "H264_BP_640x480_15fps_1200Kbps_AACLC_48KHz_32kbps_m_1_17.3gp";
    final String imageItemFileName2 = INPUT_FILE_PATH + "IMG_176x144.jpg";
    final String videoItemFileName3 = INPUT_FILE_PATH + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_161kbps_s_0_26.mp4";
    final String overlayFile = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png";
    final String audioTrackFilename = INPUT_FILE_PATH + "AMRNB_8KHz_12.2Kbps_m_1_17.3gp";
    final String maskFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg";
    final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor, "m1", videoItemFileName1, renderingMode);
    mediaItem1.setExtractBoundaries(0, 20000);
    mVideoEditor.addMediaItem(mediaItem1);
    final MediaImageItem mediaItem2 = new MediaImageItem(mVideoEditor, "m2", imageItemFileName1, 10000, renderingMode);
    mVideoEditor.addMediaItem(mediaItem2);
    final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor, "m3", videoItemFileName2, renderingMode);
    mediaItem3.setExtractBoundaries(0, 20000);
    mVideoEditor.addMediaItem(mediaItem3);
    final MediaImageItem mediaItem4 = new MediaImageItem(mVideoEditor, "m4", imageItemFileName2, 10000, renderingMode);
    mVideoEditor.addMediaItem(mediaItem4);
    final MediaVideoItem mediaItem5 = new MediaVideoItem(mVideoEditor, "m5", videoItemFileName3, renderingMode);
    mediaItem5.setExtractBoundaries(0, 20000);
    mVideoEditor.addMediaItem(mediaItem5);
    /**
         * 7.Add TransitionAlpha, Apply this  Transition as Begin for Media Item 1
         *  with duration = 2 sec behavior = BEHAVIOR_LINEAR, mask file name =
         * TransitionSpiral_QVGA.jpg , blending percent = 50%, invert = true;
         * */
    final TransitionAlpha transition1 = mVideoEditorHelper.createTAlpha("transition1", null, mediaItem1, 2000, Transition.BEHAVIOR_LINEAR, maskFilename, 50, true);
    mVideoEditor.addTransition(transition1);
    /**
         * 8.Add Transition Sliding between MediaItem 2 and 3 ,
         *  Sliding Direction  = DIRECTION_RIGHT_OUT_LEFT_IN,
         *  behavior  = BEHAVIOR_MIDDLE_FAST and duration = 4sec
         * */
    final TransitionSliding transition2And3 = mVideoEditorHelper.createTSliding("transition2", mediaItem2, mediaItem3, 4000, Transition.BEHAVIOR_MIDDLE_FAST, TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN);
    mVideoEditor.addTransition(transition2And3);
    /**
         * 9.Add Transition Crossfade between  Media Item 3 and 4,
         *  behavior = BEHAVIOR_MIDDLE_SLOW, duration = 3.5 sec
         * */
    final TransitionCrossfade transition3And4 = mVideoEditorHelper.createTCrossFade("transition3", mediaItem3, mediaItem4, 3500, Transition.BEHAVIOR_MIDDLE_SLOW);
    mVideoEditor.addTransition(transition3And4);
    /**
         * 10.Add Transition Fadeblack between  Media Item 4 and 5,
         *  behavior = BEHAVIOR_SPEED_DOWN, duration = 3.5 sec
         * */
    final TransitionFadeBlack transition4And5 = mVideoEditorHelper.createTFadeBlack("transition4", mediaItem4, mediaItem5, 3500, Transition.BEHAVIOR_SPEED_DOWN);
    mVideoEditor.addTransition(transition4And5);
    /**
         * 11.Add Effect 1 type="TYPE_SEPIA" to the MediaItem 1,
         *  start time=1sec and duration =4secs
         * */
    final EffectColor effectColor1 = mVideoEditorHelper.createEffectItem(mediaItem1, "effect1", 1000, 4000, EffectColor.TYPE_SEPIA, 0);
    mediaItem1.addEffect(effectColor1);
    /**
         * 12.Add Overlay 1  to the MediaItem 3: Frame Overlay with start time = 1 sec
         * duration = 4 sec with item  = IMG_640x480_Overlay1.png
         * */
    final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFile, 640, 480);
    final OverlayFrame overlayFrame = mVideoEditorHelper.createOverlay(mediaItem3, "overlay", mBitmap, 1000, 4000);
    mediaItem3.addOverlay(overlayFrame);
    /**
         * 13.Add Effect 2 type="TYPE_NEGATIVE" to the MediaItem 2,
         *  start time=8sec and duration =2secs
         * */
    final EffectColor effectColor2 = mVideoEditorHelper.createEffectItem(mediaItem2, "effect2", 8000, 2000, EffectColor.TYPE_NEGATIVE, 0);
    mediaItem2.addEffect(effectColor2);
    /**
         * 14.Add Effect 3 type="TYPE_COLOR" to the MediaItem 3, color param = "PINK",
         *  start time=5 sec and duration =3secs
         * */
    final EffectColor effectColor3 = mVideoEditorHelper.createEffectItem(mediaItem3, "effect3", 5000, 3000, EffectColor.TYPE_COLOR, EffectColor.PINK);
    mediaItem3.addEffect(effectColor3);
    /**
         * 15.Add Effect 4 type="TYPE_FIFTIES" to the MediaItem 4,
         *  start time=2 sec and duration =1secs
        * */
    final EffectColor effectColor4 = mVideoEditorHelper.createEffectItem(mediaItem4, "effect4", 2000, 1000, EffectColor.TYPE_FIFTIES, 0);
    mediaItem4.addEffect(effectColor4);
    /**
         * 16.Add KenBurnsEffect for MediaItem 4 with
         *  duration = 3 sec and startTime = 4 sec
         *  StartRect
         *  left = org_height/3  ;  top = org_width/3
         *  bottom = org_width/2  ;  right = org_height/2
         *  EndRect
         *  left = 0  ;  top = 0
         *  bottom =  org_height;  right =  org_width
         * */
    final Rect startRect = new Rect((mediaItem4.getHeight() / 3), (mediaItem4.getWidth() / 3), (mediaItem4.getHeight() / 2), (mediaItem4.getWidth() / 2));
    final Rect endRect = new Rect(0, 0, mediaItem4.getWidth(), mediaItem4.getHeight());
    final EffectKenBurns kbEffectOnMediaItem = new EffectKenBurns(mediaItem4, "KBOnM2", startRect, endRect, 4000, 3000);
    mediaItem4.addEffect(kbEffectOnMediaItem);
    /** 17.Add Audio Track,Set extract boundaries o to 10 sec.
         * */
    final AudioTrack audioTrack = mVideoEditorHelper.createAudio(mVideoEditor, "audioTrack", audioTrackFilename);
    mVideoEditor.addAudioTrack(audioTrack);
    /** 18.Enable Looping for Audio Track.
         * */
    audioTrack.enableLoop();
    int timeTaken = 0;
    final long beginTime = SystemClock.uptimeMillis();
    try {
        mVideoEditor.export(outFilename, outHeight, outBitrate, new ExportProgressListener() {

            public void onProgress(VideoEditor ve, String outFileName, int progress) {
            }
        });
    } catch (Exception e) {
        assertTrue("Error in Export" + e.toString(), false);
    }
    mVideoEditorHelper.checkDeleteExistingFile(outFilename);
    timeTaken = calculateTimeTaken(beginTime, 1);
    loggingInfo[0] = "Time taken to do ONE export of storyboard duration " + mVideoEditor.getDuration() + " is :" + timeTaken;
    writeTimingInfo("testPerformanceExport (in mSec)", loggingInfo);
    mVideoEditorHelper.deleteProject(new File(mVideoEditor.getPath()));
}
Also used : Rect(android.graphics.Rect) VideoEditor(android.media.videoeditor.VideoEditor) EffectKenBurns(android.media.videoeditor.EffectKenBurns) ExportProgressListener(android.media.videoeditor.VideoEditor.ExportProgressListener) TransitionFadeBlack(android.media.videoeditor.TransitionFadeBlack) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaImageItem(android.media.videoeditor.MediaImageItem) OverlayFrame(android.media.videoeditor.OverlayFrame) TransitionCrossfade(android.media.videoeditor.TransitionCrossfade) TransitionAlpha(android.media.videoeditor.TransitionAlpha) Bitmap(android.graphics.Bitmap) EffectColor(android.media.videoeditor.EffectColor) TransitionSliding(android.media.videoeditor.TransitionSliding) AudioTrack(android.media.videoeditor.AudioTrack) File(java.io.File) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

TransitionFadeBlack (android.media.videoeditor.TransitionFadeBlack)8 LargeTest (android.test.suitebuilder.annotation.LargeTest)7 MediaImageItem (android.media.videoeditor.MediaImageItem)6 MediaVideoItem (android.media.videoeditor.MediaVideoItem)6 TransitionAlpha (android.media.videoeditor.TransitionAlpha)4 TransitionCrossfade (android.media.videoeditor.TransitionCrossfade)4 TransitionSliding (android.media.videoeditor.TransitionSliding)4 VideoEditor (android.media.videoeditor.VideoEditor)3 ExportProgressListener (android.media.videoeditor.VideoEditor.ExportProgressListener)2 MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)2 Bitmap (android.graphics.Bitmap)1 Rect (android.graphics.Rect)1 AudioTrack (android.media.videoeditor.AudioTrack)1 EffectColor (android.media.videoeditor.EffectColor)1 EffectKenBurns (android.media.videoeditor.EffectKenBurns)1 OverlayFrame (android.media.videoeditor.OverlayFrame)1 Transition (android.media.videoeditor.Transition)1 OverlayData (android.media.videoeditor.VideoEditor.OverlayData)1 PreviewProgressListener (android.media.videoeditor.VideoEditor.PreviewProgressListener)1 SurfaceHolder (android.view.SurfaceHolder)1