use of android.media.videoeditor.MediaVideoItem in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorAPITest method testVideoLessThanAudio.
/**
* To add Audio Track Greater than MediaItem Duration
*
* @throws Exception
*/
@LargeTest
public void testVideoLessThanAudio() throws Exception {
final String videoItemFileName1 = INPUT_FILE_PATH + "MPEG4_SP_720x480_30fps_280kbps_AACLC_48kHz_96kbps_s_0_21.mp4";
final String audioTrackFilename = INPUT_FILE_PATH + "AACLC_48KHz_256Kbps_s_1_17.3gp";
final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName1, renderingMode);
mVideoEditor.addMediaItem(mediaVideoItem1);
final AudioTrack audioTrack = mVideoEditorHelper.createAudio(mVideoEditor, "audioTrackId", audioTrackFilename);
mVideoEditor.addAudioTrack(audioTrack);
assertEquals("Storyboard = mediaItem Duration", mediaVideoItem1.getDuration(), mVideoEditor.getDuration());
assertTrue("Audio Duration > mediaItem Duration", (audioTrack.getDuration() > mediaVideoItem1.getDuration() ? true : false));
}
use of android.media.videoeditor.MediaVideoItem 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);
}
use of android.media.videoeditor.MediaVideoItem in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorPreviewTest method testPreviewWithOverlayEffectKenBurn.
/**
* To test Preview : Preview of current work having Overlay and Effect
* applied
*/
@LargeTest
public void testPreviewWithOverlayEffectKenBurn() throws Exception {
final String videoItemFileName = INPUT_FILE_PATH + "H264_BP_640x480_30fps_192kbps_1_5.mp4";
final String imageItemFileName = INPUT_FILE_PATH + "IMG_640x480.jpg";
final String videoItemFileName1 = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4";
final String overlayFilename = INPUT_FILE_PATH + "IMG_640x480_Overlay1.png";
final Semaphore blockTillPreviewCompletes = new Semaphore(1);
previewStart = false;
previewStop = false;
final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFileName, MediaItem.RENDERING_MODE_BLACK_BORDER);
mVideoEditor.addMediaItem(mediaVideoItem1);
final MediaImageItem mediaImageItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", imageItemFileName, 10000, MediaItem.RENDERING_MODE_BLACK_BORDER);
mVideoEditor.addMediaItem(mediaImageItem2);
final MediaVideoItem mediaVideoItem3 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER);
mVideoEditor.addMediaItem(mediaVideoItem3);
final EffectColor effectColor = mVideoEditorHelper.createEffectItem(mediaVideoItem1, "Effect1", 1000, 3000, EffectColor.TYPE_COLOR, EffectColor.GREEN);
mediaVideoItem1.addEffect(effectColor);
final Rect startRect = new Rect((mediaImageItem2.getHeight() / 3), (mediaImageItem2.getWidth() / 3), (mediaImageItem2.getHeight() / 2), (mediaImageItem2.getWidth() / 2));
final Rect endRect = new Rect(0, 0, mediaImageItem2.getWidth(), mediaImageItem2.getHeight());
final EffectKenBurns kbeffectOnMI2 = new EffectKenBurns(mediaImageItem2, "KBOnM2", startRect, endRect, 0, 10000);
assertNotNull("EffectKenBurns", kbeffectOnMI2);
mediaImageItem2.addEffect(kbeffectOnMI2);
final Bitmap mBitmap = mVideoEditorHelper.getBitmap(overlayFilename, 640, 480);
final OverlayFrame overlayFrame = mVideoEditorHelper.createOverlay(mediaVideoItem3, "OverlayID", mBitmap, (mediaImageItem2.getDuration() / 4), (mediaVideoItem3.getDuration() / 3));
mediaVideoItem3.addOverlay(overlayFrame);
validatePreviewProgress(5000, -1, false, mVideoEditor.getDuration());
}
use of android.media.videoeditor.MediaVideoItem 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.MediaVideoItem in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorPerformance method testPerformanceThumbnailVideoItem.
/**
* To test the performance of thumbnail extraction
*
* @throws Exception
*/
@LargeTest
public void testPerformanceThumbnailVideoItem() throws Exception {
final String videoItemFileName = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_512kbps_AACLC_48khz_132kbps_s_0_26.mp4";
final int videoItemStartTime = 0;
final int videoItemEndTime = 20000;
final int renderingMode = MediaItem.RENDERING_MODE_BLACK_BORDER;
final String[] loggingInfo = new String[1];
final MediaVideoItem mediaVideoItem = new MediaVideoItem(mVideoEditor, "m1", videoItemFileName, renderingMode);
mediaVideoItem.setExtractBoundaries(videoItemStartTime, videoItemEndTime);
int timeTaken = 0;
long beginTime = SystemClock.uptimeMillis();
for (int i = 0; i < NUM_OF_ITERATIONS; i++) {
mediaVideoItem.getThumbnail(mediaVideoItem.getWidth() / 2, mediaVideoItem.getHeight() / 2, i);
}
timeTaken = calculateTimeTaken(beginTime, NUM_OF_ITERATIONS);
loggingInfo[0] = "Duration taken to get Video Thumbnails :" + timeTaken;
writeTimingInfo("testPerformanceThumbnailVideoItem (in mSec)", loggingInfo);
}
Aggregations