Search in sources :

Example 21 with MediaItem

use of android.media.videoeditor.MediaItem in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorImpl method insertMediaItem.

/*
     * {@inheritDoc}
     */
public synchronized void insertMediaItem(MediaItem mediaItem, String afterMediaItemId) {
    if (mMediaItems.contains(mediaItem)) {
        throw new IllegalArgumentException("Media item already exists: " + mediaItem.getId());
    }
    if (afterMediaItemId == null) {
        mMANativeHelper.setGeneratePreview(true);
        if (mMediaItems.size() > 0) {
            /**
                 *  Invalidate the transition at the beginning of the timeline
                 */
            removeTransitionBefore(0);
        }
        mMediaItems.add(0, mediaItem);
        computeTimelineDuration();
        generateProjectThumbnail();
    } else {
        final int mediaItemCount = mMediaItems.size();
        for (int i = 0; i < mediaItemCount; i++) {
            final MediaItem mi = mMediaItems.get(i);
            if (mi.getId().equals(afterMediaItemId)) {
                mMANativeHelper.setGeneratePreview(true);
                /**
                     *  Invalidate the transition at this position
                     */
                removeTransitionAfter(i);
                /**
                     *  Insert the new media item
                     */
                mMediaItems.add(i + 1, mediaItem);
                computeTimelineDuration();
                return;
            }
        }
        throw new IllegalArgumentException("MediaItem not found: " + afterMediaItemId);
    }
}
Also used : MediaItem(android.media.videoeditor.MediaItem)

Example 22 with MediaItem

use of android.media.videoeditor.MediaItem in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorImpl method parseMediaItem.

/**
     * Parse the media item
     *
     * @param parser The parser
     * @return The media item
     */
private MediaItem parseMediaItem(XmlPullParser parser) throws IOException {
    final String mediaItemId = parser.getAttributeValue("", ATTR_ID);
    final String type = parser.getAttributeValue("", ATTR_TYPE);
    final String filename = parser.getAttributeValue("", ATTR_FILENAME);
    final int renderingMode = Integer.parseInt(parser.getAttributeValue("", ATTR_RENDERING_MODE));
    final MediaItem currentMediaItem;
    if (MediaImageItem.class.getSimpleName().equals(type)) {
        final long durationMs = Long.parseLong(parser.getAttributeValue("", ATTR_DURATION));
        currentMediaItem = new MediaImageItem(this, mediaItemId, filename, durationMs, renderingMode);
    } else if (MediaVideoItem.class.getSimpleName().equals(type)) {
        final long beginMs = Long.parseLong(parser.getAttributeValue("", ATTR_BEGIN_TIME));
        final long endMs = Long.parseLong(parser.getAttributeValue("", ATTR_END_TIME));
        final int volume = Integer.parseInt(parser.getAttributeValue("", ATTR_VOLUME));
        final boolean muted = Boolean.parseBoolean(parser.getAttributeValue("", ATTR_MUTED));
        final String audioWaveformFilename = parser.getAttributeValue("", ATTR_AUDIO_WAVEFORM_FILENAME);
        currentMediaItem = new MediaVideoItem(this, mediaItemId, filename, renderingMode, beginMs, endMs, volume, muted, audioWaveformFilename);
        final long beginTimeMs = Long.parseLong(parser.getAttributeValue("", ATTR_BEGIN_TIME));
        final long endTimeMs = Long.parseLong(parser.getAttributeValue("", ATTR_END_TIME));
        ((MediaVideoItem) currentMediaItem).setExtractBoundaries(beginTimeMs, endTimeMs);
        final int volumePercent = Integer.parseInt(parser.getAttributeValue("", ATTR_VOLUME));
        ((MediaVideoItem) currentMediaItem).setVolume(volumePercent);
    } else {
        throw new IllegalArgumentException("Unknown media item type: " + type);
    }
    return currentMediaItem;
}
Also used : MediaItem(android.media.videoeditor.MediaItem) MediaImageItem(android.media.videoeditor.MediaImageItem)

Example 23 with MediaItem

use of android.media.videoeditor.MediaItem 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);
}
Also used : VideoEditor(android.media.videoeditor.VideoEditor) MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaProcessingProgressListener(android.media.videoeditor.VideoEditor.MediaProcessingProgressListener) MediaImageItem(android.media.videoeditor.MediaImageItem) OverlayFrame(android.media.videoeditor.OverlayFrame) TransitionCrossfade(android.media.videoeditor.TransitionCrossfade) Bitmap(android.graphics.Bitmap) EffectColor(android.media.videoeditor.EffectColor) MediaItem(android.media.videoeditor.MediaItem) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 24 with MediaItem

use of android.media.videoeditor.MediaItem in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorPreviewTest method testPreviewTheStoryBoard.

// -----------------------------------------------------------------
// Preview
// -----------------------------------------------------------------
/**
     *To test Preview : FULL Preview of current work (beginning till end)
     */
@LargeTest
public void testPreviewTheStoryBoard() 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_256kbps_0_30.mp4";
    final String videoItemFileName3 = INPUT_FILE_PATH + "H263_profile0_176x144_15fps_256kbps_AACLC_32kHz_128kbps_s_1_17.3gp";
    previewStart = false;
    previewStop = false;
    final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem1", videoItemFileName1, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem1.setExtractBoundaries(0, 10000);
    mVideoEditor.addMediaItem(mediaVideoItem1);
    final MediaVideoItem mediaVideoItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem2", videoItemFileName2, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mVideoEditor.addMediaItem(mediaVideoItem2);
    mediaVideoItem2.setExtractBoundaries(0, 10000);
    final MediaVideoItem mediaVideoItem3 = mVideoEditorHelper.createMediaItem(mVideoEditor, "mediaVideoItem3", videoItemFileName3, MediaItem.RENDERING_MODE_BLACK_BORDER);
    mediaVideoItem3.setExtractBoundaries(0, 10000);
    mVideoEditor.insertMediaItem(mediaVideoItem3, mediaVideoItem1.getId());
    List<MediaItem> mediaList = mVideoEditor.getAllMediaItems();
    assertEquals("Media Item 1", mediaVideoItem1, mediaList.get(0));
    assertEquals("Media Item 3", mediaVideoItem3, mediaList.get(1));
    assertEquals("Media Item 2", mediaVideoItem2, mediaList.get(2));
    mediaVideoItem1.setRenderingMode(MediaItem.RENDERING_MODE_BLACK_BORDER);
    assertEquals("Media Item 1 Rendering Mode", MediaItem.RENDERING_MODE_BLACK_BORDER, mediaVideoItem1.getRenderingMode());
    mediaVideoItem2.setRenderingMode(MediaItem.RENDERING_MODE_BLACK_BORDER);
    assertEquals("Media Item 2 Rendering Mode", MediaItem.RENDERING_MODE_BLACK_BORDER, mediaVideoItem2.getRenderingMode());
    mediaVideoItem3.setRenderingMode(MediaItem.RENDERING_MODE_STRETCH);
    assertEquals("Media Item 3 Rendering Mode", MediaItem.RENDERING_MODE_STRETCH, mediaVideoItem3.getRenderingMode());
    mVideoEditor.setAspectRatio(MediaProperties.ASPECT_RATIO_5_3);
    assertEquals("Aspect Ratio", MediaProperties.ASPECT_RATIO_5_3, mVideoEditor.getAspectRatio());
    validatePreviewProgress(0, -1, false, mVideoEditor.getDuration());
}
Also used : MediaItem(android.media.videoeditor.MediaItem) MediaVideoItem(android.media.videoeditor.MediaVideoItem) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 25 with MediaItem

use of android.media.videoeditor.MediaItem 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());
}
Also used : MediaVideoItem(android.media.videoeditor.MediaVideoItem) MediaImageItem(android.media.videoeditor.MediaImageItem) TransitionCrossfade(android.media.videoeditor.TransitionCrossfade) MediaItem(android.media.videoeditor.MediaItem) Transition(android.media.videoeditor.Transition) AudioTrack(android.media.videoeditor.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

MediaItem (android.media.videoeditor.MediaItem)35 MediaImageItem (android.media.videoeditor.MediaImageItem)11 File (java.io.File)8 MediaVideoItem (android.media.videoeditor.MediaVideoItem)5 LargeTest (android.test.suitebuilder.annotation.LargeTest)5 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 Bitmap (android.graphics.Bitmap)3 TransitionCrossfade (android.media.videoeditor.TransitionCrossfade)3 Rect (android.graphics.Rect)2 MediaMetadataRetriever (android.media.MediaMetadataRetriever)2 AudioTrack (android.media.videoeditor.AudioTrack)2 MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 XmlPullParser (org.xmlpull.v1.XmlPullParser)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 XmlSerializer (org.xmlpull.v1.XmlSerializer)2