mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Demo: Split video Effect generation out of createTransformer.
PiperOrigin-RevId: 477524540 (cherry picked from commit 1cfe18cd1f45e850df3b21ca8e63635956cf758e)
This commit is contained in:
parent
55a7316158
commit
c08e4b664b
@ -272,11 +272,38 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
.setEnableFallback(bundle.getBoolean(ConfigurationActivity.ENABLE_FALLBACK))
|
||||
.build());
|
||||
|
||||
ImmutableList.Builder<Effect> effects = new ImmutableList.Builder<>();
|
||||
transformerBuilder.setVideoEffects(createVideoEffectsListFromBundle(bundle));
|
||||
|
||||
if (bundle.getBoolean(ConfigurationActivity.ENABLE_DEBUG_PREVIEW)) {
|
||||
transformerBuilder.setDebugViewProvider(new DemoDebugViewProvider());
|
||||
}
|
||||
}
|
||||
return transformerBuilder
|
||||
.addListener(
|
||||
new Transformer.Listener() {
|
||||
@Override
|
||||
public void onTransformationCompleted(
|
||||
MediaItem mediaItem, TransformationResult transformationResult) {
|
||||
TransformerActivity.this.onTransformationCompleted(filePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransformationError(
|
||||
MediaItem mediaItem, TransformationException exception) {
|
||||
TransformerActivity.this.onTransformationError(exception);
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
private ImmutableList<Effect> createVideoEffectsListFromBundle(Bundle bundle) {
|
||||
@Nullable
|
||||
boolean[] selectedEffects =
|
||||
bundle.getBooleanArray(ConfigurationActivity.DEMO_EFFECTS_SELECTIONS);
|
||||
if (selectedEffects != null) {
|
||||
if (selectedEffects == null) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
ImmutableList.Builder<Effect> effects = new ImmutableList.Builder<>();
|
||||
if (selectedEffects[0]) {
|
||||
effects.add(MatrixTransformationFactory.createDizzyCropEffect());
|
||||
}
|
||||
@ -327,8 +354,8 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
// uses a linear RGB color space internally. Meaning this is only for demonstration
|
||||
// purposes and it does not display a correct sepia frame.
|
||||
float[] sepiaMatrix = {
|
||||
0.393f, 0.349f, 0.272f, 0, 0.769f, 0.686f, 0.534f, 0, 0.189f, 0.168f, 0.131f, 0, 0,
|
||||
0, 0, 1
|
||||
0.393f, 0.349f, 0.272f, 0, 0.769f, 0.686f, 0.534f, 0, 0.189f, 0.168f, 0.131f, 0, 0, 0,
|
||||
0, 1
|
||||
};
|
||||
effects.add((RgbMatrix) (presentationTimeUs, useHdr) -> sepiaMatrix);
|
||||
break;
|
||||
@ -365,8 +392,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
effects.add(
|
||||
new HslAdjustment.Builder()
|
||||
.adjustHue(bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_HUE))
|
||||
.adjustSaturation(
|
||||
bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_SATURATION))
|
||||
.adjustSaturation(bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_SATURATION))
|
||||
.adjustLightness(bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_LIGHTNESS))
|
||||
.build());
|
||||
}
|
||||
@ -397,29 +423,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
if (selectedEffects[10]) {
|
||||
effects.add(MatrixTransformationFactory.createZoomInTransition());
|
||||
}
|
||||
transformerBuilder.setVideoEffects(effects.build());
|
||||
}
|
||||
|
||||
if (bundle.getBoolean(ConfigurationActivity.ENABLE_DEBUG_PREVIEW)) {
|
||||
transformerBuilder.setDebugViewProvider(new DemoDebugViewProvider());
|
||||
}
|
||||
}
|
||||
return transformerBuilder
|
||||
.addListener(
|
||||
new Transformer.Listener() {
|
||||
@Override
|
||||
public void onTransformationCompleted(
|
||||
MediaItem mediaItem, TransformationResult transformationResult) {
|
||||
TransformerActivity.this.onTransformationCompleted(filePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransformationError(
|
||||
MediaItem mediaItem, TransformationException exception) {
|
||||
TransformerActivity.this.onTransformationError(exception);
|
||||
}
|
||||
})
|
||||
.build();
|
||||
return effects.build();
|
||||
}
|
||||
|
||||
@RequiresNonNull({
|
||||
|
Loading…
x
Reference in New Issue
Block a user