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

Remove deprecated MediaTransformer methods #184

Merged
merged 1 commit into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
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
128 changes: 0 additions & 128 deletions litr/src/main/java/com/linkedin/android/litr/MediaTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
import com.linkedin.android.litr.codec.MediaCodecEncoder;
import com.linkedin.android.litr.exception.MediaSourceException;
import com.linkedin.android.litr.exception.MediaTargetException;
import com.linkedin.android.litr.filter.GlFilter;
import com.linkedin.android.litr.io.MediaExtractorMediaSource;
import com.linkedin.android.litr.io.MediaMuxerMediaTarget;
import com.linkedin.android.litr.io.MediaSource;
import com.linkedin.android.litr.io.MediaTarget;
import com.linkedin.android.litr.render.AudioRenderer;
import com.linkedin.android.litr.render.GlVideoRenderer;
import com.linkedin.android.litr.render.Renderer;
import com.linkedin.android.litr.utils.TranscoderUtils;

import java.io.File;
Expand Down Expand Up @@ -90,46 +88,6 @@ public MediaTransformer(@NonNull Context context, @Nullable Looper looper, @Null
this.executorService = executorService;
}

/**
* 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.
*
* @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 outputFilePath Absolute path of output media file
* @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 granularity progress reporting granularity. NO_GRANULARITY for per-frame progress reporting,
* or positive integer value for number of times transformation progress should be reported
* @param filters optional OpenGL filters to apply to video frames
*
* @deprecated use the version with {@link TransformationOptions}
*/
@Deprecated
public void transform(@NonNull String requestId,
@NonNull Uri inputUri,
@NonNull String outputFilePath,
@Nullable MediaFormat targetVideoFormat,
@Nullable MediaFormat targetAudioFormat,
@NonNull TransformationListener listener,
@IntRange(from = GRANULARITY_NONE) int granularity,
@Nullable List<GlFilter> filters) {
TransformationOptions transformationOptions = new TransformationOptions.Builder()
.setGranularity(granularity)
.setVideoFilters(filters)
.build();
transform(requestId,
inputUri,
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.
Expand Down Expand Up @@ -239,75 +197,6 @@ public void transform(@NonNull String requestId,
}
}

/**
* Transform audio/video tracks using provided transformation components (source, target, decoder, etc.)
* It is up to a client to provide component implementations that work together - for example, output of media source
* should be in format that decoder would accept, or renderer should use OpenGL if decoder and encoder use Surface.
*
* If renderer has overlay(s), video track(s) will be transcoded with parameters as close to source format as possible.
*
* @param requestId client defined unique id for a transformation request. If not unique, {@link IllegalArgumentException} will be thrown.
* @param mediaSource {@link MediaSource} to provide input frames
* @param decoder {@link Decoder} to decode input video frames
* @param videoRenderer {@link Renderer} to draw (with optional filters) decoder's output frame onto encoder's input frame
* @param encoder {@link Encoder} to encode output video frames into target format
* @param mediaTarget {@link MediaTarget} to write/mux output frames
* @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 granularity progress reporting granularity. NO_GRANULARITY for per-frame progress reporting,
* or positive integer value for number of times transformation progress should be reported
* @deprecated use transform(List<TrackTransform>> instead
*/
@Deprecated
public void transform(@NonNull String requestId,
@NonNull MediaSource mediaSource,
@NonNull Decoder decoder,
@NonNull Renderer videoRenderer,
@NonNull Encoder encoder,
@NonNull MediaTarget mediaTarget,
@Nullable MediaFormat targetVideoFormat,
@Nullable MediaFormat targetAudioFormat,
@NonNull TransformationListener listener,
@IntRange(from = GRANULARITY_NONE) int granularity) {
if (futureMap.containsKey(requestId)) {
throw new IllegalArgumentException("Request with id " + requestId + " already exists");
}

int trackCount = mediaSource.getTrackCount();
List<TrackTransform> trackTransforms = new ArrayList<>(trackCount);
for (int track = 0; track < trackCount; track++) {
MediaFormat sourceMediaFormat = mediaSource.getTrackFormat(track);
String mimeType = null;
if (sourceMediaFormat.containsKey(MediaFormat.KEY_MIME)) {
mimeType = sourceMediaFormat.getString(MediaFormat.KEY_MIME);
}

if (mimeType == null) {
Log.e(TAG, "Mime type is null for track " + track);
continue;
}

TrackTransform.Builder trackTransformBuilder = new TrackTransform.Builder(mediaSource, track, mediaTarget)
.setTargetTrack(track);

if (mimeType.startsWith("video")) {
trackTransformBuilder.setDecoder(decoder)
.setRenderer(videoRenderer)
.setEncoder(encoder)
.setTargetFormat(targetVideoFormat);
} else if (mimeType.startsWith("audio")) {
trackTransformBuilder.setDecoder(new MediaCodecDecoder())
.setEncoder(new MediaCodecEncoder())
.setTargetFormat(targetAudioFormat);
}

trackTransforms.add(trackTransformBuilder.build());
}

transform(requestId, trackTransforms, listener, granularity);
}

/**
* Transform using specific track transformation instructions. This allows things muxing/demuxing tracks, applying
* different transformations to different tracks, etc.
Expand Down Expand Up @@ -379,23 +268,6 @@ public void release() {
executorService.shutdownNow();
}

/**
* Estimates target size of a target video based on a provided target format. If no target audio format is specified,
* uses 320 Kbps bitrate to estimate audio track size, if cannot extract audio bitrate. If track duration is not available,
* maximum track duration will be used. If track bitrate cannot be extracted, track will not be used to estimate size.
* @param inputUri {@link Uri} of a source video
* @param targetVideoFormat video format for a transformation target
* @param targetAudioFormat audio format for a transformation target
* @return estimated size of a transcoding target video file in bytes, -1 otherwise
* @deprecated use getEstimatedTargetVideoSize that takes List<TrackTransform> or TransformationOptions
*/
@Deprecated
public long getEstimatedTargetVideoSize(@NonNull Uri inputUri,
@NonNull MediaFormat targetVideoFormat,
@Nullable MediaFormat targetAudioFormat) {
return getEstimatedTargetVideoSize(inputUri, targetVideoFormat, targetAudioFormat, null);
}

/**
* Estimates target size of a target video based on provided target formats. If no target audio format is specified,
* uses 320 Kbps bitrate to estimate audio track size, if cannot extract audio bitrate. If track duration is not available,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
import android.content.Context;
import android.media.MediaFormat;
import android.net.Uri;

import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.linkedin.android.litr.MediaTransformer;
import com.linkedin.android.litr.TrackTransform;
import com.linkedin.android.litr.TransformationListener;
import com.linkedin.android.litr.codec.Decoder;
import com.linkedin.android.litr.codec.Encoder;
import com.linkedin.android.litr.filter.GlFilter;
import com.linkedin.android.litr.io.MediaSource;
import com.linkedin.android.litr.io.MediaTarget;
import com.linkedin.android.litr.render.Renderer;
import com.linkedin.android.litr.TransformationOptions;

import java.util.List;

Expand All @@ -43,26 +40,11 @@ public void setEvents(@NonNull List<TransformationEvent> transformationEvents) {
@Override
public void transform(@NonNull String requestId,
@NonNull Uri inputUri,
@NonNull String outputFilePath,
@NonNull Uri outputUri,
@Nullable MediaFormat targetVideoFormat,
@Nullable MediaFormat targetAudioFormat,
@NonNull TransformationListener listener,
@IntRange(from = GRANULARITY_NONE) int granularity,
@Nullable List<GlFilter> filters) {
playEvents(listener);
}

@Override
public void transform(@NonNull String requestId,
@NonNull MediaSource mediaSource,
@NonNull Decoder decoder,
@NonNull Renderer videoRenderer,
@NonNull Encoder encoder,
@NonNull MediaTarget mediaTarget,
@Nullable MediaFormat targetVideoFormat,
@Nullable MediaFormat targetAudioFormat,
@NonNull TransformationListener listener,
@IntRange(from = GRANULARITY_NONE) int granularity) {
@Nullable TransformationOptions transformationOptions) {
playEvents(listener);
}

Expand All @@ -84,7 +66,8 @@ public void release() {}
@Override
public long getEstimatedTargetVideoSize(@NonNull Uri inputUri,
@NonNull MediaFormat targetVideoFormat,
@Nullable MediaFormat targetAudioFormat) {
@Nullable MediaFormat targetAudioFormat,
@Nullable TransformationOptions transformationOptions) {
return 0;
}

Expand Down