effectSettings_clip2;
341 |
342 | String output = null;
343 |
344 | if (mNativeHelper == null) {
345 | if (m1 != null)
346 | mNativeHelper = m1.getNativeContext();
347 | else if (m2 != null)
348 | mNativeHelper = m2.getNativeContext();
349 | }
350 | transitionSetting = getTransitionSettings();
351 | if (m1 != null && m2 != null) {
352 | /* transition between media items */
353 | clipSettings1 = m1.getClipSettings();
354 | clipSettings2 = m2.getClipSettings();
355 | clipSettings1.beginCutTime = (int)(clipSettings1.endCutTime -
356 | this.mDurationMs);
357 | clipSettings2.endCutTime = (int)(clipSettings2.beginCutTime +
358 | this.mDurationMs);
359 | /*
360 | * Check how many effects and overlays overlap with transition and
361 | * generate effect clip first if there is any overlap
362 | */
363 | effectSettings_clip1 = isEffectandOverlayOverlapping(m1, clipSettings1,1);
364 | effectSettings_clip2 = isEffectandOverlayOverlapping(m2, clipSettings2,2);
365 | for (int index = 0; index < effectSettings_clip2.size(); index++ ) {
366 | effectSettings_clip2.get(index).startTime += this.mDurationMs;
367 | }
368 | editSettings.effectSettingsArray =
369 | new EffectSettings[effectSettings_clip1.size()
370 | + effectSettings_clip2.size()];
371 | int i=0,j=0;
372 | while (i < effectSettings_clip1.size()) {
373 | editSettings.effectSettingsArray[j] = effectSettings_clip1.get(i);
374 | i++;
375 | j++;
376 | }
377 | i=0;
378 | while (i < effectSettings_clip2.size()) {
379 | editSettings.effectSettingsArray[j] = effectSettings_clip2.get(i);
380 | i++;
381 | j++;
382 | }
383 | } else if (m1 == null && m2 != null) {
384 | /* begin transition at first media item */
385 | m2.generateBlankFrame(clipSettings1);
386 | clipSettings2 = m2.getClipSettings();
387 | clipSettings1.endCutTime = (int)(this.mDurationMs + 50);
388 | clipSettings2.endCutTime = (int)(clipSettings2.beginCutTime +
389 | this.mDurationMs);
390 | /*
391 | * Check how many effects and overlays overlap with transition and
392 | * generate effect clip first if there is any overlap
393 | */
394 | effectSettings_clip2 = isEffectandOverlayOverlapping(m2, clipSettings2,2);
395 | for (int index = 0; index < effectSettings_clip2.size(); index++ ) {
396 | effectSettings_clip2.get(index).startTime += this.mDurationMs;
397 | }
398 | editSettings.effectSettingsArray = new EffectSettings[effectSettings_clip2.size()];
399 | int i=0, j=0;
400 | while (i < effectSettings_clip2.size()) {
401 | editSettings.effectSettingsArray[j] = effectSettings_clip2.get(i);
402 | i++;
403 | j++;
404 | }
405 | } else if (m1 != null && m2 == null) {
406 | /* end transition at last media item */
407 | clipSettings1 = m1.getClipSettings();
408 | m1.generateBlankFrame(clipSettings2);
409 | clipSettings1.beginCutTime = (int)(clipSettings1.endCutTime -
410 | this.mDurationMs);
411 | clipSettings2.endCutTime = (int)(this.mDurationMs + 50);
412 | /*
413 | * Check how many effects and overlays overlap with transition and
414 | * generate effect clip first if there is any overlap
415 | */
416 | effectSettings_clip1 = isEffectandOverlayOverlapping(m1, clipSettings1,1);
417 | editSettings.effectSettingsArray = new EffectSettings[effectSettings_clip1.size()];
418 | int i=0,j=0;
419 | while (i < effectSettings_clip1.size()) {
420 | editSettings.effectSettingsArray[j] = effectSettings_clip1.get(i);
421 | i++;
422 | j++;
423 | }
424 | }
425 |
426 | editSettings.clipSettingsArray = new ClipSettings[2];
427 | editSettings.clipSettingsArray[0] = clipSettings1;
428 | editSettings.clipSettingsArray[1] = clipSettings2;
429 | editSettings.backgroundMusicSettings = null;
430 | editSettings.transitionSettingsArray = new TransitionSettings[1];
431 | editSettings.transitionSettingsArray[0] = transitionSetting;
432 | output = mNativeHelper.generateTransitionClip(editSettings, mUniqueId,
433 | m1, m2,this);
434 | setFilename(output);
435 | }
436 |
437 |
438 | /**
439 | * Set the transition filename.
440 | */
441 | void setFilename(String filename) {
442 | mFilename = filename;
443 | }
444 |
445 | /**
446 | * Get the transition filename.
447 | */
448 | String getFilename() {
449 | return mFilename;
450 | }
451 |
452 | /**
453 | * Remove any resources associated with this transition
454 | */
455 | void invalidate() {
456 | if (mFilename != null) {
457 | new File(mFilename).delete();
458 | mFilename = null;
459 | }
460 | }
461 |
462 | /**
463 | * Check if the transition is generated.
464 | *
465 | * @return true if the transition is generated
466 | */
467 | boolean isGenerated() {
468 | return (mFilename != null);
469 | }
470 |
471 | /*
472 | * {@inheritDoc}
473 | */
474 | @Override
475 | public boolean equals(Object object) {
476 | if (!(object instanceof Transition)) {
477 | return false;
478 | }
479 | return mUniqueId.equals(((Transition)object).mUniqueId);
480 | }
481 |
482 | /*
483 | * {@inheritDoc}
484 | */
485 | @Override
486 | public int hashCode() {
487 | return mUniqueId.hashCode();
488 | }
489 | }
490 |
--------------------------------------------------------------------------------
/src/android/media/videoeditor/TransitionAlpha.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package android.media.videoeditor;
18 |
19 | import android.graphics.Bitmap;
20 | import android.graphics.BitmapFactory;
21 | import java.io.DataOutputStream;
22 | import java.io.File;
23 | import java.io.FileOutputStream;
24 | import java.io.IOException;
25 | import java.nio.ByteBuffer;
26 | import java.nio.IntBuffer;
27 |
28 | /**
29 | * This class allows to render an "alpha blending" transition according to a
30 | * bitmap mask. The mask shows the shape of the transition all along the
31 | * duration of the transition: just before the transition, video 1 is fully
32 | * displayed. When the transition starts, as the time goes on, pixels of video 2
33 | * replace pixels of video 1 according to the gray scale pixel value of the
34 | * mask.
35 | * {@hide}
36 | */
37 | public class TransitionAlpha extends Transition {
38 | /** This is the input JPEG file for the mask */
39 | private final String mMaskFilename;
40 |
41 | /**
42 | * This is percentage (between 0 and 100) of blending between video 1 and
43 | * video 2 if this value equals 0, then the mask is strictly applied if this
44 | * value equals 100, then the mask is not at all applied (no transition
45 | * effect)
46 | */
47 | private final int mBlendingPercent;
48 |
49 | /**
50 | * If true, this value inverts the direction of the mask: white pixels of
51 | * the mask show video 2 pixels first black pixels of the mask show video 2
52 | * pixels last.
53 | */
54 | private final boolean mIsInvert;
55 |
56 |
57 | private int mWidth;
58 | private int mHeight;
59 | private String mRGBMaskFile;
60 |
61 | /**
62 | * An object of this type cannot be instantiated by using the default
63 | * constructor
64 | */
65 | @SuppressWarnings("unused")
66 | private TransitionAlpha() {
67 | this(null, null, null, 0, 0, null, 0, false);
68 | }
69 |
70 | /**
71 | * Constructor
72 | *
73 | * @param transitionId The transition id
74 | * @param afterMediaItem The transition is applied to the end of this media
75 | * item
76 | * @param beforeMediaItem The transition is applied to the beginning of this
77 | * media item
78 | * @param durationMs duration of the transition in milliseconds
79 | * @param behavior behavior is one of the behavior defined in Transition
80 | * class
81 | * @param maskFilename JPEG file name. The dimension of the image
82 | * corresponds to 720p (16:9 aspect ratio). Mask files are
83 | * shared between video editors and can be created in the
84 | * projects folder (the parent folder for all projects).
85 | * @param blendingPercent The blending percent applied
86 | * @param invert true to invert the direction of the alpha blending
87 | * @throws IllegalArgumentException if behavior is not supported, or if
88 | * direction are not supported.
89 | */
90 | public TransitionAlpha(String transitionId, MediaItem afterMediaItem,
91 | MediaItem beforeMediaItem, long durationMs, int behavior,
92 | String maskFilename, int blendingPercent, boolean invert) {
93 | super(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior);
94 |
95 | /**
96 | * Generate a RGB file for the supplied mask file
97 | */
98 | final BitmapFactory.Options dbo = new BitmapFactory.Options();
99 | dbo.inJustDecodeBounds = true;
100 | if (!new File(maskFilename).exists())
101 | throw new IllegalArgumentException("File not Found " + maskFilename);
102 | BitmapFactory.decodeFile(maskFilename, dbo);
103 |
104 | mWidth = dbo.outWidth;
105 | mHeight = dbo.outHeight;
106 |
107 | mRGBMaskFile = String.format(mNativeHelper.getProjectPath() +
108 | "/" + "mask" + transitionId+ ".rgb");
109 |
110 |
111 | FileOutputStream fl = null;
112 |
113 | try{
114 | fl = new FileOutputStream(mRGBMaskFile);
115 | } catch (IOException e) {
116 | /* catch IO exception */
117 | }
118 | final DataOutputStream dos = new DataOutputStream(fl);
119 |
120 | if (fl != null) {
121 | /**
122 | * Write to rgb file
123 | */
124 | Bitmap imageBitmap = BitmapFactory.decodeFile(maskFilename);
125 | final int [] framingBuffer = new int[mWidth];
126 | ByteBuffer byteBuffer = ByteBuffer.allocate(framingBuffer.length * 4);
127 | IntBuffer intBuffer;
128 |
129 | byte[] array = byteBuffer.array();
130 | int tmp = 0;
131 | while (tmp < mHeight) {
132 | imageBitmap.getPixels(framingBuffer, 0, mWidth, 0, tmp,mWidth, 1);
133 | intBuffer = byteBuffer.asIntBuffer();
134 | intBuffer.put(framingBuffer,0,mWidth);
135 | try {
136 | dos.write(array);
137 | } catch (IOException e) {
138 | /* catch file write error */
139 | }
140 | tmp += 1;
141 | }
142 |
143 | imageBitmap.recycle();
144 | try{
145 | fl.close();
146 | }catch (IOException e) {
147 | /* file close error */
148 | }
149 | }
150 |
151 | /**
152 | * Capture the details
153 | */
154 | mMaskFilename = maskFilename;
155 | mBlendingPercent = blendingPercent;
156 | mIsInvert = invert;
157 | }
158 |
159 | public int getRGBFileWidth() {
160 | return mWidth;
161 | }
162 |
163 | public int getRGBFileHeight() {
164 | return mHeight;
165 | }
166 |
167 | public String getPNGMaskFilename() {
168 | return mRGBMaskFile;
169 | }
170 |
171 | /**
172 | * Get the blending percentage
173 | *
174 | * @return The blending percentage
175 | */
176 | public int getBlendingPercent() {
177 | return mBlendingPercent;
178 | }
179 |
180 | /**
181 | * Get the filename of the mask.
182 | *
183 | * @return The mask filename
184 | */
185 | public String getMaskFilename() {
186 | return mMaskFilename;
187 | }
188 |
189 | /**
190 | * Check if the alpha blending direction is inverted.
191 | *
192 | * @return true if the direction of the alpha blending is inverted
193 | */
194 | public boolean isInvert() {
195 | return mIsInvert;
196 | }
197 |
198 | /*
199 | * {@inheritDoc}
200 | */
201 | @Override
202 | public void generate() {
203 | super.generate();
204 | }
205 | }
206 |
--------------------------------------------------------------------------------
/src/android/media/videoeditor/TransitionCrossfade.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | package android.media.videoeditor;
19 |
20 |
21 | /**
22 | * This class allows to render a crossfade (dissolve) effect transition between
23 | * two videos
24 | * {@hide}
25 | */
26 | public class TransitionCrossfade extends Transition {
27 | /**
28 | * An object of this type cannot be instantiated by using the default
29 | * constructor
30 | */
31 | @SuppressWarnings("unused")
32 | private TransitionCrossfade() {
33 | this(null, null, null, 0, 0);
34 | }
35 |
36 | /**
37 | * Constructor
38 | *
39 | * @param transitionId The transition id
40 | * @param afterMediaItem The transition is applied to the end of this
41 | * media item
42 | * @param beforeMediaItem The transition is applied to the beginning of
43 | * this media item
44 | * @param durationMs duration of the transition in milliseconds
45 | * @param behavior behavior is one of the behavior defined in Transition
46 | * class
47 | *
48 | * @throws IllegalArgumentException if behavior is not supported.
49 | */
50 | public TransitionCrossfade(String transitionId, MediaItem afterMediaItem,
51 | MediaItem beforeMediaItem, long durationMs, int behavior) {
52 | super(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior);
53 | }
54 |
55 | /*
56 | * {@inheritDoc}
57 | */
58 | @Override
59 | void generate() {
60 | super.generate();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/android/media/videoeditor/TransitionFadeBlack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | package android.media.videoeditor;
19 |
20 |
21 | /**
22 | * This class is used to render a fade to black and fade from black transition
23 | * between two media items.
24 | * {@hide}
25 | */
26 | public class TransitionFadeBlack extends Transition {
27 | /**
28 | * An object of this type cannot be instantiated by using the default
29 | * constructor
30 | */
31 | @SuppressWarnings("unused")
32 | private TransitionFadeBlack() {
33 | this(null, null, null, 0, 0);
34 | }
35 |
36 | /**
37 | * Constructor
38 | *
39 | * @param transitionId The transition id
40 | * @param afterMediaItem The transition is applied to the end of this
41 | * media item
42 | * @param beforeMediaItem The transition is applied to the beginning of
43 | * this media item
44 | * @param durationMs duration of the transition
45 | * @param behavior behavior is one of the behavior defined in Transition
46 | * class
47 | *
48 | * @throws IllegalArgumentException if behavior is not supported.
49 | */
50 | public TransitionFadeBlack(String transitionId, MediaItem afterMediaItem,
51 | MediaItem beforeMediaItem, long durationMs, int behavior) {
52 | super(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior);
53 | }
54 |
55 | /*
56 | * {@inheritDoc}
57 | */
58 | @Override
59 | void generate() {
60 | super.generate();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/android/media/videoeditor/TransitionSliding.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package android.media.videoeditor;
18 |
19 | /**
20 | * This class allows to create sliding transitions
21 | * {@hide}
22 | */
23 | public class TransitionSliding extends Transition {
24 |
25 | /** Video 1 is pushed to the right while video 2 is coming from left */
26 | public final static int DIRECTION_RIGHT_OUT_LEFT_IN = 0;
27 | /** Video 1 is pushed to the left while video 2 is coming from right */
28 | public static final int DIRECTION_LEFT_OUT_RIGHT_IN = 1;
29 | /** Video 1 is pushed to the top while video 2 is coming from bottom */
30 | public static final int DIRECTION_TOP_OUT_BOTTOM_IN = 2;
31 | /** Video 1 is pushed to the bottom while video 2 is coming from top */
32 | public static final int DIRECTION_BOTTOM_OUT_TOP_IN = 3;
33 |
34 | // The sliding transitions
35 | private final int mSlidingDirection;
36 |
37 | /**
38 | * An object of this type cannot be instantiated by using the default
39 | * constructor
40 | */
41 | @SuppressWarnings("unused")
42 | private TransitionSliding() {
43 | this(null, null, null, 0, 0, 0);
44 | }
45 |
46 | /**
47 | * Constructor
48 | *
49 | * @param transitionId The transition id
50 | * @param afterMediaItem The transition is applied to the end of this
51 | * media item
52 | * @param beforeMediaItem The transition is applied to the beginning of
53 | * this media item
54 | * @param durationMs duration of the transition in milliseconds
55 | * @param behavior behavior is one of the behavior defined in Transition
56 | * class
57 | * @param direction direction shall be one of the supported directions like
58 | * RIGHT_OUT_LEFT_IN
59 | *
60 | * @throws IllegalArgumentException if behavior is not supported.
61 | */
62 | public TransitionSliding(String transitionId, MediaItem afterMediaItem,
63 | MediaItem beforeMediaItem, long durationMs, int behavior,
64 | int direction) {
65 | super(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior);
66 | switch (direction) {
67 | case DIRECTION_RIGHT_OUT_LEFT_IN:
68 | case DIRECTION_LEFT_OUT_RIGHT_IN:
69 | case DIRECTION_TOP_OUT_BOTTOM_IN:
70 | case DIRECTION_BOTTOM_OUT_TOP_IN:
71 | break;
72 |
73 | default:
74 | throw new IllegalArgumentException("Invalid direction");
75 | }
76 | mSlidingDirection = direction;
77 | }
78 |
79 | /**
80 | * Get the sliding direction.
81 | *
82 | * @return The sliding direction
83 | */
84 | public int getDirection() {
85 | return mSlidingDirection;
86 | }
87 |
88 | /*
89 | * {@inheritDoc}
90 | */
91 | @Override
92 | void generate() {
93 | super.generate();
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/android/media/videoeditor/VideoEditorFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | package android.media.videoeditor;
19 |
20 | import java.io.File;
21 | import java.io.FileNotFoundException;
22 | import java.io.IOException;
23 |
24 | import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener;
25 |
26 | /**
27 | * The VideoEditorFactory class must be used to instantiate VideoEditor objects
28 | * by creating a new project {@link #create(String)} or by loading an
29 | * existing project {@link #load(String)}.
30 | * {@hide}
31 | */
32 | public class VideoEditorFactory {
33 | /**
34 | * This is the factory method for creating a new VideoEditor instance.
35 | *
36 | * @param projectPath The path where all VideoEditor internal
37 | * files are stored. When a project is deleted the application is
38 | * responsible for deleting the path and its contents.
39 | *
40 | * @return The VideoEditor instance
41 | *
42 | * @throws IOException if path does not exist or if the path can
43 | * not be accessed in read/write mode
44 | */
45 | public static VideoEditor create(String projectPath) throws IOException {
46 | /*
47 | * If the project path does not exist create it
48 | */
49 | final File dir = new File(projectPath);
50 | if (!dir.exists()) {
51 | if (!dir.mkdirs()) {
52 | throw new FileNotFoundException("Cannot create project path: "
53 | + projectPath);
54 | } else {
55 | /*
56 | * Create the file which hides the media files
57 | * from the media scanner
58 | */
59 | if (!new File(dir, ".nomedia").createNewFile()) {
60 | throw new FileNotFoundException("Cannot create file .nomedia");
61 | }
62 | }
63 | }
64 |
65 | return new VideoEditorImpl(projectPath);
66 | }
67 |
68 | /**
69 | * This is the factory method for instantiating a VideoEditor from the
70 | * internal state previously saved with the
71 | * {@link VideoEditor#save(String)} method.
72 | *
73 | * @param projectPath The path where all VideoEditor internal files
74 | * are stored. When a project is deleted the application is
75 | * responsible for deleting the path and its contents.
76 | * @param generatePreview if set to true the
77 | * {@link MediaEditor#generatePreview(MediaProcessingProgressListener
78 | * listener)}
79 | * will be called internally to generate any needed transitions.
80 | *
81 | * @return The VideoEditor instance
82 | *
83 | * @throws IOException if path does not exist or if the path can
84 | * not be accessed in read/write mode or if one of the resource
85 | * media files cannot be retrieved
86 | */
87 | public static VideoEditor load(String projectPath, boolean generatePreview)
88 | throws IOException {
89 | final VideoEditor videoEditor = new VideoEditorImpl(projectPath);
90 | if (generatePreview) {
91 | videoEditor.generatePreview(null);
92 | }
93 | return videoEditor;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/android/media/videoeditor/VideoEditorProfile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package android.media.videoeditor;
17 |
18 | /**
19 | * The VideoEditorProfile class is used to retrieve the
20 | * predefined videoeditor profile settings for videoeditor applications.
21 | * These settings are read-only.
22 | *
23 | * The videoeditor profile specifies the following set of parameters:
24 | *
25 | * - max input video frame width
26 | *
- max input video frame height
27 | *
- max output video frame width
28 | *
- max output video frame height
29 | *
30 | * {@hide}
31 | */
32 | public class VideoEditorProfile
33 | {
34 | static {
35 | System.loadLibrary("media_jni");
36 | native_init();
37 | }
38 | /**
39 | * The max input video frame width
40 | */
41 | public int maxInputVideoFrameWidth;
42 |
43 | /**
44 | * The max input video frame height
45 | */
46 | public int maxInputVideoFrameHeight;
47 |
48 | /**
49 | * The max ouput video frame width
50 | */
51 | public int maxOutputVideoFrameWidth;
52 |
53 | /**
54 | * The max ouput video frame height
55 | */
56 | public int maxOutputVideoFrameHeight;
57 |
58 | /**
59 | * Returns the videoeditor profile
60 | */
61 | public static VideoEditorProfile get() {
62 | return native_get_videoeditor_profile();
63 | }
64 |
65 | /**
66 | * Returns the supported profile by given video codec
67 | */
68 | public static int getExportProfile(int vidCodec) {
69 | int profile = -1;
70 |
71 | switch (vidCodec) {
72 | case MediaProperties.VCODEC_H263:
73 | case MediaProperties.VCODEC_H264:
74 | case MediaProperties.VCODEC_MPEG4:
75 | profile = native_get_videoeditor_export_profile(vidCodec);
76 | break;
77 | default :
78 | throw new IllegalArgumentException("Unsupported video codec" + vidCodec);
79 | }
80 |
81 | return profile;
82 | }
83 |
84 | /**
85 | * Returns the supported level by given video codec
86 | */
87 | public static int getExportLevel(int vidCodec) {
88 | int level = -1;
89 |
90 | switch (vidCodec) {
91 | case MediaProperties.VCODEC_H263:
92 | case MediaProperties.VCODEC_H264:
93 | case MediaProperties.VCODEC_MPEG4:
94 | level = native_get_videoeditor_export_level(vidCodec);
95 | break;
96 | default :
97 | throw new IllegalArgumentException("Unsupported video codec" + vidCodec);
98 | }
99 |
100 | return level;
101 | }
102 |
103 | // Private constructor called by JNI
104 | private VideoEditorProfile(int inputWidth,
105 | int inputHeight,
106 | int outputWidth,
107 | int outputHeight) {
108 |
109 | this.maxInputVideoFrameWidth = inputWidth;
110 | this.maxInputVideoFrameHeight = inputHeight;
111 | this.maxOutputVideoFrameWidth = outputWidth;
112 | this.maxOutputVideoFrameHeight = outputHeight;
113 | }
114 |
115 | // Methods implemented by JNI
116 | private static native final void native_init();
117 | private static native final VideoEditorProfile
118 | native_get_videoeditor_profile();
119 | private static native final int native_get_videoeditor_export_profile(int codec);
120 | private static native final int native_get_videoeditor_export_level(int level);
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/src/android/media/videoeditor/WaveformData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | package android.media.videoeditor;
19 |
20 | import java.io.File;
21 | import java.io.FileInputStream;
22 | import java.io.IOException;
23 |
24 | /**
25 | * Class which describes the waveform data of an audio track. The gain values
26 | * represent the average gain for an audio frame. For audio codecs which do not
27 | * operate on a per frame bases (eg. ALAW, ULAW) a reasonable audio frame
28 | * duration will be assumed (eg. 50ms).
29 | * {@hide}
30 | */
31 | public class WaveformData {
32 | /*
33 | * Instance variables
34 | */
35 | private final int mFrameDurationMs;
36 | private final int mFramesCount;
37 | private final short[] mGains;
38 |
39 | /*
40 | * This constructor shall not be used
41 | */
42 | @SuppressWarnings("unused")
43 | private WaveformData() throws IOException {
44 | mFrameDurationMs = 0;
45 | mFramesCount = 0;
46 | mGains = null;
47 | }
48 |
49 | /*
50 | * Constructor
51 | *
52 | * @param audioWaveformFilename The name of the audio waveform file
53 | *
54 | * The file format is as following:
55 | *
56 | * - first 4 bytes provide the number of samples for each value, as
57 | * big-endian signed
58 | * - 4 following bytes is the total number of values in the file, as
59 | * big-endian signed
60 | * - then, all values follow as bytes
61 | *
62 | *
63 | * @throws IOException on failure of file input stream operations
64 | * @throws IllegalArgumentException if audioWaveformFilename is null
65 | */
66 | WaveformData(String audioWaveformFilename) throws IOException {
67 |
68 | if (audioWaveformFilename == null) {
69 | throw new IllegalArgumentException("WaveformData : filename is null");
70 | }
71 |
72 | FileInputStream audioGraphFileReadHandle = null;
73 |
74 | try {
75 | final File audioGraphFileContext = new File(audioWaveformFilename);
76 |
77 | audioGraphFileReadHandle = new FileInputStream(audioGraphFileContext);
78 | /*
79 | * Read frame duration
80 | */
81 | final byte tempFrameDuration[] = new byte[4];
82 |
83 | audioGraphFileReadHandle.read(tempFrameDuration, 0, 4);
84 |
85 | int tempFrameDurationMs = 0;
86 | int tempFramesCounter = 0;
87 | for (int i = 0; i < 4; i++) {
88 | tempFrameDurationMs = (tempFrameDurationMs << 8);
89 | tempFrameDurationMs = (tempFrameDurationMs | (tempFrameDuration[i] & 0xff));
90 | }
91 | mFrameDurationMs = tempFrameDurationMs;
92 |
93 | /*
94 | * Read count
95 | */
96 | final byte tempFramesCount[] = new byte[4];
97 |
98 | audioGraphFileReadHandle.read(tempFramesCount, 0, 4);
99 | for (int i = 0; i < 4; i++) {
100 | tempFramesCounter = (tempFramesCounter << 8);
101 | tempFramesCounter = (tempFramesCounter | (tempFramesCount[i] & 0xff));
102 | }
103 | mFramesCount = tempFramesCounter;
104 |
105 | /*
106 | * Capture the graph values
107 | */
108 | mGains = new short[mFramesCount];
109 |
110 | for (int i = 0; i < mFramesCount; i++) {
111 | mGains[i] = (short)audioGraphFileReadHandle.read();
112 | }
113 | } finally {
114 | if (audioGraphFileReadHandle != null) {
115 | audioGraphFileReadHandle.close();
116 | }
117 | }
118 | }
119 |
120 | /**
121 | * @return The duration of a frame in milliseconds
122 | */
123 | public int getFrameDuration() {
124 | return mFrameDurationMs;
125 | }
126 |
127 | /**
128 | * @return The number of frames within the waveform data
129 | */
130 | public int getFramesCount() {
131 | return mFramesCount;
132 | }
133 |
134 | /**
135 | * @return The array of frame gains. The size of the array is the frames
136 | * count. The values of the frame gains range from 0 to 255.
137 | */
138 | public short[] getFrameGains() {
139 | return mGains;
140 | }
141 | }
142 |
--------------------------------------------------------------------------------