Skip to content

Commit 96e89f0

Browse files
committed
获取编码器的行为做一些特殊兼容
1 parent cd48615 commit 96e89f0

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

app/src/main/java/com/demo/mediacodec/transcode/TranscodeRunner.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,19 @@ private void prepareEncoder(VideoOutputConfig outputConfig) throws Exception {
289289
mConfig, outputConfig);
290290

291291
String codecName = MediaCodecUtils.findEncoderByFormat(mOutputFormat);
292+
if (TextUtils.isEmpty(codecName)) {
293+
if (mConfig.outWidth < mConfig.outHeight) {
294+
//有些设备下面判断是否支持写的不够好,这里主动交换一下width和height,看能否获取出编码器
295+
MediaFormat tempF = MediaCodecUtils.createOutputFormat(mContext, mVideoUri
296+
, mOriVideoFormat, mConfig, outputConfig);
297+
tempF.setInteger(MediaFormat.KEY_WIDTH, mConfig.outHeight);
298+
tempF.setInteger(MediaFormat.KEY_HEIGHT, mConfig.outWidth);
299+
codecName = MediaCodecUtils.findEncoderByFormat(tempF);
300+
}
301+
}
292302
if (TextUtils.isEmpty(codecName)) {
293303
throw new NoSupportMediaCodecException("没有找到合适的编码器! outputFormat:" + mOutputFormat,
294-
outputConfig.outputLevel);
304+
outputConfig.outputLevel);
295305
}
296306
mEncodeCodecThread = new HandlerThread("EncodeCodecThread");
297307
mEncodeCodecThread.start();

0 commit comments

Comments
 (0)