Search in sources :

Example 96 with MediaVideoItem

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

the class VideoEditorAPITest method testAllEffects.

/**
     * To test Effect Color.
     */
@LargeTest
public void testAllEffects() throws Exception {
    final String videoItemFileName = INPUT_FILE_PATH + "MPEG4_SP_640x480_30fps_512Kbps_0_27.mp4";
    boolean flagForException = false;
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    final EffectColor effectColor1 = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect1", 1000, 1000, EffectColor.TYPE_COLOR, EffectColor.PINK);
    mediaVideoItem1.addEffect(effectColor1);
    assertEquals("Associated Media Item", mediaVideoItem1, effectColor1.getMediaItem());
    assertTrue("Effect Id", effectColor1.getId().equals("effect1"));
    assertEquals("Effect StartTime", 1000, effectColor1.getStartTime());
    assertEquals("Effect EndTime", 1000, effectColor1.getDuration());
    assertEquals("Effect Type", EffectColor.TYPE_COLOR, effectColor1.getType());
    assertEquals("Effect Color", EffectColor.PINK, effectColor1.getColor());
    final EffectColor effectColor2 = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect2", 2000, 1000, EffectColor.TYPE_COLOR, EffectColor.GRAY);
    mediaVideoItem1.addEffect(effectColor2);
    assertEquals("Associated Media Item", mediaVideoItem1, effectColor2.getMediaItem());
    assertTrue("Effect Id", effectColor2.getId().equals("effect2"));
    assertEquals("Effect StartTime", 2000, effectColor2.getStartTime());
    assertEquals("Effect EndTime", 1000, effectColor2.getDuration());
    assertEquals("Effect Type", EffectColor.TYPE_COLOR, effectColor2.getType());
    assertEquals("Effect Color", EffectColor.GRAY, effectColor2.getColor());
    final EffectColor effectColor3 = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect3", 3000, 1000, EffectColor.TYPE_COLOR, EffectColor.GREEN);
    mediaVideoItem1.addEffect(effectColor3);
    assertEquals("Associated Media Item", mediaVideoItem1, effectColor3.getMediaItem());
    assertTrue("Effect Id", effectColor3.getId().equals("effect3"));
    assertEquals("Effect StartTime", 3000, effectColor3.getStartTime());
    assertEquals("Effect EndTime", 1000, effectColor3.getDuration());
    assertEquals("Effect Type", EffectColor.TYPE_COLOR, effectColor3.getType());
    assertEquals("Effect Color", EffectColor.GREEN, effectColor3.getColor());
    final EffectColor effectColor4 = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect4", 4000, 1000, EffectColor.TYPE_GRADIENT, EffectColor.PINK);
    mediaVideoItem1.addEffect(effectColor4);
    assertEquals("Associated Media Item", mediaVideoItem1, effectColor4.getMediaItem());
    assertTrue("Effect Id", effectColor4.getId().equals("effect4"));
    assertEquals("Effect StartTime", 4000, effectColor4.getStartTime());
    assertEquals("Effect EndTime", 1000, effectColor4.getDuration());
    assertEquals("Effect Type", EffectColor.TYPE_GRADIENT, effectColor4.getType());
    assertEquals("Effect Color", EffectColor.PINK, effectColor4.getColor());
    final EffectColor effectColor5 = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect5", 5000, 1000, EffectColor.TYPE_GRADIENT, EffectColor.GRAY);
    mediaVideoItem1.addEffect(effectColor5);
    assertEquals("Associated Media Item", mediaVideoItem1, effectColor5.getMediaItem());
    assertTrue("Effect Id", effectColor5.getId().equals("effect5"));
    assertEquals("Effect StartTime", 5000, effectColor5.getStartTime());
    assertEquals("Effect EndTime", 1000, effectColor5.getDuration());
    assertEquals("Effect Type", EffectColor.TYPE_GRADIENT, effectColor5.getType());
    assertEquals("Effect Color", EffectColor.GRAY, effectColor5.getColor());
    final EffectColor effectColor6 = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect6", 6000, 1000, EffectColor.TYPE_GRADIENT, EffectColor.GREEN);
    mediaVideoItem1.addEffect(effectColor6);
    assertEquals("Associated Media Item", mediaVideoItem1, effectColor6.getMediaItem());
    assertTrue("Effect Id", effectColor6.getId().equals("effect6"));
    assertEquals("Effect StartTime", 6000, effectColor6.getStartTime());
    assertEquals("Effect EndTime", 1000, effectColor6.getDuration());
    assertEquals("Effect Type", EffectColor.TYPE_GRADIENT, effectColor6.getType());
    assertEquals("Effect Color", EffectColor.GREEN, effectColor6.getColor());
    final EffectColor effectColor7 = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect7", 7000, 1000, EffectColor.TYPE_FIFTIES, 0);
    mediaVideoItem1.addEffect(effectColor7);
    assertEquals("Associated Media Item", mediaVideoItem1, effectColor7.getMediaItem());
    assertTrue("Effect Id", effectColor7.getId().equals("effect7"));
    assertEquals("Effect StartTime", 7000, effectColor7.getStartTime());
    assertEquals("Effect EndTime", 1000, effectColor7.getDuration());
    assertEquals("Effect Type", EffectColor.TYPE_FIFTIES, effectColor7.getType());
    assertEquals("Effect Color", -1, effectColor7.getColor());
    final EffectColor effectColor8 = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect8", 8000, 1000, EffectColor.TYPE_SEPIA, 0);
    mediaVideoItem1.addEffect(effectColor8);
    assertEquals("Associated Media Item", mediaVideoItem1, effectColor8.getMediaItem());
    assertTrue("Effect Id", effectColor8.getId().equals("effect8"));
    assertEquals("Effect StartTime", 8000, effectColor8.getStartTime());
    assertEquals("Effect EndTime", 1000, effectColor8.getDuration());
    assertEquals("Effect Type", EffectColor.TYPE_SEPIA, effectColor8.getType());
    assertEquals("Effect Color", -1, effectColor8.getColor());
    final EffectColor effectColor9 = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect9", 9000, 1000, EffectColor.TYPE_NEGATIVE, 0);
    mediaVideoItem1.addEffect(effectColor9);
    assertEquals("Associated Media Item", mediaVideoItem1, effectColor9.getMediaItem());
    assertTrue("Effect Id", effectColor9.getId().equals("effect9"));
    assertEquals("Effect StartTime", 9000, effectColor9.getStartTime());
    assertEquals("Effect EndTime", 1000, effectColor9.getDuration());
    assertEquals("Effect Type", EffectColor.TYPE_NEGATIVE, effectColor9.getType());
    assertEquals("Effect Color", -1, effectColor9.getColor());
    try {
        mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect9", 9000, 1000, EffectColor.TYPE_COLOR - 1, 0);
    } catch (IllegalArgumentException e) {
        flagForException = true;
    }
    assertTrue("Effect type Invalid", flagForException);
    flagForException = false;
    try {
        mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect9", 9000, 1000, EffectColor.TYPE_FIFTIES + 1, 0);
    } catch (IllegalArgumentException e) {
        flagForException = true;
    }
    assertTrue("Effect type Invalid", flagForException);
    try {
        mVideoEditorHelper.createEffectItem(mediaVideoItem1, "effect10", 10000, 1000, EffectColor.TYPE_FIFTIES + EffectColor.TYPE_GRADIENT, 0);
    } catch (IllegalArgumentException e) {
        flagForException = true;
    }
    assertTrue("Effect type Invalid", flagForException);
}
Also used : EffectColor(android.media.videoeditor.EffectColor) MediaVideoItem(android.media.videoeditor.MediaVideoItem) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 97 with MediaVideoItem

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

the class VideoEditorPerformance method testThumbnailH264AnIFrame.

/**
     *To test ThumbnailList for H264
     */
@LargeTest
public void testThumbnailH264AnIFrame() throws Exception {
    final String videoItemFilename = INPUT_FILE_PATH + "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
    final int outWidth = 1080;
    final int outHeight = 720;
    final int atTime = 3000;
    int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    final String[] loggingInfo = new String[1];
    long durationToAddObjects = 0;
    final MediaVideoItem mediaVideoItem = new MediaVideoItem(mVideoEditor, "m1", videoItemFilename, renderingMode);
    assertNotNull("MediaVideoItem", mediaVideoItem);
    for (int i = 0; i < NUM_OF_ITERATIONS; i++) {
        final long duration1 = SystemClock.uptimeMillis();
        mediaVideoItem.getThumbnail(outWidth, outHeight, atTime + i);
        final long duration2 = SystemClock.uptimeMillis();
        durationToAddObjects += (duration2 - duration1);
    }
    final float timeTaken = (float) durationToAddObjects * 1.0f / (float) NUM_OF_ITERATIONS;
    loggingInfo[0] = "Time taken Thumbnail generation :" + timeTaken;
    writeTimingInfo("testThumbnailH264AnIFrame", loggingInfo);
}
Also used : MediaVideoItem(android.media.videoeditor.MediaVideoItem) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 98 with MediaVideoItem

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

the class VideoEditorPerformance method testPerformanceOverlayVideoItem.

/**
     * To test the performance of adding and removing the overlay to media item
     *
     * @throws Exception
     */
@LargeTest
public void testPerformanceOverlayVideoItem() throws Exception {
    final String videoItemFileName1 = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4";
    final int videoItemStartTime1 = 0;
    final int videoItemEndTime1 = 10000;
    final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    final String overlayFilename = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png";
    final int overlayStartTime = 1000;
    final int overlayDuration = 5000;
    final String[] loggingInfo = new String[2];
    MediaVideoItem mediaVideoItem = null;
    try {
        mediaVideoItem = new MediaVideoItem(mVideoEditor, "m0", videoItemFileName1, renderingMode);
        mediaVideoItem.setExtractBoundaries(videoItemStartTime1, videoItemEndTime1);
    } catch (Exception e1) {
        assertTrue("Can not create Video Item with file name = " + e1.toString(), false);
    }
    final OverlayFrame[] overlayFrame = new OverlayFrame[NUM_OF_ITERATIONS];
    final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFilename, 640, 480);
    int timeTaken = 0;
    long beginTime = SystemClock.uptimeMillis();
    for (int i = 0; i < NUM_OF_ITERATIONS; i++) {
        overlayFrame[i] = new OverlayFrame(mediaVideoItem, "overlay" + i, mBitmap, overlayStartTime, overlayDuration);
        mediaVideoItem.addOverlay(overlayFrame[i]);
    }
    timeTaken = calculateTimeTaken(beginTime, NUM_OF_ITERATIONS);
    loggingInfo[0] = "Time taken to add & create Overlay :" + timeTaken;
    beginTime = SystemClock.uptimeMillis();
    for (int i = 0; i < NUM_OF_ITERATIONS; i++) {
        assertEquals("Removing Overlays", overlayFrame[i], mediaVideoItem.removeOverlay((overlayFrame[i].getId())));
    }
    timeTaken = calculateTimeTaken(beginTime, NUM_OF_ITERATIONS);
    loggingInfo[1] = "\n\tTime taken to remove  Overlay :" + timeTaken;
    writeTimingInfo("testPerformanceOverlayVideoItem (in mSec)", loggingInfo);
}
Also used : Bitmap(android.graphics.Bitmap) MediaVideoItem(android.media.videoeditor.MediaVideoItem) OverlayFrame(android.media.videoeditor.OverlayFrame) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 99 with MediaVideoItem

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

the class VideoEditorPerformance method testPerformanceWithKenBurn.

/**
     * To test the performance of generatePreview : with KenBurn
     *
     * @throws Exception
     */
@LargeTest
public void testPerformanceWithKenBurn() throws Exception {
    final String videoItemFileName = INPUT_FILE_PATH + "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
    final String imageItemFileName = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
    final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    long averageTime = 0;
    final String[] loggingInfo = new String[1];
    final MediaVideoItem mediaVideoItem = new MediaVideoItem(mVideoEditor, "mediaItem1", videoItemFileName, renderingMode);
    mediaVideoItem.setExtractBoundaries(0, 10000);
    mVideoEditor.addMediaItem(mediaVideoItem);
    final MediaImageItem mediaImageItem = new MediaImageItem(mVideoEditor, "mediaItem2", imageItemFileName, 10000, renderingMode);
    mVideoEditor.addMediaItem(mediaImageItem);
    final Rect startRect = new Rect((mediaImageItem.getHeight() / 3), (mediaImageItem.getWidth() / 3), (mediaImageItem.getHeight() / 2), (mediaImageItem.getWidth() / 2));
    final Rect endRect = new Rect(0, 0, mediaImageItem.getWidth(), mediaImageItem.getHeight());
    final EffectKenBurns kbEffectOnMediaItem = new EffectKenBurns(mediaImageItem, "KBOnM2", startRect, endRect, 500, 3000);
    mediaImageItem.addEffect(kbEffectOnMediaItem);
    for (int i = 0; i < NUM_OF_ITERATIONS; i++) {
        final long duration1 = SystemClock.uptimeMillis();
        mVideoEditor.generatePreview(new MediaProcessingProgressListener() {

            public void onProgress(Object item, int action, int progress) {
            }
        });
        final long duration2 = SystemClock.uptimeMillis();
        mediaImageItem.removeEffect(kbEffectOnMediaItem.getId());
        mediaImageItem.addEffect(kbEffectOnMediaItem);
        averageTime += duration2 - duration1;
    }
    final long durationToAddObjects = (averageTime);
    final float timeTaken = (float) durationToAddObjects * 1.0f / (float) NUM_OF_ITERATIONS;
    loggingInfo[0] = "Time taken to Generate KenBurn Effect :" + timeTaken;
    writeTimingInfo("testPerformanceWithKenBurn", loggingInfo);
}
Also used : Rect(android.graphics.Rect) EffectKenBurns(android.media.videoeditor.EffectKenBurns) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) MediaImageItem(android.media.videoeditor.MediaImageItem) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 100 with MediaVideoItem

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

the class VideoEditorExportTest method testExportWithoutMediaItemsAddRemove.

/**
     * To Test Export : With Media Items add and removed in the story Board
     *
     * @throws Exception
     */
@LargeTest
public void testExportWithoutMediaItemsAddRemove() 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_640x480.jpg";
    final String maskFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg";
    boolean flagForException = false;
    final MediaVideoItem mediaItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaItem1.setExtractBoundaries(0, 15000);
    mVideoEditor.addMediaItem(mediaItem1);
    final MediaImageItem mediaItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaItem2);
    final TransitionAlpha transition1 = mVideoEditorHelper.createTAlpha("transition1", mediaItem1, mediaItem2, 3000, Transition.BEHAVIOR_LINEAR, maskFilename, 50, false);
    mVideoEditor.addTransition(transition1);
    final EffectColor effectColor = mVideoEditorHelper.createEffectItem(mediaItem2, "effect", 12000, 3000, EffectColor.TYPE_COLOR, EffectColor.PINK);
    mediaItem2.addEffect(effectColor);
    mVideoEditor.removeMediaItem(mediaItem1.getId());
    mVideoEditor.removeMediaItem(mediaItem2.getId());
    try {
        final int[] progressUpdate = new int[100];
        mVideoEditor.export("/sdcard/Test.3gp", MediaProperties.HEIGHT_720, MediaProperties.BITRATE_800K, new ExportProgressListener() {

            int i = 0;

            public void onProgress(VideoEditor ve, String outFileName, int progress) {
                progressUpdate[i++] = progress;
            }
        });
        mVideoEditorHelper.checkProgressCBValues(progressUpdate);
    } catch (IllegalStateException e) {
        flagForException = true;
    }
    assertTrue("Export with MediaItem added and removed", flagForException);
}
Also used : VideoEditor(android.media.videoeditor.VideoEditor) EffectColor(android.media.videoeditor.EffectColor) ExportProgressListener(android.media.videoeditor.VideoEditor.ExportProgressListener) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaImageItem(android.media.videoeditor.MediaImageItem) TransitionAlpha(android.media.videoeditor.TransitionAlpha) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

MediaVideoItem (android.media.videoeditor.MediaVideoItem)119 LargeTest (android.test.suitebuilder.annotation.LargeTest)115 Bitmap (android.graphics.Bitmap)39 MediaImageItem (android.media.videoeditor.MediaImageItem)28 MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)17 EffectColor (android.media.videoeditor.EffectColor)16 TransitionCrossfade (android.media.videoeditor.TransitionCrossfade)15 VideoEditor (android.media.videoeditor.VideoEditor)15 AudioTrack (android.media.videoeditor.AudioTrack)12 OverlayFrame (android.media.videoeditor.OverlayFrame)11 ExportProgressListener (android.media.videoeditor.VideoEditor.ExportProgressListener)11 TransitionAlpha (android.media.videoeditor.TransitionAlpha)9 Semaphore (java.util.concurrent.Semaphore)9 OverlayData (android.media.videoeditor.VideoEditor.OverlayData)7 SurfaceHolder (android.view.SurfaceHolder)7 TransitionFadeBlack (android.media.videoeditor.TransitionFadeBlack)6 TransitionSliding (android.media.videoeditor.TransitionSliding)6 Rect (android.graphics.Rect)5 EffectKenBurns (android.media.videoeditor.EffectKenBurns)5 MediaItem (android.media.videoeditor.MediaItem)5