Skip to content

Commit

Permalink
Allow creating fragmented MP4 file via demo app
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 594435072
  • Loading branch information
SheenaChhabra authored and copybara-github committed Dec 29, 2023
1 parent 27ae6d9 commit 846ace1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> hdrModeAdapter =
new ArrayAdapter<>(/* context= */ this, R.layout.spinner_item);
Expand Down Expand Up @@ -409,6 +412,7 @@ protected void onNewIntent(Intent intent) {
"enableFallbackCheckBox",
"enableDebugPreviewCheckBox",
"abortSlowExportCheckBox",
"produceFragmentedMp4CheckBox",
"hdrModeSpinner",
"audioEffectsSelections",
"videoEffectsSelections"
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@
android:id="@+id/abort_slow_export_checkbox"
android:layout_gravity="end"/>
</TableRow>
<TableRow
android:layout_weight="1">
<TextView
android:layout_gravity="center_vertical"
android:text="@string/produce_fragmented_mp4" />
<CheckBox
android:id="@+id/produce_fragmented_mp4_checkbox"
android:layout_gravity="end"/>
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="center_vertical" >
Expand Down
1 change: 1 addition & 0 deletions demos/transformer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<string name="enable_fallback" translatable="false">Enable fallback</string>
<string name="enable_debug_preview" translatable="false">Enable debug preview</string>
<string name="abort_slow_export" translatable="false">Abort slow export</string>
<string name="produce_fragmented_mp4" translatable="false">Produce fragmented MP4</string>
<string name="trim" translatable="false">Trim</string>
<string name="hdr_mode" translatable="false">HDR mode</string>
<string name="select_audio_effects" translatable="false">Add audio effects</string>
Expand Down

0 comments on commit 846ace1

Please sign in to comment.