Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new transform method that accepts output URI #182

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.linkedin.android.litr.render.Renderer;
import com.linkedin.android.litr.utils.TranscoderUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -150,15 +151,49 @@ public void transform(@NonNull String requestId,
@Nullable MediaFormat targetAudioFormat,
@NonNull TransformationListener listener,
@Nullable TransformationOptions transformationOptions) {
transform(
requestId,
inputUri,
Uri.fromFile(new File(outputFilePath)),
targetVideoFormat,
targetAudioFormat,
listener,
transformationOptions
);
}

/**
* Transform video and audio track(s): change resolution, frame rate, bitrate, etc. Video track transformation
* uses default hardware accelerated codecs and OpenGL renderer.
*
* If overlay(s) are provided, video track(s) will be transcoded with parameters as close to source format as possible.
*
* This API is recommended to be used on devices with Android 10+ because it works with scoped storage
*
* @param requestId client defined unique id for a transformation request. If not unique, {@link IllegalArgumentException} will be thrown.
* @param inputUri input video {@link Uri}
* @param outputUri {@link Uri} of transformation output media
* @param targetVideoFormat target format parameters for video track(s), null to keep them as is
* @param targetAudioFormat target format parameters for audio track(s), null to keep them as is
* @param listener {@link TransformationListener} implementation, to get updates on transformation status/result/progress
* @param transformationOptions optional instance of {@link TransformationOptions}
*/
public void transform(@NonNull String requestId,
@NonNull Uri inputUri,
@NonNull Uri outputUri,
@Nullable MediaFormat targetVideoFormat,
@Nullable MediaFormat targetAudioFormat,
@NonNull TransformationListener listener,
@Nullable TransformationOptions transformationOptions) {
TransformationOptions options = transformationOptions == null
? new TransformationOptions.Builder().build()
: transformationOptions;

try {
MediaSource mediaSource = new MediaExtractorMediaSource(context, inputUri, options.sourceMediaRange);
MediaTarget mediaTarget = new MediaMuxerMediaTarget(
outputFilePath,
context,
outputUri,
mediaSource.getTrackCount(),
mediaSource.getOrientationHint(),
MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
Expand Down