use of android.media.videoeditor.VideoEditor.MediaProcessingProgressListener 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.VideoEditor.MediaProcessingProgressListener in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorPerformance method testPerformanceGeneratePreviewWithTransitions.
/**
* To test the performance of generatePreview : with Transitions
*
* @throws Exception
*/
@LargeTest
public void testPerformanceGeneratePreviewWithTransitions() 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;
final int transitionBehavior = Transition.BEHAVIOR_MIDDLE_FAST;
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 TransitionCrossfade transitionCrossFade = new TransitionCrossfade("transitionCrossFade", mediaVideoItem, mediaImageItem, 5000, transitionBehavior);
mVideoEditor.addTransition(transitionCrossFade);
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);
averageTime += (duration2 - duration1);
}
final long durationToAddObjects = averageTime;
final float timeTaken = (float) durationToAddObjects * 1.0f / (float) NUM_OF_ITERATIONS;
loggingInfo[0] = "Time taken to Generate Preview with transition :" + timeTaken;
writeTimingInfo("testPerformanceGeneratePreviewWithTransitions:", loggingInfo);
}
use of android.media.videoeditor.VideoEditor.MediaProcessingProgressListener in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorStressTest method testStressLoadAndSave.
/**
* To stress test : load and save
*
* @throws Exception
*/
@LargeTest
public void testStressLoadAndSave() throws Exception {
final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
final String VideoItemFileName1 = INPUT_FILE_PATH + "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
final String VideoItemFileName2 = INPUT_FILE_PATH + "H264_BP_800x480_15fps_512kbps_1_17.mp4";
final String VideoItemFileName3 = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_1200kbps_AACLC_48khz_64kbps_m_1_17.3gp";
final String ImageItemFileName4 = INPUT_FILE_PATH + "IMG_640x480.jpg";
final String ImageItemFileName5 = INPUT_FILE_PATH + "IMG_176x144.jpg";
final String OverlayFile6 = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png";
final String[] loggingInfo = new String[1];
int i = 0;
final String[] projectPath = new String[10];
writeTestCaseHeader("testStressLoadAndSave");
getBeginMemory();
for (i = 0; i < 10; i++) {
projectPath[i] = mVideoEditorHelper.createRandomFile(PROJECT_LOCATION);
final VideoEditor mVideoEditor1 = mVideoEditorHelper.createVideoEditor(projectPath[i]);
final MediaVideoItem mediaItem1 = new MediaVideoItem(mVideoEditor1, "m1", VideoItemFileName1, renderingMode);
mVideoEditor1.addMediaItem(mediaItem1);
mediaItem1.setExtractBoundaries(0, 10000);
final MediaVideoItem mediaItem2 = new MediaVideoItem(mVideoEditor1, "m2", VideoItemFileName2, renderingMode);
mVideoEditor1.addMediaItem(mediaItem2);
mediaItem2.setExtractBoundaries(mediaItem2.getDuration() / 4, mediaItem2.getDuration() / 2);
final MediaVideoItem mediaItem3 = new MediaVideoItem(mVideoEditor1, "m3", VideoItemFileName3, renderingMode);
mVideoEditor1.addMediaItem(mediaItem3);
mediaItem3.setExtractBoundaries(mediaItem3.getDuration() / 2, mediaItem3.getDuration());
final MediaImageItem mediaItem4 = new MediaImageItem(mVideoEditor1, "m4", ImageItemFileName4, 5000, renderingMode);
mVideoEditor1.addMediaItem(mediaItem4);
final MediaImageItem mediaItem5 = new MediaImageItem(mVideoEditor1, "m5", ImageItemFileName5, 5000, renderingMode);
mVideoEditor1.addMediaItem(mediaItem5);
final EffectColor effectColor1 = mVideoEditorHelper.createEffectItem(mediaItem3, "effect1", 10000, 2000, EffectColor.TYPE_COLOR, EffectColor.GREEN);
mediaItem3.addEffect(effectColor1);
final Bitmap mBitmap = mVideoEditorHelper.getBitmap(OverlayFile6, 640, 480);
final OverlayFrame overlayFrame = mVideoEditorHelper.createOverlay(mediaItem4, "overlay", mBitmap, 4000, 1000);
mediaItem4.addOverlay(overlayFrame);
final TransitionCrossfade tranCrossfade = new TransitionCrossfade("transCF", mediaItem1, mediaItem2, 5000, Transition.BEHAVIOR_MIDDLE_FAST);
mVideoEditor1.addTransition(tranCrossfade);
final EffectColor effectColor2 = mVideoEditorHelper.createEffectItem(mediaItem4, "effect2", 0, mediaItem4.getDuration(), EffectColor.TYPE_COLOR, EffectColor.PINK);
mediaItem4.addEffect(effectColor2);
mVideoEditor1.generatePreview(new MediaProcessingProgressListener() {
public void onProgress(Object item, int action, int progress) {
}
});
mVideoEditor1.save();
mVideoEditor1.release();
getAfterMemory_updateLog(loggingInfo, false, i);
}
getAfterMemory_updateLog(loggingInfo, false, i);
/** Remove items and check for memory leak if any */
for (i = 0; i < 10; i++) {
final VideoEditor mVideoEditor1b = VideoEditorFactory.load(projectPath[i], true);
List<MediaItem> mediaList = mVideoEditor1b.getAllMediaItems();
assertEquals("Media Item List Size", 5, mediaList.size());
mediaList.get(3).removeEffect("effect1");
mediaList.get(3).removeEffect("effect2");
mediaList.get(2).removeOverlay("overlay");
mVideoEditor1b.removeTransition("transCF");
mVideoEditor1b.removeMediaItem("m5");
mVideoEditor1b.removeMediaItem("m4");
mVideoEditor1b.removeMediaItem("m3");
mVideoEditor1b.removeMediaItem("m2");
mVideoEditor1b.removeMediaItem("m1");
mVideoEditor1b.release();
getAfterMemory_updateLog(loggingInfo, true, i);
}
getAfterMemory_updateLog(loggingInfo, true, i);
}
use of android.media.videoeditor.VideoEditor.MediaProcessingProgressListener in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorPerformance method testPerformanceTransitionWithEffectOverlapping.
/**
* To test creation of story board with Transition and Two Effects, Effect
* overlapping transitions
*
* @throws Exception
*/
@LargeTest
public void testPerformanceTransitionWithEffectOverlapping() 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 renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
final int transitionDuration = 5000;
final int transitionBehavior = Transition.BEHAVIOR_MIDDLE_FAST;
final int effectItemStartTime1 = 5000;
final int effectItemDurationTime1 = 5000;
final int effectType1 = EffectColor.TYPE_COLOR;
final int effectColorType1 = EffectColor.GREEN;
final int effectItemStartTime2 = 5000;
final int effectItemDurationTime2 = 5000;
final int effectType2 = EffectColor.TYPE_COLOR;
final int effectColorType2 = EffectColor.GREEN;
int averageTime = 0;
final String[] loggingInfo = new String[1];
final MediaVideoItem mediaVideoItem1 = new MediaVideoItem(mVideoEditor, "mediaItem1", videoItemFileName1, renderingMode);
mVideoEditor.addMediaItem(mediaVideoItem1);
final MediaVideoItem mediaVideoItem2 = new MediaVideoItem(mVideoEditor, "mediaItem2", videoItemFileName2, renderingMode);
mVideoEditor.addMediaItem(mediaVideoItem2);
final TransitionCrossfade transitionCrossFade = new TransitionCrossfade("transitionCrossFade", mediaVideoItem1, mediaVideoItem2, transitionDuration, transitionBehavior);
mVideoEditor.addTransition(transitionCrossFade);
final EffectColor effectColor1 = new EffectColor(mediaVideoItem1, "effect1", effectItemStartTime1, effectItemDurationTime1, effectType1, effectColorType1);
mediaVideoItem1.addEffect(effectColor1);
final EffectColor effectColor2 = new EffectColor(mediaVideoItem2, "effect2", effectItemStartTime2, effectItemDurationTime2, effectType2, effectColorType2);
mediaVideoItem2.addEffect(effectColor2);
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);
averageTime += duration2 - duration1;
}
final long durationToAddObjects = (averageTime);
final float timeTaken = (float) durationToAddObjects * 1.0f / (float) NUM_OF_ITERATIONS;
loggingInfo[0] = "Time taken to TransitionWithEffectOverlapping :" + timeTaken;
writeTimingInfo("testPerformanceTransitionWithEffectOverlapping", loggingInfo);
}
use of android.media.videoeditor.VideoEditor.MediaProcessingProgressListener in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorPerformance method testPerformanceWithAudioTrack.
/**
* To test the performance : With an audio track
*
* @throws Exception
*/
@LargeTest
public void testPerformanceWithAudioTrack() throws Exception {
final String videoItemFileName1 = INPUT_FILE_PATH + "H264_BP_1080x720_30fps_800kbps_1_17.mp4";
final String audioFilename1 = INPUT_FILE_PATH + "AACLC_44.1kHz_256kbps_s_1_17.mp4";
final String audioFilename2 = INPUT_FILE_PATH + "AMRNB_8KHz_12.2Kbps_m_1_17.3gp";
final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
final int audioVolume = 50;
final String[] loggingInfo = new String[2];
int timeTaken = 0;
final MediaVideoItem mediaVideoItem = new MediaVideoItem(mVideoEditor, "mediaItem1", videoItemFileName1, renderingMode);
mVideoEditor.addMediaItem(mediaVideoItem);
final AudioTrack audioTrack1 = new AudioTrack(mVideoEditor, "Audio Track1", audioFilename1);
audioTrack1.disableDucking();
audioTrack1.setVolume(audioVolume);
mVideoEditor.addAudioTrack(audioTrack1);
long beginTime = SystemClock.uptimeMillis();
mVideoEditor.generatePreview(new MediaProcessingProgressListener() {
public void onProgress(Object item, int action, int progress) {
}
});
timeTaken = calculateTimeTaken(beginTime, 1);
loggingInfo[0] = "Time taken for 1st Audio Track (AACLC) :" + timeTaken;
final AudioTrack audioTrack2 = new AudioTrack(mVideoEditor, "Audio Track2", audioFilename2);
audioTrack2.enableLoop();
beginTime = SystemClock.uptimeMillis();
mVideoEditor.generatePreview(new MediaProcessingProgressListener() {
public void onProgress(Object item, int action, int progress) {
}
});
timeTaken = calculateTimeTaken(beginTime, 1);
loggingInfo[1] = "\n\tTime taken for 2nd Audio Track(AMRNB) :" + timeTaken;
writeTimingInfo("testPerformanceWithAudioTrack", loggingInfo);
}
Aggregations