Search in sources :

Example 1 with PreviewProgressListener

use of android.media.videoeditor.VideoEditor.PreviewProgressListener 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 2 with PreviewProgressListener

use of android.media.videoeditor.VideoEditor.PreviewProgressListener 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 3 with PreviewProgressListener

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

Example 4 with PreviewProgressListener

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

the class VideoEditorPreviewTest method testPreviewDuringExport.

/**
     *To test Preview : Export during preview
     */
@LargeTest
public void testPreviewDuringExport() throws Exception {
    final String videoItemFileName = INPUT_FILE_PATH + "H264_BP_640x480_30fps_192kbps_1_5.mp4";
    final Semaphore blockTillPreviewCompletes = new Semaphore(1);
    previewStart = false;
    previewStop = false;
    previewError = false;
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem1.setExtractBoundaries(0, 20000);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    mVideoEditor.generatePreview(new MediaProcessingProgressListener() {

        public void onProgress(Object item, int action, int progress) {
        }
    });
    long waitingTime = minWaitingTime + mVideoEditor.getDuration();
    blockTillPreviewCompletes.acquire();
    final String fileName = mVideoEditor.getPath() + "/test.3gp";
    final int height = MediaProperties.HEIGHT_480;
    final int bitrate = MediaProperties.BITRATE_512K;
    try {
        mVideoEditor.export(fileName, height, bitrate, new ExportProgressListener() {

            public void onProgress(VideoEditor ve, String outFileName, int progress) {
            }
        });
    } catch (IOException e) {
        assertTrue("UnExpected Error in Export" + e.toString(), false);
    }
    final SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    try {
        mVideoEditor.startPreview(surfaceHolder, 5000, -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();
                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 : VideoEditor(android.media.videoeditor.VideoEditor) ExportProgressListener(android.media.videoeditor.VideoEditor.ExportProgressListener) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) IOException(java.io.IOException) SurfaceHolder(android.view.SurfaceHolder) PreviewProgressListener(android.media.videoeditor.VideoEditor.PreviewProgressListener) OverlayData(android.media.videoeditor.VideoEditor.OverlayData) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 5 with PreviewProgressListener

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

the class VideoEditorPreviewTest method testPreviewWithDurationGreaterThanMediaDuration.

/**
     * To test Preview : Preview of current Effects applied (with from time >
     * total duration)
     */
@LargeTest
public void testPreviewWithDurationGreaterThanMediaDuration() throws Exception {
    final String videoItemFileName = INPUT_FILE_PATH + "H264_BP_640x480_30fps_192kbps_1_5.mp4";
    final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
    boolean flagForException = false;
    final Semaphore blockTillPreviewCompletes = new Semaphore(1);
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName, renderingMode);
    try {
        mediaVideoItem1.setExtractBoundaries(0, 20000);
    } catch (Exception e) {
        assertTrue("Exception during setExtract Boundaries", false);
    }
    mVideoEditor.addMediaItem(mediaVideoItem1);
    final SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    long waitingTime = minWaitingTime + (mVideoEditor.getDuration() - 30000);
    if (waitingTime < 0) {
        waitingTime = minWaitingTime;
    }
    blockTillPreviewCompletes.acquire();
    try {
        mVideoEditor.startPreview(surfaceHolder, 30000, -1, true, 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 (IllegalArgumentException e) {
        blockTillPreviewCompletes.release();
        flagForException = true;
    }
    blockTillPreviewCompletes.tryAcquire(waitingTime, TimeUnit.MILLISECONDS);
    assertTrue("Expected Error in Preview", flagForException);
    mVideoEditor.stopPreview();
    blockTillPreviewCompletes.release();
}
Also used : SurfaceHolder(android.view.SurfaceHolder) VideoEditor(android.media.videoeditor.VideoEditor) PreviewProgressListener(android.media.videoeditor.VideoEditor.PreviewProgressListener) MediaVideoItem(android.media.videoeditor.MediaVideoItem) OverlayData(android.media.videoeditor.VideoEditor.OverlayData) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

VideoEditor (android.media.videoeditor.VideoEditor)6 OverlayData (android.media.videoeditor.VideoEditor.OverlayData)6 PreviewProgressListener (android.media.videoeditor.VideoEditor.PreviewProgressListener)6 SurfaceHolder (android.view.SurfaceHolder)6 LargeTest (android.test.suitebuilder.annotation.LargeTest)5 MediaVideoItem (android.media.videoeditor.MediaVideoItem)4 MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)4 IOException (java.io.IOException)4 Semaphore (java.util.concurrent.Semaphore)4 MediaImageItem (android.media.videoeditor.MediaImageItem)2 TransitionAlpha (android.media.videoeditor.TransitionAlpha)2 EffectColor (android.media.videoeditor.EffectColor)1 Transition (android.media.videoeditor.Transition)1 TransitionCrossfade (android.media.videoeditor.TransitionCrossfade)1 TransitionFadeBlack (android.media.videoeditor.TransitionFadeBlack)1 TransitionSliding (android.media.videoeditor.TransitionSliding)1 ExportProgressListener (android.media.videoeditor.VideoEditor.ExportProgressListener)1