use of android.media.videoeditor.Transition 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()));
}
use of android.media.videoeditor.Transition in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorAPITest method testVideoEditorAPI.
/**
* To test Video Editor API
*
* @throws Exception
*/
@LargeTest
public void testVideoEditorAPI() throws Exception {
final String videoItemFileName1 = INPUT_FILE_PATH + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4";
final String videoItemFileName2 = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp";
final String videoItemFileName3 = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4";
final String imageItemFileName1 = INPUT_FILE_PATH + "IMG_640x480.jpg";
final String imageItemFileName2 = INPUT_FILE_PATH + "IMG_176x144.jpg";
final String audioFilename1 = INPUT_FILE_PATH + "AMRNB_8KHz_12.2Kbps_m_1_17.3gp";
final String audioFilename2 = INPUT_FILE_PATH + "AACLC_48KHz_256Kbps_s_1_17.3gp";
final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
boolean flagForException = false;
TransitionCrossfade transition2And4;
final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName1, renderingMode);
mediaVideoItem1.setExtractBoundaries(0, 10000);
mVideoEditor.addMediaItem(mediaVideoItem1);
final MediaVideoItem mediaVideoItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", videoItemFileName2, renderingMode);
mediaVideoItem2.setExtractBoundaries(mediaVideoItem2.getDuration() / 4, mediaVideoItem2.getDuration() / 2);
mVideoEditor.addMediaItem(mediaVideoItem2);
final MediaVideoItem mediaVideoItem3 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", videoItemFileName3, renderingMode);
mediaVideoItem3.setExtractBoundaries(mediaVideoItem3.getDuration() / 2, mediaVideoItem3.getDuration());
mVideoEditor.addMediaItem(mediaVideoItem3);
final MediaImageItem mediaImageItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", imageItemFileName1, 5000, renderingMode);
final MediaImageItem mediaImageItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", imageItemFileName2, 5000, renderingMode);
List<MediaItem> mediaList = mVideoEditor.getAllMediaItems();
assertEquals("Media Item List Size", 3, mediaList.size());
mVideoEditor.insertMediaItem(mediaImageItem1, 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", mediaImageItem1, mediaList.get(2));
assertEquals("Media item 3", mediaVideoItem3, mediaList.get(3));
mVideoEditor.insertMediaItem(mediaImageItem2, mediaImageItem1.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", mediaImageItem1, mediaList.get(2));
assertEquals("Media item 5", mediaImageItem2, mediaList.get(3));
assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4));
mVideoEditor.moveMediaItem(mediaVideoItem1.getId(), mediaImageItem2.getId());
mediaList = mVideoEditor.getAllMediaItems();
assertEquals("Media Item List Size", 5, mediaList.size());
assertEquals("Media item 2", mediaVideoItem2, mediaList.get(0));
assertEquals("Media item 4", mediaImageItem1, mediaList.get(1));
assertEquals("Media item 5", mediaImageItem2, mediaList.get(2));
assertEquals("Media item 1", mediaVideoItem1, mediaList.get(3));
assertEquals("Media item 3", mediaVideoItem3, mediaList.get(4));
assertEquals("Media Item 1", mediaVideoItem1, mVideoEditor.getMediaItem(mediaVideoItem1.getId()));
flagForException = false;
transition2And4 = null;
try {
transition2And4 = mVideoEditorHelper.createTCrossFade("transition2And4", mediaVideoItem2, mediaImageItem1, 2000, Transition.BEHAVIOR_MIDDLE_FAST);
mVideoEditor.addTransition(transition2And4);
} catch (IllegalArgumentException e) {
flagForException = true;
}
assertFalse("Transition2and4 cannot be created", flagForException);
TransitionCrossfade transition1And3 = null;
flagForException = false;
try {
transition1And3 = mVideoEditorHelper.createTCrossFade("transition1And3", mediaVideoItem1, mediaVideoItem2, 5000, Transition.BEHAVIOR_MIDDLE_FAST);
mVideoEditor.addTransition(transition1And3);
} catch (IllegalArgumentException e) {
flagForException = true;
}
assertTrue("Transition1and3 cannot be created", flagForException);
List<Transition> transitionList = mVideoEditor.getAllTransitions();
assertEquals("Transition List", 1, transitionList.size());
assertEquals("Transition 2", transition2And4, mVideoEditor.getTransition(transition2And4.getId()));
final AudioTrack audioTrack = mVideoEditorHelper.createAudio(mVideoEditor, "audioTrack", audioFilename1);
mVideoEditor.addAudioTrack(audioTrack);
List<AudioTrack> audioList = mVideoEditor.getAllAudioTracks();
assertEquals("Audio List", 1, audioList.size());
final AudioTrack audioTrack1 = mVideoEditorHelper.createAudio(mVideoEditor, "audioTrack1", audioFilename2);
flagForException = false;
try {
mVideoEditor.addAudioTrack(audioTrack1);
} catch (IllegalArgumentException e) {
flagForException = true;
}
assertTrue("Audio Track support is 1 ", flagForException);
flagForException = false;
try {
mVideoEditor.insertAudioTrack(audioTrack1, "audioTrack");
} catch (IllegalArgumentException e) {
flagForException = true;
}
assertTrue("Audio Track supports is 1 ", flagForException);
assertEquals("Removing AudioTrack", audioTrack, mVideoEditor.removeAudioTrack(audioTrack.getId()));
assertEquals("Removing transition", transition2And4, mVideoEditor.removeTransition(transition2And4.getId()));
assertEquals("Removing Media Item", mediaVideoItem2, mVideoEditor.removeMediaItem(mediaVideoItem2.getId()));
mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_16_9);
assertEquals("Check Aspect Ratio", MediaProperties.ASPECT_RATIO_16_9, mVideoEditor.getAspectRatio());
long storyBoardDuration = mediaVideoItem1.getTimelineDuration() + mediaVideoItem3.getTimelineDuration() + mediaImageItem1.getDuration() + mediaImageItem2.getDuration();
assertEquals("Story Board Duration", storyBoardDuration, mVideoEditor.getDuration());
}
Aggregations