Commit 651fa0db by claincly Committed by Andrew Lewis

Apply suggested AVC profile depending on the API version.

PiperOrigin-RevId: 424322341
parent 76ceca70
...@@ -33,6 +33,7 @@ import com.google.android.exoplayer2.mediacodec.MediaCodecUtil; ...@@ -33,6 +33,7 @@ import com.google.android.exoplayer2.mediacodec.MediaCodecUtil;
import com.google.android.exoplayer2.util.MediaFormatUtil; import com.google.android.exoplayer2.util.MediaFormatUtil;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.TraceUtil; import com.google.android.exoplayer2.util.TraceUtil;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull;
...@@ -123,9 +124,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -123,9 +124,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
format = getVideoEncoderSupportedFormat(format, allowedMimeTypes); format = getVideoEncoderSupportedFormat(format, allowedMimeTypes);
MediaFormat mediaFormat = String mimeType = checkNotNull(format.sampleMimeType);
MediaFormat.createVideoFormat( MediaFormat mediaFormat = MediaFormat.createVideoFormat(mimeType, format.width, format.height);
checkNotNull(format.sampleMimeType), format.width, format.height);
mediaFormat.setFloat(MediaFormat.KEY_FRAME_RATE, format.frameRate); mediaFormat.setFloat(MediaFormat.KEY_FRAME_RATE, format.frameRate);
mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, format.averageBitrate); mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, format.averageBitrate);
...@@ -138,6 +138,29 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -138,6 +138,29 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} }
} }
// TODO(b/210593256): Remove overriding profile/level (before API 29) after switching to in-app
// muxing.
if (mimeType.equals(MimeTypes.VIDEO_H264)) {
// Applying suggested profile/level settings from
// https://developer.android.com/guide/topics/media/sharing-video#b-frames_and_encoding_profiles
if (Util.SDK_INT >= 29) {
// Use the highest supported profile and use B-frames.
mediaFormat.setInteger(
MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AVCProfileHigh);
mediaFormat.setInteger(MediaFormat.KEY_MAX_B_FRAMES, 1);
} else if (Util.SDK_INT >= 26) {
// Use the highest-supported profile, but disable the generation of B-frames. This
// accommodates some limitations in the MediaMuxer in these system versions.
mediaFormat.setInteger(
MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AVCProfileHigh);
mediaFormat.setInteger(MediaFormat.KEY_LATENCY, 1);
} else {
// Use the baseline profile for safest results.
mediaFormat.setInteger(
MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline);
}
}
mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, DEFAULT_COLOR_FORMAT); mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, DEFAULT_COLOR_FORMAT);
mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, DEFAULT_I_FRAME_INTERVAL_SECS); mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, DEFAULT_I_FRAME_INTERVAL_SECS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment