mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Apply suggested AVC profile depending on the API version.
PiperOrigin-RevId: 424322341
This commit is contained in:
parent
47fd32f1d4
commit
2ed1deb52d
1 changed files with 26 additions and 3 deletions
|
|
@ -32,6 +32,7 @@ import androidx.media3.common.Format;
|
||||||
import androidx.media3.common.MimeTypes;
|
import androidx.media3.common.MimeTypes;
|
||||||
import androidx.media3.common.util.MediaFormatUtil;
|
import androidx.media3.common.util.MediaFormatUtil;
|
||||||
import androidx.media3.common.util.TraceUtil;
|
import androidx.media3.common.util.TraceUtil;
|
||||||
|
import androidx.media3.common.util.Util;
|
||||||
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil;
|
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue