From 846ace16aa8051ddca9b5feb61ac8db2987e4a06 Mon Sep 17 00:00:00 2001 From: sheenachhabra Date: Fri, 29 Dec 2023 04:36:14 -0800 Subject: [PATCH] Allow creating fragmented MP4 file via demo app PiperOrigin-RevId: 594435072 --- .../demo/transformer/ConfigurationActivity.java | 5 +++++ .../demo/transformer/TransformerActivity.java | 16 ++++++++++++++-- .../main/res/layout/configuration_activity.xml | 9 +++++++++ .../transformer/src/main/res/values/strings.xml | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/demos/transformer/src/main/java/androidx/media3/demo/transformer/ConfigurationActivity.java b/demos/transformer/src/main/java/androidx/media3/demo/transformer/ConfigurationActivity.java index cc6f1c104fc..cbec6ddc18a 100644 --- a/demos/transformer/src/main/java/androidx/media3/demo/transformer/ConfigurationActivity.java +++ b/demos/transformer/src/main/java/androidx/media3/demo/transformer/ConfigurationActivity.java @@ -78,6 +78,7 @@ public final class ConfigurationActivity extends AppCompatActivity { public static final String ENABLE_FALLBACK = "enable_fallback"; public static final String ENABLE_DEBUG_PREVIEW = "enable_debug_preview"; public static final String ABORT_SLOW_EXPORT = "abort_slow_export"; + public static final String PRODUCE_FRAGMENTED_MP4 = "produce_fragmented_mp4"; public static final String HDR_MODE = "hdr_mode"; public static final String AUDIO_EFFECTS_SELECTIONS = "audio_effects_selections"; public static final String VIDEO_EFFECTS_SELECTIONS = "video_effects_selections"; @@ -230,6 +231,7 @@ public final class ConfigurationActivity extends AppCompatActivity { private @MonotonicNonNull CheckBox enableFallbackCheckBox; private @MonotonicNonNull CheckBox enableDebugPreviewCheckBox; private @MonotonicNonNull CheckBox abortSlowExportCheckBox; + private @MonotonicNonNull CheckBox produceFragmentedMp4CheckBox; private @MonotonicNonNull Spinner hdrModeSpinner; private @MonotonicNonNull Button selectAudioEffectsButton; private @MonotonicNonNull Button selectVideoEffectsButton; @@ -345,6 +347,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { enableDebugPreviewCheckBox = findViewById(R.id.enable_debug_preview_checkbox); abortSlowExportCheckBox = findViewById(R.id.abort_slow_export_checkbox); + produceFragmentedMp4CheckBox = findViewById(R.id.produce_fragmented_mp4_checkbox); ArrayAdapter hdrModeAdapter = new ArrayAdapter<>(/* context= */ this, R.layout.spinner_item); @@ -409,6 +412,7 @@ protected void onNewIntent(Intent intent) { "enableFallbackCheckBox", "enableDebugPreviewCheckBox", "abortSlowExportCheckBox", + "produceFragmentedMp4CheckBox", "hdrModeSpinner", "audioEffectsSelections", "videoEffectsSelections" @@ -450,6 +454,7 @@ private void startExport(View view) { bundle.putBoolean(ENABLE_FALLBACK, enableFallbackCheckBox.isChecked()); bundle.putBoolean(ENABLE_DEBUG_PREVIEW, enableDebugPreviewCheckBox.isChecked()); bundle.putBoolean(ABORT_SLOW_EXPORT, abortSlowExportCheckBox.isChecked()); + bundle.putBoolean(PRODUCE_FRAGMENTED_MP4, produceFragmentedMp4CheckBox.isChecked()); String selectedhdrMode = String.valueOf(hdrModeSpinner.getSelectedItem()); bundle.putInt(HDR_MODE, checkNotNull(HDR_MODE_DESCRIPTIONS.get(selectedhdrMode))); bundle.putBooleanArray(AUDIO_EFFECTS_SELECTIONS, audioEffectsSelections); diff --git a/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java b/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java index ff1f84eff40..b63b4d47445 100644 --- a/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java +++ b/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java @@ -87,6 +87,8 @@ import androidx.media3.transformer.Effects; import androidx.media3.transformer.ExportException; import androidx.media3.transformer.ExportResult; +import androidx.media3.transformer.InAppMuxer; +import androidx.media3.transformer.Muxer; import androidx.media3.transformer.ProgressHolder; import androidx.media3.transformer.Transformer; import androidx.media3.ui.AspectRatioFrameLayout; @@ -320,11 +322,21 @@ private Transformer createTransformer(@Nullable Bundle bundle, Uri inputUri, Str .setEnableFallback(bundle.getBoolean(ConfigurationActivity.ENABLE_FALLBACK)) .build()); + long maxDelayBetweenSamplesMs = DefaultMuxer.Factory.DEFAULT_MAX_DELAY_BETWEEN_SAMPLES_MS; if (!bundle.getBoolean(ConfigurationActivity.ABORT_SLOW_EXPORT)) { - transformerBuilder.setMuxerFactory( - new DefaultMuxer.Factory(/* maxDelayBetweenSamplesMs= */ C.TIME_UNSET)); + maxDelayBetweenSamplesMs = C.TIME_UNSET; } + Muxer.Factory muxerFactory = new DefaultMuxer.Factory(maxDelayBetweenSamplesMs); + if (bundle.getBoolean(ConfigurationActivity.PRODUCE_FRAGMENTED_MP4)) { + muxerFactory = + new InAppMuxer.Factory.Builder() + .setMaxDelayBetweenSamplesMs(maxDelayBetweenSamplesMs) + .setFragmentedMp4Enabled(true) + .build(); + } + transformerBuilder.setMuxerFactory(muxerFactory); + if (bundle.getBoolean(ConfigurationActivity.ENABLE_DEBUG_PREVIEW)) { transformerBuilder.setDebugViewProvider(new DemoDebugViewProvider()); } diff --git a/demos/transformer/src/main/res/layout/configuration_activity.xml b/demos/transformer/src/main/res/layout/configuration_activity.xml index d492da4bbbd..ec07d6eb99d 100644 --- a/demos/transformer/src/main/res/layout/configuration_activity.xml +++ b/demos/transformer/src/main/res/layout/configuration_activity.xml @@ -215,6 +215,15 @@ android:id="@+id/abort_slow_export_checkbox" android:layout_gravity="end"/> + + + + diff --git a/demos/transformer/src/main/res/values/strings.xml b/demos/transformer/src/main/res/values/strings.xml index 7b32d75c6ba..b1b06021c97 100644 --- a/demos/transformer/src/main/res/values/strings.xml +++ b/demos/transformer/src/main/res/values/strings.xml @@ -30,6 +30,7 @@ Enable fallback Enable debug preview Abort slow export + Produce fragmented MP4 Trim HDR mode Add audio effects