Search in sources :

Example 1 with OverlayData

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

the class VideoEditorPreviewTest method testPreviewWithRenderPreviewFrameWithoutGenerate.

/**
     * To test Preview : Preview of current Effects applied (with Render Preview
     * Frame)
     */
@LargeTest
public void testPreviewWithRenderPreviewFrameWithoutGenerate() throws Exception {
    final String videoItemFileName = INPUT_FILE_PATH + "H264_BP_640x480_30fps_256kbps_1_17.mp4";
    boolean flagForException = false;
    long duration = 0;
    OverlayData overlayData1 = new OverlayData();
    final MediaVideoItem mediaVideoItem = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem);
    final SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    duration = mVideoEditor.getDuration();
    /* RenderPreviewFrame returns -1 to indicate last frame */
    try {
        mVideoEditor.renderPreviewFrame(surfaceHolder, duration, overlayData1);
    } catch (IllegalStateException e) {
        flagForException = true;
    }
    assertTrue(" Render Preview Frame without generate", flagForException);
    duration = mVideoEditor.getDuration() + 1000;
    try {
        mVideoEditor.renderPreviewFrame(surfaceHolder, duration, overlayData1);
    } catch (IllegalArgumentException e) {
        flagForException = true;
    }
    assertTrue(" Preview time greater than duration", flagForException);
}
Also used : SurfaceHolder(android.view.SurfaceHolder) MediaVideoItem(android.media.videoeditor.MediaVideoItem) OverlayData(android.media.videoeditor.VideoEditor.OverlayData) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 2 with OverlayData

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

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

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

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

the class VideoEditorPreviewTest method testRenderPreviewFrame.

/**
     * To test render Preview Frame
     */
@LargeTest
public void testRenderPreviewFrame() throws Exception {
    final String videoItemFileName1 = INPUT_FILE_PATH + "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
    final String videoItemFileName2 = INPUT_FILE_PATH + "MPEG4_SP_800x480_515kbps_15fps_AMR_NB_8KHz_12.2kbps_m_0_26.mp4";
    final String videoItemFileName3 = INPUT_FILE_PATH + "H264_BP_640x480_30fps_256kbps_1_17.mp4";
    final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
    final String imageItemFilename2 = INPUT_FILE_PATH + "IMG_176x144.jpg";
    final String audioFilename = INPUT_FILE_PATH + "AMRNB_8KHz_12.2Kbps_m_1_17.3gp";
    OverlayData overlayData1 = new OverlayData();
    previewStart = false;
    previewStop = false;
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem1.setExtractBoundaries(0, 10000);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    final MediaVideoItem mediaVideoItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem1.setExtractBoundaries(mediaVideoItem2.getDuration() / 4, mediaVideoItem2.getDuration() / 2);
    mVideoEditor.addMediaItem(mediaVideoItem2);
    final MediaVideoItem mediaVideoItem3 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", videoItemFileName3, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem1.setExtractBoundaries(mediaVideoItem2.getDuration() / 2, mediaVideoItem2.getDuration());
    mVideoEditor.addMediaItem(mediaVideoItem3);
    final MediaImageItem mediaImageItem4 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", imageItemFilename1, 5000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    final MediaImageItem mediaImageItem5 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", imageItemFilename2, 5000, MediaItem.RENDERING_MODE_BLACK_BORDER);
    List<MediaItem> mediaList = mVideoEditor.getAllMediaItems();
    assertEquals("Media Item List Size", 3, mediaList.size());
    mVideoEditor.insertMediaItem(mediaImageItem4, mediaVideoItem2.getId());
    mediaList = mVideoEditor.getAllMediaItems();
    assertEquals("Media Item List Size", 4, mediaList.size());
    assertEquals("Media item 1", mediaVideoItem1, mediaList.get(0));
    assertEquals("Media item 2", mediaVideoItem2, mediaList.get(1));
    assertEquals("Media item 4", mediaImageItem4, mediaList.get(2));
    assertEquals("Media item 3", mediaVideoItem3, mediaList.get(3));
    mVideoEditor.insertMediaItem(mediaImageItem5, mediaImageItem4.getId());
    mediaList = mVideoEditor.getAllMediaItems();
    assertEquals("Media Item List Size", 5, mediaList.size());
    assertEquals("Media item 1", mediaVideoItem1, mediaList.get(0));
    assertEquals("Media item 2", mediaVideoItem2, mediaList.get(1));
    assertEquals("Media item 4", mediaImageItem4, mediaList.get(2));
    assertEquals("Media item 5", mediaImageItem5, mediaList.get(3));
    assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4));
    mVideoEditor.moveMediaItem(mediaVideoItem1.getId(), mediaImageItem5.getId());
    mediaList = mVideoEditor.getAllMediaItems();
    assertEquals("Media Item List Size", 5, mediaList.size());
    assertEquals("Media item 2", mediaVideoItem2, mediaList.get(0));
    assertEquals("Media item 4", mediaImageItem4, mediaList.get(1));
    assertEquals("Media item 5", mediaImageItem5, mediaList.get(2));
    assertEquals("Media item 1", mediaVideoItem1, mediaList.get(3));
    assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4));
    final TransitionCrossfade transition2And4CrossFade = mVideoEditorHelper.createTCrossFade("transition2And4CrossFade", mediaVideoItem2, mediaImageItem4, 2000, Transition.BEHAVIOR_MIDDLE_FAST);
    mVideoEditor.addTransition(transition2And4CrossFade);
    final TransitionCrossfade transition1And3CrossFade = mVideoEditorHelper.createTCrossFade("transition1And3CrossFade", mediaVideoItem1, mediaVideoItem3, 5000, Transition.BEHAVIOR_MIDDLE_FAST);
    mVideoEditor.addTransition(transition1And3CrossFade);
    final AudioTrack audioTrack = mVideoEditorHelper.createAudio(mVideoEditor, "a1", audioFilename);
    audioTrack.setExtractBoundaries(0, 2000);
    mVideoEditor.addAudioTrack(audioTrack);
    audioTrack.enableLoop();
    mVideoEditor.generatePreview(new MediaProcessingProgressListener() {

        public void onProgress(Object item, int action, int progress) {
        }
    });
    final SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    mVideoEditor.renderPreviewFrame(surfaceHolder, mVideoEditor.getDuration() / 4, overlayData1);
    Thread.sleep(1000);
    mVideoEditor.renderPreviewFrame(surfaceHolder, mVideoEditor.getDuration() / 2, overlayData1);
    Thread.sleep(1000);
    mVideoEditor.renderPreviewFrame(surfaceHolder, mVideoEditor.getDuration(), overlayData1);
}
Also used : SurfaceHolder(android.view.SurfaceHolder) MediaItem(android.media.videoeditor.MediaItem) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) MediaImageItem(android.media.videoeditor.MediaImageItem) OverlayData(android.media.videoeditor.VideoEditor.OverlayData) AudioTrack(android.media.videoeditor.AudioTrack) TransitionCrossfade(android.media.videoeditor.TransitionCrossfade) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

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