Toggle video effects in the composition demo.
Add an option to enable or disable video effects in preview or export. PiperOrigin-RevId: 662488658
This commit is contained in:
parent
9d008da356
commit
2d527b08c3
@ -79,6 +79,7 @@ public final class CompositionPreviewActivity extends AppCompatActivity {
|
||||
private AppCompatTextView exportInformationTextView;
|
||||
private Stopwatch exportStopwatch;
|
||||
private boolean includeBackgroundAudioTrack;
|
||||
private boolean appliesVideoEffects;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -102,6 +103,10 @@ public final class CompositionPreviewActivity extends AppCompatActivity {
|
||||
backgroundAudioCheckBox.setOnCheckedChangeListener(
|
||||
(compoundButton, checked) -> includeBackgroundAudioTrack = checked);
|
||||
|
||||
AppCompatCheckBox applyVideoEffectsCheckBox = findViewById(R.id.apply_video_effects_checkbox);
|
||||
applyVideoEffectsCheckBox.setOnCheckedChangeListener(
|
||||
((compoundButton, checked) -> appliesVideoEffects = checked));
|
||||
|
||||
presetDescriptions = getResources().getStringArray(R.array.preset_descriptions);
|
||||
// Select two media items by default.
|
||||
selectedMediaItems = new boolean[presetDescriptions.length];
|
||||
@ -145,9 +150,12 @@ public final class CompositionPreviewActivity extends AppCompatActivity {
|
||||
String[] presetUris = getResources().getStringArray(/* id= */ R.array.preset_uris);
|
||||
int[] presetDurationsUs = getResources().getIntArray(/* id= */ R.array.preset_durations);
|
||||
List<EditedMediaItem> mediaItems = new ArrayList<>();
|
||||
ImmutableList<Effect> effects =
|
||||
ImmutableList.of(
|
||||
MatrixTransformationFactory.createDizzyCropEffect(), RgbFilter.createGrayscaleFilter());
|
||||
ImmutableList<Effect> videoEffects =
|
||||
appliesVideoEffects
|
||||
? ImmutableList.of(
|
||||
MatrixTransformationFactory.createDizzyCropEffect(),
|
||||
RgbFilter.createGrayscaleFilter())
|
||||
: ImmutableList.of();
|
||||
// Preview requires all sequences to be the same duration, so calculate main sequence duration
|
||||
// and limit background sequence duration to match.
|
||||
long videoSequenceDurationUs = 0;
|
||||
@ -165,7 +173,7 @@ public final class CompositionPreviewActivity extends AppCompatActivity {
|
||||
.setEffects(
|
||||
new Effects(
|
||||
/* audioProcessors= */ ImmutableList.of(pitchChanger),
|
||||
/* videoEffects= */ effects))
|
||||
/* videoEffects= */ videoEffects))
|
||||
.setDurationUs(presetDurationsUs[i]);
|
||||
videoSequenceDurationUs += presetDurationsUs[i];
|
||||
mediaItems.add(itemBuilder.build());
|
||||
|
@ -43,7 +43,7 @@
|
||||
android:layout_marginBottom="8dp"
|
||||
android:padding="8dp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:text="@string/preview_single_sequence" />
|
||||
android:text="@string/preview_composition" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -64,7 +64,7 @@
|
||||
android:id="@+id/sequence_header_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/single_sequence_items"
|
||||
android:text="@string/video_sequence_items"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/composition_preview_card_view"
|
||||
app:layout_constraintBottom_toTopOf="@id/composition_preset_list"/>
|
||||
@ -75,8 +75,18 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:text="@string/edit"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/composition_preview_card_view"/>
|
||||
app:layout_constraintStart_toEndOf="@id/sequence_header_text"
|
||||
app:layout_constraintTop_toTopOf="@id/sequence_header_text"
|
||||
app:layout_constraintBottom_toBottomOf="@id/sequence_header_text"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatCheckBox
|
||||
android:id="@+id/apply_video_effects_checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/add_effects"
|
||||
app:layout_constraintStart_toEndOf="@id/edit_sequence_button"
|
||||
app:layout_constraintTop_toTopOf="@id/sequence_header_text"
|
||||
app:layout_constraintBottom_toBottomOf="@id/sequence_header_text" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/composition_preset_list"
|
||||
|
@ -16,9 +16,10 @@
|
||||
<resources>
|
||||
<string name="app_name">Composition Demo</string>
|
||||
<string name="edit">Edit</string>
|
||||
<string name="add_effects">Add effects</string>
|
||||
<string name="preview" translatable="false">Preview</string>
|
||||
<string name="preview_single_sequence" translatable="false">Single sequence preview</string>
|
||||
<string name="single_sequence_items" translatable="false">Single sequence items:</string>
|
||||
<string name="preview_composition" translatable="false">Composition preview</string>
|
||||
<string name="video_sequence_items" translatable="false">Video sequence items:</string>
|
||||
<string name="select_preset_title" translatable="false">Choose preset input</string>
|
||||
<string name="export" translatable="false">Export</string>
|
||||
<string name="export_completed" translatable="false">Export completed in %.3f seconds.\nOutput: %s</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user