Search in sources :

Example 6 with MediaProcessingProgressListener

use of android.media.videoeditor.VideoEditor.MediaProcessingProgressListener in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorPerformance method testPerformanceEffectOverlappingTransition.

/**
     * To test the performance of generatePreview : with Transitions and
     * Effect,Overlapping scenario
     *
     * @throws Exception
     */
@LargeTest
public void testPerformanceEffectOverlappingTransition() throws Exception {
    final String videoItemFileName1 = INPUT_FILE_PATH + "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
    final String videoItemFileName2 = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4";
    final int videoStartTime1 = 0;
    final int videoEndTime1 = 10000;
    final int videoStartTime2 = 0;
    final int videoEndTime2 = 10000;
    final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    final int transitionDuration = 5000;
    final int transitionBehavior = Transition.BEHAVIOR_MIDDLE_FAST;
    final int effectItemStartTime = 5000;
    final int effectItemDurationTime = 5000;
    final int effectType = EffectColor.TYPE_COLOR;
    final int effectColorType = EffectColor.GREEN;
    long averageDuration = 0;
    final String[] loggingInfo = new String[1];
    final MediaVideoItem mediaVideoItem1 = new MediaVideoItem(mVideoEditor, "mediaItem1", videoItemFileName1, renderingMode);
    mediaVideoItem1.setExtractBoundaries(videoStartTime1, videoEndTime1);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    final MediaVideoItem mediaVideoItem2 = new MediaVideoItem(mVideoEditor, "mediaItem2", videoItemFileName2, renderingMode);
    mediaVideoItem2.setExtractBoundaries(videoStartTime2, videoEndTime2);
    mVideoEditor.addMediaItem(mediaVideoItem2);
    final TransitionCrossfade transitionCrossFade = new TransitionCrossfade("transitionCrossFade", mediaVideoItem1, mediaVideoItem2, transitionDuration, transitionBehavior);
    mVideoEditor.addTransition(transitionCrossFade);
    final EffectColor effectColor = new EffectColor(mediaVideoItem1, "effect", effectItemStartTime, effectItemDurationTime, effectType, effectColorType);
    mediaVideoItem1.addEffect(effectColor);
    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();
        mVideoEditor.removeTransition(transitionCrossFade.getId());
        mVideoEditor.addTransition(transitionCrossFade);
        averageDuration += (duration2 - duration1);
    }
    SystemClock.uptimeMillis();
    final long durationToAddObjects = (averageDuration);
    final float timeTaken = (float) durationToAddObjects * 1.0f / (float) NUM_OF_ITERATIONS;
    loggingInfo[0] = "Time taken to testPerformanceEffectOverlappingTransition :" + timeTaken;
    writeTimingInfo("testPerformanceEffectOverlappingTransition:", loggingInfo);
}
Also used : EffectColor(android.media.videoeditor.EffectColor) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) TransitionCrossfade(android.media.videoeditor.TransitionCrossfade) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 7 with MediaProcessingProgressListener

use of android.media.videoeditor.VideoEditor.MediaProcessingProgressListener in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorExportTest method testExportTransition.

/**
     *To Test export : With Transition on Different Media Items
     */
@LargeTest
public void testExportTransition() throws Exception {
    final String videoItemFilename1 = INPUT_FILE_PATH + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.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 videoItemFilename3 = INPUT_FILE_PATH + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4";
    final String imageItemFilename2 = INPUT_FILE_PATH + "IMG_176x144.jpg";
    final String imageItemFilename3 = INPUT_FILE_PATH + "IMG_640x480.jpg";
    final String outFilename = mVideoEditorHelper.createRandomFile(mVideoEditor.getPath() + "/") + ".3gp";
    final String maskFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg";
    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 MediaVideoItem mediaItem4 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaItem4);
    mediaItem4.setExtractBoundaries(0, 8000);
    final TransitionCrossfade transition3And4 = mVideoEditorHelper.createTCrossFade("transition3", mediaItem3, mediaItem4, 3500, Transition.BEHAVIOR_MIDDLE_SLOW);
    mVideoEditor.addTransition(transition3And4);
    final MediaImageItem mediaItem5 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", imageItemFilename2, 7000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaItem5);
    final TransitionFadeBlack transition4And5 = mVideoEditorHelper.createTFadeBlack("transition4", mediaItem4, mediaItem5, 3500, Transition.BEHAVIOR_SPEED_DOWN);
    mVideoEditor.addTransition(transition4And5);
    final MediaImageItem mediaItem6 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", imageItemFilename3, 3000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaItem6);
    final TransitionSliding transition5And6 = mVideoEditorHelper.createTSliding("transition5", mediaItem5, mediaItem6, 1000, /*4000*/
    Transition.BEHAVIOR_SPEED_UP, TransitionSliding.DIRECTION_LEFT_OUT_RIGHT_IN);
    mVideoEditor.addTransition(transition5And6);
    final TransitionSliding transition6 = mVideoEditorHelper.createTSliding("transition6", mediaItem6, null, 1000, /*4000*/
    Transition.BEHAVIOR_SPEED_UP, TransitionSliding.DIRECTION_TOP_OUT_BOTTOM_IN);
    mVideoEditor.addTransition(transition6);
    mVideoEditor.generatePreview(new MediaProcessingProgressListener() {

        public void onProgress(Object item, int action, int progress) {
        }
    });
    try {
        final int[] progressUpdate = new int[100];
        mVideoEditor.export(outFilename, 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 (Exception e) {
        assertTrue("Error in Export" + e.toString(), false);
    }
    final long storyBoardDuration = mediaItem1.getTimelineDuration() + mediaItem2.getTimelineDuration() + mediaItem3.getTimelineDuration() - transition2And3.getDuration() + mediaItem4.getTimelineDuration() - transition3And4.getDuration() + mediaItem5.getTimelineDuration() - transition4And5.getDuration() + mediaItem6.getTimelineDuration() - transition5And6.getDuration();
    mVideoEditorHelper.validateExport(mVideoEditor, outFilename, MediaProperties.HEIGHT_720, 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) TransitionFadeBlack(android.media.videoeditor.TransitionFadeBlack) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) MediaImageItem(android.media.videoeditor.MediaImageItem) TransitionCrossfade(android.media.videoeditor.TransitionCrossfade) TransitionAlpha(android.media.videoeditor.TransitionAlpha) TransitionSliding(android.media.videoeditor.TransitionSliding) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 8 with MediaProcessingProgressListener

use of android.media.videoeditor.VideoEditor.MediaProcessingProgressListener in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorExportTest method testExportTwoVideos.

/**
     * To Test Export :Two Media Items added
     *
     * @throws Exception
     */
@LargeTest
public void testExportTwoVideos() throws Exception {
    final String videoItemFileName = INPUT_FILE_PATH + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp";
    final String videoItemFileName1 = INPUT_FILE_PATH + "H264_BP_640x480_12.5fps_256kbps_AACLC_16khz_24kbps_s_0_26.mp4";
    final String outFilename = mVideoEditorHelper.createRandomFile(mVideoEditor.getPath() + "/") + ".3gp";
    final MediaVideoItem mediaVideoItem = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem);
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    mVideoEditor.generatePreview(new MediaProcessingProgressListener() {

        public void onProgress(Object item, int action, int progress) {
        }
    });
    try {
        final int[] progressUpdate = new int[100];
        mVideoEditor.export(outFilename, 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 (Exception e) {
        assertTrue("Error in Export" + e.toString(), false);
    }
    mVideoEditorHelper.validateExport(mVideoEditor, outFilename, MediaProperties.HEIGHT_720, 0, (mediaVideoItem.getDuration() + mediaVideoItem1.getDuration()), 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) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 9 with MediaProcessingProgressListener

use of android.media.videoeditor.VideoEditor.MediaProcessingProgressListener in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorPreviewTest method validatePreviewProgress.

protected void validatePreviewProgress(int startMs, int endMs, boolean loop, long duration) throws Exception {
    final int[] progressUpdate = new int[100];
    final Semaphore blockTillPreviewCompletes = new Semaphore(1);
    previewStart = false;
    previewStop = false;
    previewError = false;
    mVideoEditor.generatePreview(new MediaProcessingProgressListener() {

        int i = 0;

        public void onProgress(Object item, int action, int progress) {
            progressUpdate[i++] = progress;
        }
    });
    mVideoEditorHelper.checkProgressCBValues(progressUpdate);
    final SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    long waitingTime = minWaitingTime;
    if (endMs == -1) {
        waitingTime += duration;
    } else {
        waitingTime += (endMs - startMs);
    }
    blockTillPreviewCompletes.acquire();
    try {
        mVideoEditor.startPreview(surfaceHolder, startMs, endMs, loop, 1, new PreviewProgressListener() {

            public void onProgress(VideoEditor videoEditor, long timeMs, OverlayData overlayData) {
                if (overlayData != null) {
                    if (overlayData.needsRendering()) {
                        overlayData.renderOverlay(MediaFrameworkTest.mDestBitmap);
                        mEventHandler.sendMessage(mEventHandler.obtainMessage(1, 2, 3));
                    }
                }
            }

            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();
    assertTrue("Preview Failed to start", previewStart);
    assertTrue("Preview Failed to stop", previewStop);
    assertFalse("Preview Error occurred", previewError);
    blockTillPreviewCompletes.release();
}
Also used : SurfaceHolder(android.view.SurfaceHolder) VideoEditor(android.media.videoeditor.VideoEditor) PreviewProgressListener(android.media.videoeditor.VideoEditor.PreviewProgressListener) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) OverlayData(android.media.videoeditor.VideoEditor.OverlayData) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException)

Example 10 with MediaProcessingProgressListener

use of android.media.videoeditor.VideoEditor.MediaProcessingProgressListener in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorPreviewTest method testStartPreviewAddRemoveMediaItems.

/**
     * To Test Preview : Add Media and Remove Media Item (Without any Media
     * Items in the story Board)
     */
@LargeTest
public void testStartPreviewAddRemoveMediaItems() throws Exception {
    final String videoItemFilename1 = INPUT_FILE_PATH + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_0_26.3gp";
    final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
    final String alphaFilename = INPUT_FILE_PATH + "TransitionSpiral_QVGA.jpg";
    boolean flagForException = false;
    final MediaVideoItem mediaVideoItem = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem.setExtractBoundaries(0, 15000);
    mVideoEditor.addMediaItem(mediaVideoItem);
    final MediaImageItem mediaImageItem = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaImageItem);
    final TransitionAlpha transition1And2 = mVideoEditorHelper.createTAlpha("transition", mediaVideoItem, mediaImageItem, 3000, Transition.BEHAVIOR_SPEED_UP, alphaFilename, 10, false);
    mVideoEditor.addTransition(transition1And2);
    final EffectColor effectColor = mVideoEditorHelper.createEffectItem(mediaImageItem, "effect", 5000, 3000, EffectColor.TYPE_COLOR, EffectColor.PINK);
    mediaImageItem.addEffect(effectColor);
    assertEquals("removing Media item 1", mediaVideoItem, mVideoEditor.removeMediaItem(mediaVideoItem.getId()));
    assertEquals("removing Media item 2", mediaImageItem, mVideoEditor.removeMediaItem(mediaImageItem.getId()));
    try {
        mVideoEditor.generatePreview(new MediaProcessingProgressListener() {

            public void onProgress(Object item, int action, int progress) {
            }
        });
        final SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        mVideoEditor.startPreview(surfaceHolder, 0, -1, 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();
            }

            public void onError(VideoEditor videoEditor, int error) {
                setPreviewError();
            }
        });
    } catch (IllegalArgumentException e) {
        flagForException = true;
    }
    assertTrue("Preview with removed Media Items", flagForException);
}
Also used : VideoEditor(android.media.videoeditor.VideoEditor) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) MediaImageItem(android.media.videoeditor.MediaImageItem) TransitionAlpha(android.media.videoeditor.TransitionAlpha) SurfaceHolder(android.view.SurfaceHolder) EffectColor(android.media.videoeditor.EffectColor) PreviewProgressListener(android.media.videoeditor.VideoEditor.PreviewProgressListener) OverlayData(android.media.videoeditor.VideoEditor.OverlayData) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)20 LargeTest (android.test.suitebuilder.annotation.LargeTest)19 MediaVideoItem (android.media.videoeditor.MediaVideoItem)17 MediaImageItem (android.media.videoeditor.MediaImageItem)12 VideoEditor (android.media.videoeditor.VideoEditor)11 TransitionCrossfade (android.media.videoeditor.TransitionCrossfade)7 ExportProgressListener (android.media.videoeditor.VideoEditor.ExportProgressListener)7 EffectColor (android.media.videoeditor.EffectColor)6 OverlayData (android.media.videoeditor.VideoEditor.OverlayData)6 SurfaceHolder (android.view.SurfaceHolder)6 AudioTrack (android.media.videoeditor.AudioTrack)5 PreviewProgressListener (android.media.videoeditor.VideoEditor.PreviewProgressListener)4 Semaphore (java.util.concurrent.Semaphore)4 TransitionAlpha (android.media.videoeditor.TransitionAlpha)3 IOException (java.io.IOException)3 Bitmap (android.graphics.Bitmap)2 Rect (android.graphics.Rect)2 EffectKenBurns (android.media.videoeditor.EffectKenBurns)2 MediaItem (android.media.videoeditor.MediaItem)2 OverlayFrame (android.media.videoeditor.OverlayFrame)2