Search in sources :

Example 6 with TransitionSliding

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

the class VideoEditorAPITest method testTransitionSliding.

/**
     * To test Transition : Sliding with all behavior
     * SPEED_UP/SPEED_DOWN/LINEAR/MIDDLE_SLOW/MIDDLE_FAST and Direction =
     * DIRECTION_RIGHT_OUT_LEFT_IN
     * ,DIRECTION_LEFT_OUT_RIGHT_IN,DIRECTION_TOP_OUT_BOTTOM_IN
     * ,DIRECTION_BOTTOM_OUT_TOP_IN
     */
@LargeTest
public void testTransitionSliding() 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 TransitionSliding transition1And2 = mVideoEditorHelper.createTSliding("transition1And2", mediaVideoItem1, mediaVideoItem2, 3000, Transition.BEHAVIOR_SPEED_UP, TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN);
    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());
    assertEquals("Transition Sliding", TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN, transition1And2.getDirection());
    final MediaImageItem mediaImageItem3 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaImageItem3);
    final TransitionSliding transition2And3 = mVideoEditorHelper.createTSliding("transition2And3", mediaVideoItem2, mediaImageItem3, 1000, Transition.BEHAVIOR_SPEED_DOWN, TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN);
    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());
    assertEquals("Transition Sliding", TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN, transition2And3.getDirection());
    final MediaVideoItem mediaVideoItem4 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem4.setExtractBoundaries(0, 18000);
    mVideoEditor.addMediaItem(mediaVideoItem4);
    final TransitionSliding transition3And4 = mVideoEditorHelper.createTSliding("transition3And4", mediaImageItem3, mediaVideoItem4, 5000, Transition.BEHAVIOR_LINEAR, TransitionSliding.DIRECTION_TOP_OUT_BOTTOM_IN);
    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());
    assertEquals("Transition Sliding", TransitionSliding.DIRECTION_TOP_OUT_BOTTOM_IN, transition3And4.getDirection());
    final MediaVideoItem mediaVideoItem5 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", videoItemFilename4, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem5);
    final TransitionSliding transition4And5 = mVideoEditorHelper.createTSliding("transition4And5", mediaVideoItem4, mediaVideoItem5, 8000, Transition.BEHAVIOR_MIDDLE_FAST, TransitionSliding.DIRECTION_BOTTOM_OUT_TOP_IN);
    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());
    assertEquals("Transition Sliding", TransitionSliding.DIRECTION_BOTTOM_OUT_TOP_IN, transition4And5.getDirection());
    final MediaVideoItem mediaVideoItem6 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", videoItemFilename5, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem6.setExtractBoundaries(0, 20000);
    mVideoEditor.addMediaItem(mediaVideoItem6);
    final TransitionSliding transition5And6 = mVideoEditorHelper.createTSliding("transition5And6", mediaVideoItem5, mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW, TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN);
    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());
    assertEquals("Transition Sliding", TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN, transition5And6.getDirection());
    flagForException = false;
    try {
        mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW, TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN - 1);
    } catch (IllegalArgumentException e) {
        flagForException = true;
    }
    assertTrue("Transition Sliding with Invalid Direction", flagForException);
    flagForException = false;
    try {
        mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1, TransitionSliding.DIRECTION_BOTTOM_OUT_TOP_IN + 1);
    } catch (IllegalArgumentException e) {
        flagForException = true;
    }
    assertTrue("Transition Sliding with Invalid behavior", flagForException);
    flagForException = false;
    try {
        mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, mediaVideoItem6, 2000, Transition.BEHAVIOR_SPEED_UP - 1, TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN);
    } catch (IllegalArgumentException e) {
        flagForException = true;
    }
    assertTrue("Transition Sliding with Invalid behavior", flagForException);
    flagForException = false;
    try {
        mVideoEditorHelper.createTSliding("transitiond6", mediaVideoItem5, mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1, TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN);
    } catch (IllegalArgumentException e) {
        flagForException = true;
    }
    assertTrue("Transition Sliding with Invalid behavior", flagForException);
}
Also used : TransitionSliding(android.media.videoeditor.TransitionSliding) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaImageItem(android.media.videoeditor.MediaImageItem) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 7 with TransitionSliding

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

the class VideoEditorExportTest method testExportMMS.

/**
     * To Test Export : With Video and Image : MMS use case
     *
     * @throws Exception
     */
@LargeTest
public void testExportMMS() throws Exception {
    final String videoItemFilename1 = INPUT_FILE_PATH + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp";
    final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
    final String videoItemFilename2 = INPUT_FILE_PATH + "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4";
    final String maskFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg";
    final String outFilename = mVideoEditorHelper.createRandomFile(mVideoEditor.getPath() + "/") + ".3gp";
    final MediaVideoItem mediaItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaItem1.setExtractBoundaries(2000, 7000);
    mVideoEditor.addMediaItem(mediaItem1);
    final TransitionAlpha transition1 = mVideoEditorHelper.createTAlpha("transition1", null, mediaItem1, 2000, Transition.BEHAVIOR_LINEAR, maskFilename, 50, true);
    mVideoEditor.addTransition(transition1);
    final MediaImageItem mediaItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", imageItemFilename1, 8000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaItem2);
    final MediaVideoItem mediaItem3 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaItem3.setExtractBoundaries(0, 8000);
    mVideoEditor.addMediaItem(mediaItem3);
    final TransitionSliding transition2And3 = mVideoEditorHelper.createTSliding("transition2", mediaItem2, mediaItem3, 4000, Transition.BEHAVIOR_MIDDLE_FAST, TransitionSliding.DIRECTION_RIGHT_OUT_LEFT_IN);
    mVideoEditor.addTransition(transition2And3);
    final TransitionCrossfade transition3 = mVideoEditorHelper.createTCrossFade("transition3", mediaItem3, null, 3500, Transition.BEHAVIOR_MIDDLE_SLOW);
    mVideoEditor.addTransition(transition3);
    final EffectColor effectColor = mVideoEditorHelper.createEffectItem(mediaItem2, "effect", 0, 3000, EffectColor.TYPE_COLOR, EffectColor.PINK);
    mediaItem2.addEffect(effectColor);
    mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_11_9);
    try {
        final int[] progressUpdate = new int[100];
        mVideoEditor.export(outFilename, MediaProperties.HEIGHT_144, MediaProperties.BITRATE_800K, new ExportProgressListener() {

            int i = 0;

            public void onProgress(VideoEditor ve, String outFileName, int progress) {
                progressUpdate[i++] = progress;
            }
        });
        mVideoEditorHelper.checkProgressCBValues(progressUpdate);
    } catch (Exception e) {
        assertTrue("Error in Export" + e.toString(), false);
    }
    final long storyBoardDuration = mediaItem1.getTimelineDuration() + mediaItem2.getTimelineDuration() + mediaItem3.getTimelineDuration() - transition2And3.getDuration();
    mVideoEditorHelper.validateExport(mVideoEditor, outFilename, MediaProperties.HEIGHT_144, 0, storyBoardDuration, MediaProperties.VCODEC_H264, MediaProperties.ACODEC_AAC_LC);
    mVideoEditorHelper.checkDeleteExistingFile(outFilename);
}
Also used : VideoEditor(android.media.videoeditor.VideoEditor) ExportProgressListener(android.media.videoeditor.VideoEditor.ExportProgressListener) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaImageItem(android.media.videoeditor.MediaImageItem) TransitionCrossfade(android.media.videoeditor.TransitionCrossfade) TransitionAlpha(android.media.videoeditor.TransitionAlpha) EffectColor(android.media.videoeditor.EffectColor) TransitionSliding(android.media.videoeditor.TransitionSliding) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

TransitionSliding (android.media.videoeditor.TransitionSliding)7 MediaImageItem (android.media.videoeditor.MediaImageItem)6 MediaVideoItem (android.media.videoeditor.MediaVideoItem)6 LargeTest (android.test.suitebuilder.annotation.LargeTest)6 TransitionAlpha (android.media.videoeditor.TransitionAlpha)5 TransitionCrossfade (android.media.videoeditor.TransitionCrossfade)5 TransitionFadeBlack (android.media.videoeditor.TransitionFadeBlack)4 VideoEditor (android.media.videoeditor.VideoEditor)4 ExportProgressListener (android.media.videoeditor.VideoEditor.ExportProgressListener)3 EffectColor (android.media.videoeditor.EffectColor)2 MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)2 Bitmap (android.graphics.Bitmap)1 Rect (android.graphics.Rect)1 AudioTrack (android.media.videoeditor.AudioTrack)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