84 lines
2.9 KiB
Java
84 lines
2.9 KiB
Java
package com.hw.videoprocessor;
|
|
|
|
import android.media.MediaCodec;
|
|
import android.media.MediaCodecInfo;
|
|
import android.media.MediaExtractor;
|
|
import android.media.MediaFormat;
|
|
import com.baidu.cloud.media.player.misc.IMediaFormat;
|
|
import com.hw.videoprocessor.util.CL;
|
|
import java.io.IOException;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class VideoUtil {
|
|
public static int a(MediaExtractor mediaExtractor, boolean z) {
|
|
int trackCount = mediaExtractor.getTrackCount();
|
|
for (int i = 0; i < trackCount; i++) {
|
|
String string = mediaExtractor.getTrackFormat(i).getString(IMediaFormat.KEY_MIME);
|
|
if (z) {
|
|
if (string.startsWith("audio/")) {
|
|
return i;
|
|
}
|
|
} else if (string.startsWith("video/")) {
|
|
return i;
|
|
}
|
|
}
|
|
return -5;
|
|
}
|
|
|
|
public static int b(String str) {
|
|
MediaExtractor mediaExtractor = new MediaExtractor();
|
|
try {
|
|
mediaExtractor.setDataSource(str);
|
|
MediaFormat trackFormat = mediaExtractor.getTrackFormat(a(mediaExtractor, false));
|
|
return trackFormat.containsKey("frame-rate") ? trackFormat.getInteger("frame-rate") : -1;
|
|
} catch (IOException e) {
|
|
CL.a(e);
|
|
return -1;
|
|
} finally {
|
|
mediaExtractor.release();
|
|
}
|
|
}
|
|
|
|
public static float a(String str) throws IOException {
|
|
MediaExtractor mediaExtractor = new MediaExtractor();
|
|
mediaExtractor.setDataSource(str);
|
|
int i = 0;
|
|
mediaExtractor.selectTrack(a(mediaExtractor, false));
|
|
long j = 0;
|
|
while (true) {
|
|
long sampleTime = mediaExtractor.getSampleTime();
|
|
if (sampleTime < 0) {
|
|
mediaExtractor.release();
|
|
return i / ((j / 1000.0f) / 1000.0f);
|
|
}
|
|
i++;
|
|
mediaExtractor.advance();
|
|
j = sampleTime;
|
|
}
|
|
}
|
|
|
|
public static boolean a(MediaCodec mediaCodec, String str, MediaFormat mediaFormat, int i, int i2) {
|
|
MediaCodecInfo.CodecProfileLevel[] codecProfileLevelArr = mediaCodec.getCodecInfo().getCapabilitiesForType(str).profileLevels;
|
|
if (codecProfileLevelArr == null) {
|
|
return false;
|
|
}
|
|
for (MediaCodecInfo.CodecProfileLevel codecProfileLevel : codecProfileLevelArr) {
|
|
if (codecProfileLevel.profile == i && codecProfileLevel.level == i2) {
|
|
mediaFormat.setInteger("profile", i);
|
|
mediaFormat.setInteger("level", i2);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static int a(MediaCodec mediaCodec, String str) {
|
|
try {
|
|
return mediaCodec.getCodecInfo().getCapabilitiesForType(str).getVideoCapabilities().getBitrateRange().getUpper().intValue();
|
|
} catch (Exception e) {
|
|
CL.a(e);
|
|
return -1;
|
|
}
|
|
}
|
|
}
|