Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7eb80570 authored by Gil Dobjanschi's avatar Gil Dobjanschi Committed by Android (Google) Code Review
Browse files

Merge "1. Added OverlayFrame constuctor 2. Invalidate transitions when...

Merge "1. Added OverlayFrame constuctor 2. Invalidate transitions when trimming video 3. Remove image file when removing an OverlayFrame 4. Bug fixes in the VideoEditor implementation"
parents 39b41d92 21e9da6f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ public abstract class Effect {
     * Set start time of the effect. If a preview or export is in progress, then
     * this change is effective for next preview or export session.
     *
     * @param startTimeMs The start time of the effect relative to the begining
     * @param startTimeMs The start time of the effect relative to the beginning
     *            of the media item in milliseconds
     */
    public void setStartTime(long startTimeMs) {
+32 −3
Original line number Diff line number Diff line
@@ -64,8 +64,8 @@ public abstract class MediaItem {
    private int mRenderingMode;

    // Beginning and end transitions
    private Transition mBeginTransition;
    private Transition mEndTransition;
    protected Transition mBeginTransition;
    protected Transition mEndTransition;

    /**
     * Constructor
@@ -113,6 +113,13 @@ public abstract class MediaItem {
     */
    public void setRenderingMode(int renderingMode) {
        mRenderingMode = renderingMode;
        if (mBeginTransition != null) {
            mBeginTransition.invalidate();
        }

        if (mEndTransition != null) {
            mEndTransition.invalidate();
        }
    }

    /**
@@ -271,7 +278,9 @@ public abstract class MediaItem {
     *
     * @param overlay The overlay to add
     * @throws IllegalStateException if a preview or an export is in progress or
     *             if the overlay id is not unique across all the overlays added.
     *             if the overlay id is not unique across all the overlays
     *             added or if the bitmap is not specified or if the dimensions of
     *             the bitmap do not match the dimensions of the media item
     */
    public void addOverlay(Overlay overlay) {
        if (mOverlays.contains(overlay)) {
@@ -283,6 +292,23 @@ public abstract class MediaItem {
                    "Overlay start time + overlay duration > media clip duration");
        }

        if (overlay instanceof OverlayFrame) {
            final OverlayFrame frame = (OverlayFrame)overlay;
            final Bitmap bitmap = frame.getBitmap();
            if (bitmap == null) {
                throw new IllegalArgumentException("Overlay bitmap not specified");
            }

            // The dimensions of the overlay bitmap must be the same as the
            // media item dimensions
            if (bitmap.getWidth() != getWidth() || bitmap.getHeight() != getHeight()) {
                throw new IllegalArgumentException(
                        "Bitmap dimensions must match media item dimensions");
            }
        } else {
            throw new IllegalArgumentException("Overlay not supported");
        }

        mOverlays.add(overlay);
        invalidateTransitions(overlay);
    }
@@ -302,6 +328,9 @@ public abstract class MediaItem {
        for (Overlay overlay : mOverlays) {
            if (overlay.getId().equals(overlayId)) {
                mOverlays.remove(overlay);
                if (overlay instanceof OverlayFrame) {
                    ((OverlayFrame)overlay).invalidate();
                }
                invalidateTransitions(overlay);
                return overlay;
            }
+13 −2
Original line number Diff line number Diff line
@@ -264,8 +264,19 @@ public class MediaVideoItem extends MediaItem {
            throw new IllegalArgumentException("Invalid end time");
        }

        if (beginMs != mBeginBoundaryTimeMs) {
            mBeginBoundaryTimeMs = beginMs;
            if (mBeginTransition != null) {
                mBeginTransition.invalidate();
            }
        }

        if (endMs == mEndBoundaryTimeMs) {
            mEndBoundaryTimeMs = endMs;
            if (mEndTransition != null) {
                mEndTransition.invalidate();
            }
        }
        // TODO: Validate/modify the start and the end time of effects and overlays
    }

+77 −9
Original line number Diff line number Diff line
@@ -16,16 +16,24 @@

package android.media.videoeditor;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap.CompressFormat;


/**
 * This class is used to overlay an image on top of a media item. This class
 * does not manage deletion of the overlay file so application may use
 * {@link #getFilename()} for this purpose.
 * This class is used to overlay an image on top of a media item.
 * {@hide}
 */
public class OverlayFrame extends Overlay {
    // Instance variables
    private final String mFilename;
    private final Bitmap mBitmap;
    private String mFilename;

    /**
     * An object of this type cannot be instantiated by using the default
@@ -33,30 +41,90 @@ public class OverlayFrame extends Overlay {
     */
    @SuppressWarnings("unused")
    private OverlayFrame() {
        this(null, null, 0, 0);
        this(null, (String)null, 0, 0);
    }

    /**
     * Constructor for an OverlayFrame
     *
     * @param overlayId The overlay id
     * @param filename The file name that contains the overlay. Only PNG
     *            supported.
     * @param bitmap The bitmap to be used as an overlay. The size of the
     *      bitmap must equal to the size of the media item to which it is
     *      added. The bitmap is typically a decoded PNG file.
     * @param startTimeMs The overlay start time in milliseconds
     * @param durationMs The overlay duration in milliseconds
     *
     * @throws IllegalArgumentException if the file type is not PNG or the
     *      startTimeMs and durationMs are incorrect.
     */
    public OverlayFrame(String overlayId, String filename, long startTimeMs, long durationMs) {
    public OverlayFrame(String overlayId, Bitmap bitmap, long startTimeMs,
            long durationMs) {
        super(overlayId, startTimeMs, durationMs);
        mBitmap = bitmap;
        mFilename = null;
    }

    /**
     * Constructor for an OverlayFrame. This constructor can be used to
     * restore the overlay after it was saved internally by the video editor.
     *
     * @param overlayId The overlay id
     * @param filename The file name that contains the overlay.
     * @param startTimeMs The overlay start time in milliseconds
     * @param durationMs The overlay duration in milliseconds
     *
     * @throws IllegalArgumentException if the file type is not PNG or the
     *      startTimeMs and durationMs are incorrect.
     */
    OverlayFrame(String overlayId, String filename, long startTimeMs, long durationMs) {
        super(overlayId, startTimeMs, durationMs);
        mFilename = filename;
        mBitmap = BitmapFactory.decodeFile(mFilename);
    }

    /**
     * @return Get the overlay bitmap
     */
    public Bitmap getBitmap() {
        return mBitmap;
    }

    /**
     * Get the file name of this overlay
     */
    public String getFilename() {
    String getFilename() {
        return mFilename;
    }

    /**
     * Save the overlay to the project folder
     *
     * @param editor The video editor
     *
     * @return
     * @throws FileNotFoundException if the bitmap cannot be saved
     * @throws IOException if the bitmap file cannot be saved
     */
    String save(VideoEditor editor) throws FileNotFoundException, IOException {
        if (mFilename != null) {
            return mFilename;
        }

        mFilename = editor.getPath() + "/" + getId() + ".png";
        // Save the image to a local file
        final FileOutputStream out = new FileOutputStream(mFilename);
        mBitmap.compress(CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
        return mFilename;
    }

    /**
     * Delete the overlay file
     */
    void invalidate() {
        if (mFilename != null) {
            new File(mFilename).delete();
        }
    }
}
+8 −6
Original line number Diff line number Diff line
@@ -58,17 +58,19 @@ public class TransitionAlpha extends Transition {
     * Constructor
     *
     * @param transitionId The transition id
     * @param afterMediaItem The transition is applied to the end of this
     * @param afterMediaItem The transition is applied to the end of this media
     *            item
     * @param beforeMediaItem The transition is applied to the beginning of this
     *            media item
     * @param beforeMediaItem The transition is applied to the beginning of
     *      this media item
     * @param durationMs duration of the transition in milliseconds
     * @param behavior behavior is one of the behavior defined in Transition
     *            class
     * @param maskFilename JPEG file name
     * @param maskFilename JPEG file name. The dimension of the image
     *           corresponds to 720p (16:9 aspect ratio). Mask files are
     *           shared between video editors and can be created in the
     *           projects folder (the parent folder for all projects).
     * @param blendingPercent The blending percent applied
     * @param invert true to invert the direction of the alpha blending
     *
     * @throws IllegalArgumentException if behavior is not supported, or if
     *             direction are not supported.
     */
Loading