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
This commit is contained in:
parent
1711d7f4c2
commit
1cfe18cd1f
@ -272,11 +272,38 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
.setEnableFallback(bundle.getBoolean(ConfigurationActivity.ENABLE_FALLBACK))
|
.setEnableFallback(bundle.getBoolean(ConfigurationActivity.ENABLE_FALLBACK))
|
||||||
.build());
|
.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
|
@Nullable
|
||||||
boolean[] selectedEffects =
|
boolean[] selectedEffects =
|
||||||
bundle.getBooleanArray(ConfigurationActivity.DEMO_EFFECTS_SELECTIONS);
|
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]) {
|
if (selectedEffects[0]) {
|
||||||
effects.add(MatrixTransformationFactory.createDizzyCropEffect());
|
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
|
// uses a linear RGB color space internally. Meaning this is only for demonstration
|
||||||
// purposes and it does not display a correct sepia frame.
|
// purposes and it does not display a correct sepia frame.
|
||||||
float[] sepiaMatrix = {
|
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.393f, 0.349f, 0.272f, 0, 0.769f, 0.686f, 0.534f, 0, 0.189f, 0.168f, 0.131f, 0, 0, 0,
|
||||||
0, 0, 1
|
0, 1
|
||||||
};
|
};
|
||||||
effects.add((RgbMatrix) (presentationTimeUs, useHdr) -> sepiaMatrix);
|
effects.add((RgbMatrix) (presentationTimeUs, useHdr) -> sepiaMatrix);
|
||||||
break;
|
break;
|
||||||
@ -365,8 +392,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
effects.add(
|
effects.add(
|
||||||
new HslAdjustment.Builder()
|
new HslAdjustment.Builder()
|
||||||
.adjustHue(bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_HUE))
|
.adjustHue(bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_HUE))
|
||||||
.adjustSaturation(
|
.adjustSaturation(bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_SATURATION))
|
||||||
bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_SATURATION))
|
|
||||||
.adjustLightness(bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_LIGHTNESS))
|
.adjustLightness(bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_LIGHTNESS))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
@ -397,29 +423,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
if (selectedEffects[10]) {
|
if (selectedEffects[10]) {
|
||||||
effects.add(MatrixTransformationFactory.createZoomInTransition());
|
effects.add(MatrixTransformationFactory.createZoomInTransition());
|
||||||
}
|
}
|
||||||
transformerBuilder.setVideoEffects(effects.build());
|
return 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresNonNull({
|
@RequiresNonNull({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user