Add setter for some audio effects to demo app.
PiperOrigin-RevId: 493001630
This commit is contained in:
parent
991010f24c
commit
ead7070b60
@ -72,7 +72,8 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
public static final String ENABLE_DEBUG_PREVIEW = "enable_debug_preview";
|
public static final String ENABLE_DEBUG_PREVIEW = "enable_debug_preview";
|
||||||
public static final String ABORT_SLOW_TRANSFORMATION = "abort_slow_transformation";
|
public static final String ABORT_SLOW_TRANSFORMATION = "abort_slow_transformation";
|
||||||
public static final String HDR_MODE = "hdr_mode";
|
public static final String HDR_MODE = "hdr_mode";
|
||||||
public static final String DEMO_EFFECTS_SELECTIONS = "demo_effects_selections";
|
public static final String AUDIO_EFFECTS_SELECTIONS = "audio_effects_selections";
|
||||||
|
public static final String VIDEO_EFFECTS_SELECTIONS = "video_effects_selections";
|
||||||
public static final String PERIODIC_VIGNETTE_CENTER_X = "periodic_vignette_center_x";
|
public static final String PERIODIC_VIGNETTE_CENTER_X = "periodic_vignette_center_x";
|
||||||
public static final String PERIODIC_VIGNETTE_CENTER_Y = "periodic_vignette_center_y";
|
public static final String PERIODIC_VIGNETTE_CENTER_Y = "periodic_vignette_center_y";
|
||||||
public static final String PERIODIC_VIGNETTE_INNER_RADIUS = "periodic_vignette_inner_radius";
|
public static final String PERIODIC_VIGNETTE_INNER_RADIUS = "periodic_vignette_inner_radius";
|
||||||
@ -123,7 +124,10 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
"HDR (HLG) H265 limited range video (encoding may fail)",
|
"HDR (HLG) H265 limited range video (encoding may fail)",
|
||||||
"720p H264 video with no audio",
|
"720p H264 video with no audio",
|
||||||
};
|
};
|
||||||
private static final String[] DEMO_EFFECTS = {
|
private static final String[] AUDIO_EFFECTS = {
|
||||||
|
"High pitched", "Sample rate of 48000Hz", "Skip silence"
|
||||||
|
};
|
||||||
|
private static final String[] VIDEO_EFFECTS = {
|
||||||
"Dizzy crop",
|
"Dizzy crop",
|
||||||
"Edge detector (Media Pipe)",
|
"Edge detector (Media Pipe)",
|
||||||
"Color filters",
|
"Color filters",
|
||||||
@ -171,8 +175,10 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
private @MonotonicNonNull CheckBox enableDebugPreviewCheckBox;
|
private @MonotonicNonNull CheckBox enableDebugPreviewCheckBox;
|
||||||
private @MonotonicNonNull CheckBox abortSlowTransformationCheckBox;
|
private @MonotonicNonNull CheckBox abortSlowTransformationCheckBox;
|
||||||
private @MonotonicNonNull Spinner hdrModeSpinner;
|
private @MonotonicNonNull Spinner hdrModeSpinner;
|
||||||
private @MonotonicNonNull Button selectDemoEffectsButton;
|
private @MonotonicNonNull Button selectAudioEffectsButton;
|
||||||
private boolean @MonotonicNonNull [] demoEffectsSelections;
|
private @MonotonicNonNull Button selectVideoEffectsButton;
|
||||||
|
private boolean @MonotonicNonNull [] audioEffectsSelections;
|
||||||
|
private boolean @MonotonicNonNull [] videoEffectsSelections;
|
||||||
private @Nullable Uri localFileUri;
|
private @Nullable Uri localFileUri;
|
||||||
private int inputUriPosition;
|
private int inputUriPosition;
|
||||||
private long trimStartMs;
|
private long trimStartMs;
|
||||||
@ -274,9 +280,13 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
hdrModeSpinner.setAdapter(hdrModeAdapter);
|
hdrModeSpinner.setAdapter(hdrModeAdapter);
|
||||||
hdrModeAdapter.addAll(HDR_MODE_DESCRIPTIONS.keySet());
|
hdrModeAdapter.addAll(HDR_MODE_DESCRIPTIONS.keySet());
|
||||||
|
|
||||||
demoEffectsSelections = new boolean[DEMO_EFFECTS.length];
|
audioEffectsSelections = new boolean[AUDIO_EFFECTS.length];
|
||||||
selectDemoEffectsButton = findViewById(R.id.select_demo_effects_button);
|
selectAudioEffectsButton = findViewById(R.id.select_audio_effects_button);
|
||||||
selectDemoEffectsButton.setOnClickListener(this::selectDemoEffects);
|
selectAudioEffectsButton.setOnClickListener(this::selectAudioEffects);
|
||||||
|
|
||||||
|
videoEffectsSelections = new boolean[VIDEO_EFFECTS.length];
|
||||||
|
selectVideoEffectsButton = findViewById(R.id.select_video_effects_button);
|
||||||
|
selectVideoEffectsButton.setOnClickListener(this::selectVideoEffects);
|
||||||
|
|
||||||
localFilePickerLauncher =
|
localFilePickerLauncher =
|
||||||
registerForActivityResult(
|
registerForActivityResult(
|
||||||
@ -332,7 +342,8 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
"enableDebugPreviewCheckBox",
|
"enableDebugPreviewCheckBox",
|
||||||
"abortSlowTransformationCheckBox",
|
"abortSlowTransformationCheckBox",
|
||||||
"hdrModeSpinner",
|
"hdrModeSpinner",
|
||||||
"demoEffectsSelections"
|
"audioEffectsSelections",
|
||||||
|
"videoEffectsSelections"
|
||||||
})
|
})
|
||||||
private void startTransformation(View view) {
|
private void startTransformation(View view) {
|
||||||
Intent transformerIntent = new Intent(/* packageContext= */ this, TransformerActivity.class);
|
Intent transformerIntent = new Intent(/* packageContext= */ this, TransformerActivity.class);
|
||||||
@ -373,7 +384,8 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
bundle.putBoolean(ABORT_SLOW_TRANSFORMATION, abortSlowTransformationCheckBox.isChecked());
|
bundle.putBoolean(ABORT_SLOW_TRANSFORMATION, abortSlowTransformationCheckBox.isChecked());
|
||||||
String selectedhdrMode = String.valueOf(hdrModeSpinner.getSelectedItem());
|
String selectedhdrMode = String.valueOf(hdrModeSpinner.getSelectedItem());
|
||||||
bundle.putInt(HDR_MODE, checkNotNull(HDR_MODE_DESCRIPTIONS.get(selectedhdrMode)));
|
bundle.putInt(HDR_MODE, checkNotNull(HDR_MODE_DESCRIPTIONS.get(selectedhdrMode)));
|
||||||
bundle.putBooleanArray(DEMO_EFFECTS_SELECTIONS, demoEffectsSelections);
|
bundle.putBooleanArray(AUDIO_EFFECTS_SELECTIONS, audioEffectsSelections);
|
||||||
|
bundle.putBooleanArray(VIDEO_EFFECTS_SELECTIONS, videoEffectsSelections);
|
||||||
bundle.putInt(COLOR_FILTER_SELECTION, colorFilterSelection);
|
bundle.putInt(COLOR_FILTER_SELECTION, colorFilterSelection);
|
||||||
bundle.putFloat(CONTRAST_VALUE, contrastValue);
|
bundle.putFloat(CONTRAST_VALUE, contrastValue);
|
||||||
bundle.putFloat(RGB_ADJUSTMENT_RED_SCALE, rgbAdjustmentRedScale);
|
bundle.putFloat(RGB_ADJUSTMENT_RED_SCALE, rgbAdjustmentRedScale);
|
||||||
@ -446,11 +458,21 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectDemoEffects(View view) {
|
private void selectAudioEffects(View view) {
|
||||||
new AlertDialog.Builder(/* context= */ this)
|
new AlertDialog.Builder(/* context= */ this)
|
||||||
.setTitle(R.string.select_demo_effects)
|
.setTitle(R.string.select_audio_effects)
|
||||||
.setMultiChoiceItems(
|
.setMultiChoiceItems(
|
||||||
DEMO_EFFECTS, checkNotNull(demoEffectsSelections), this::selectDemoEffect)
|
AUDIO_EFFECTS, checkNotNull(audioEffectsSelections), this::selectAudioEffect)
|
||||||
|
.setPositiveButton(android.R.string.ok, /* listener= */ null)
|
||||||
|
.create()
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectVideoEffects(View view) {
|
||||||
|
new AlertDialog.Builder(/* context= */ this)
|
||||||
|
.setTitle(R.string.select_video_effects)
|
||||||
|
.setMultiChoiceItems(
|
||||||
|
VIDEO_EFFECTS, checkNotNull(videoEffectsSelections), this::selectVideoEffect)
|
||||||
.setPositiveButton(android.R.string.ok, /* listener= */ null)
|
.setPositiveButton(android.R.string.ok, /* listener= */ null)
|
||||||
.create()
|
.create()
|
||||||
.show();
|
.show();
|
||||||
@ -477,9 +499,14 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresNonNull("demoEffectsSelections")
|
@RequiresNonNull("audioEffectsSelections")
|
||||||
private void selectDemoEffect(DialogInterface dialog, int which, boolean isChecked) {
|
private void selectAudioEffect(DialogInterface dialog, int which, boolean isChecked) {
|
||||||
demoEffectsSelections[which] = isChecked;
|
audioEffectsSelections[which] = isChecked;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresNonNull("videoEffectsSelections")
|
||||||
|
private void selectVideoEffect(DialogInterface dialog, int which, boolean isChecked) {
|
||||||
|
videoEffectsSelections[which] = isChecked;
|
||||||
if (!isChecked) {
|
if (!isChecked) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -612,7 +639,8 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
"rotateSpinner",
|
"rotateSpinner",
|
||||||
"enableDebugPreviewCheckBox",
|
"enableDebugPreviewCheckBox",
|
||||||
"hdrModeSpinner",
|
"hdrModeSpinner",
|
||||||
"selectDemoEffectsButton"
|
"selectAudioEffectsButton",
|
||||||
|
"selectVideoEffectsButton"
|
||||||
})
|
})
|
||||||
private void onRemoveAudio(View view) {
|
private void onRemoveAudio(View view) {
|
||||||
if (((CheckBox) view).isChecked()) {
|
if (((CheckBox) view).isChecked()) {
|
||||||
@ -633,7 +661,8 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
"rotateSpinner",
|
"rotateSpinner",
|
||||||
"enableDebugPreviewCheckBox",
|
"enableDebugPreviewCheckBox",
|
||||||
"hdrModeSpinner",
|
"hdrModeSpinner",
|
||||||
"selectDemoEffectsButton"
|
"selectAudioEffectsButton",
|
||||||
|
"selectVideoEffectsButton"
|
||||||
})
|
})
|
||||||
private void onRemoveVideo(View view) {
|
private void onRemoveVideo(View view) {
|
||||||
if (((CheckBox) view).isChecked()) {
|
if (((CheckBox) view).isChecked()) {
|
||||||
@ -653,7 +682,8 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
"rotateSpinner",
|
"rotateSpinner",
|
||||||
"enableDebugPreviewCheckBox",
|
"enableDebugPreviewCheckBox",
|
||||||
"hdrModeSpinner",
|
"hdrModeSpinner",
|
||||||
"selectDemoEffectsButton"
|
"selectAudioEffectsButton",
|
||||||
|
"selectVideoEffectsButton"
|
||||||
})
|
})
|
||||||
private void enableTrackSpecificOptions(boolean isAudioEnabled, boolean isVideoEnabled) {
|
private void enableTrackSpecificOptions(boolean isAudioEnabled, boolean isVideoEnabled) {
|
||||||
forceSilentAudioCheckbox.setEnabled(isVideoEnabled);
|
forceSilentAudioCheckbox.setEnabled(isVideoEnabled);
|
||||||
@ -664,7 +694,8 @@ public final class ConfigurationActivity extends AppCompatActivity {
|
|||||||
rotateSpinner.setEnabled(isVideoEnabled);
|
rotateSpinner.setEnabled(isVideoEnabled);
|
||||||
enableDebugPreviewCheckBox.setEnabled(isVideoEnabled);
|
enableDebugPreviewCheckBox.setEnabled(isVideoEnabled);
|
||||||
hdrModeSpinner.setEnabled(isVideoEnabled);
|
hdrModeSpinner.setEnabled(isVideoEnabled);
|
||||||
selectDemoEffectsButton.setEnabled(isVideoEnabled);
|
selectAudioEffectsButton.setEnabled(isAudioEnabled);
|
||||||
|
selectVideoEffectsButton.setEnabled(isVideoEnabled);
|
||||||
|
|
||||||
findViewById(R.id.audio_mime_text_view).setEnabled(isAudioEnabled);
|
findViewById(R.id.audio_mime_text_view).setEnabled(isAudioEnabled);
|
||||||
findViewById(R.id.video_mime_text_view).setEnabled(isVideoEnabled);
|
findViewById(R.id.video_mime_text_view).setEnabled(isVideoEnabled);
|
||||||
|
@ -41,6 +41,7 @@ import androidx.media3.common.C;
|
|||||||
import androidx.media3.common.DebugViewProvider;
|
import androidx.media3.common.DebugViewProvider;
|
||||||
import androidx.media3.common.Effect;
|
import androidx.media3.common.Effect;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
|
import androidx.media3.common.audio.AudioProcessor;
|
||||||
import androidx.media3.common.util.Log;
|
import androidx.media3.common.util.Log;
|
||||||
import androidx.media3.common.util.Util;
|
import androidx.media3.common.util.Util;
|
||||||
import androidx.media3.effect.Contrast;
|
import androidx.media3.effect.Contrast;
|
||||||
@ -52,6 +53,8 @@ import androidx.media3.effect.RgbFilter;
|
|||||||
import androidx.media3.effect.RgbMatrix;
|
import androidx.media3.effect.RgbMatrix;
|
||||||
import androidx.media3.effect.SingleColorLut;
|
import androidx.media3.effect.SingleColorLut;
|
||||||
import androidx.media3.exoplayer.ExoPlayer;
|
import androidx.media3.exoplayer.ExoPlayer;
|
||||||
|
import androidx.media3.exoplayer.audio.SilenceSkippingAudioProcessor;
|
||||||
|
import androidx.media3.exoplayer.audio.SonicAudioProcessor;
|
||||||
import androidx.media3.exoplayer.util.DebugTextViewHelper;
|
import androidx.media3.exoplayer.util.DebugTextViewHelper;
|
||||||
import androidx.media3.transformer.DefaultEncoderFactory;
|
import androidx.media3.transformer.DefaultEncoderFactory;
|
||||||
import androidx.media3.transformer.DefaultMuxer;
|
import androidx.media3.transformer.DefaultMuxer;
|
||||||
@ -283,7 +286,8 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
.setEnableFallback(bundle.getBoolean(ConfigurationActivity.ENABLE_FALLBACK))
|
.setEnableFallback(bundle.getBoolean(ConfigurationActivity.ENABLE_FALLBACK))
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
transformerBuilder.setVideoEffects(createVideoEffectsListFromBundle(bundle));
|
transformerBuilder.setAudioProcessors(createAudioProcessorsFromBundle(bundle));
|
||||||
|
transformerBuilder.setVideoEffects(createVideoEffectsFromBundle(bundle));
|
||||||
|
|
||||||
if (bundle.getBoolean(ConfigurationActivity.ENABLE_DEBUG_PREVIEW)) {
|
if (bundle.getBoolean(ConfigurationActivity.ENABLE_DEBUG_PREVIEW)) {
|
||||||
transformerBuilder.setDebugViewProvider(new DemoDebugViewProvider());
|
transformerBuilder.setDebugViewProvider(new DemoDebugViewProvider());
|
||||||
@ -325,10 +329,45 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImmutableList<Effect> createVideoEffectsListFromBundle(Bundle bundle) {
|
private ImmutableList<AudioProcessor> createAudioProcessorsFromBundle(Bundle bundle) {
|
||||||
|
@Nullable
|
||||||
|
boolean[] selectedAudioEffects =
|
||||||
|
bundle.getBooleanArray(ConfigurationActivity.AUDIO_EFFECTS_SELECTIONS);
|
||||||
|
|
||||||
|
if (selectedAudioEffects == null) {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImmutableList.Builder<AudioProcessor> processors = new ImmutableList.Builder<>();
|
||||||
|
|
||||||
|
if (selectedAudioEffects[0] || selectedAudioEffects[1]) {
|
||||||
|
SonicAudioProcessor sonicAudioProcessor = new SonicAudioProcessor();
|
||||||
|
// High pitched
|
||||||
|
if (selectedAudioEffects[0]) {
|
||||||
|
sonicAudioProcessor.setPitch(2f);
|
||||||
|
}
|
||||||
|
// 48KHz sample rate.
|
||||||
|
if (selectedAudioEffects[1]) {
|
||||||
|
sonicAudioProcessor.setOutputSampleRateHz(48_000);
|
||||||
|
}
|
||||||
|
processors.add(sonicAudioProcessor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip silence
|
||||||
|
if (selectedAudioEffects[2]) {
|
||||||
|
SilenceSkippingAudioProcessor silenceSkippingAudioProcessor =
|
||||||
|
new SilenceSkippingAudioProcessor();
|
||||||
|
silenceSkippingAudioProcessor.setEnabled(true);
|
||||||
|
processors.add(silenceSkippingAudioProcessor);
|
||||||
|
}
|
||||||
|
|
||||||
|
return processors.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImmutableList<Effect> createVideoEffectsFromBundle(Bundle bundle) {
|
||||||
@Nullable
|
@Nullable
|
||||||
boolean[] selectedEffects =
|
boolean[] selectedEffects =
|
||||||
bundle.getBooleanArray(ConfigurationActivity.DEMO_EFFECTS_SELECTIONS);
|
bundle.getBooleanArray(ConfigurationActivity.VIDEO_EFFECTS_SELECTIONS);
|
||||||
if (selectedEffects == null) {
|
if (selectedEffects == null) {
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@
|
|||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/selected_file_text_view"
|
app:layout_constraintTop_toBottomOf="@+id/selected_file_text_view"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/select_demo_effects_button">
|
app:layout_constraintBottom_toTopOf="@+id/select_audio_effects_button">
|
||||||
<TableLayout
|
<TableLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -229,13 +229,24 @@
|
|||||||
</TableLayout>
|
</TableLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/select_demo_effects_button"
|
android:id="@+id/select_audio_effects_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="32dp"
|
android:layout_marginTop="32dp"
|
||||||
android:layout_marginStart="32dp"
|
android:layout_marginStart="32dp"
|
||||||
android:layout_marginEnd="32dp"
|
android:layout_marginEnd="32dp"
|
||||||
android:text="@string/select_demo_effects"
|
android:text="@string/select_audio_effects"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/select_video_effects_button"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/select_video_effects_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="32dp"
|
||||||
|
android:layout_marginStart="32dp"
|
||||||
|
android:layout_marginEnd="32dp"
|
||||||
|
android:text="@string/select_video_effects"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/transform_button"
|
app:layout_constraintBottom_toTopOf="@+id/transform_button"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
@ -32,7 +32,8 @@
|
|||||||
<string name="abort_slow_transformation" translatable="false">Abort slow transformation</string>
|
<string name="abort_slow_transformation" translatable="false">Abort slow transformation</string>
|
||||||
<string name="trim" translatable="false">Trim</string>
|
<string name="trim" translatable="false">Trim</string>
|
||||||
<string name="hdr_mode" translatable="false">HDR mode</string>
|
<string name="hdr_mode" translatable="false">HDR mode</string>
|
||||||
<string name="select_demo_effects" translatable="false">Add demo effects</string>
|
<string name="select_audio_effects" translatable="false">Add audio effects</string>
|
||||||
|
<string name="select_video_effects" translatable="false">Add video effects</string>
|
||||||
<string name="periodic_vignette_options" translatable="false">Periodic vignette options</string>
|
<string name="periodic_vignette_options" translatable="false">Periodic vignette options</string>
|
||||||
<string name="no_media_pipe_error" translatable="false">Failed to load MediaPipe processor. Check the README for instructions.</string>
|
<string name="no_media_pipe_error" translatable="false">Failed to load MediaPipe processor. Check the README for instructions.</string>
|
||||||
<string name="transform" translatable="false">Transform</string>
|
<string name="transform" translatable="false">Transform</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user