检测是否可以被硬解
image.pngimage.png
1、在FFMpeg中获取视频解码器的名称
从AVCodecContext结构体中取得AVCodec,AVCodec也是一个结构体,这个结构体中有个属性name
2、根据1中获取的name查找手机是否有对应的硬解码器
一般是在FFMpeg中得到视频解码器的名称(name)后,回调Java层,在Java层检测手机是否有对应的解码器,主要用到类MediaCodecList
private static Map<String, String> codecMap = new HashMap<>();
static {
//https://juejin.im/entry/5aa234f751882555712bf210#comment
/**
"video/x-vnd.on2.vp8" - VP8 video (i.e. video in .webm)
"video/x-vnd.on2.vp9" - VP9 video (i.e. video in .webm)
"video/avc" - H.264/AVC video
"video/hevc" - H.265/HEVC video
"video/mp4v-es" - MPEG4 video
"video/3gpp" - H.263 video
"audio/3gpp" - AMR narrowband audio
"audio/amr-wb" - AMR wideband audio
"audio/mpeg" - MPEG1/2 audio layer III
"audio/mp4a-latm" - AAC audio (note, this is raw AAC packets, not packaged in LATM!)
"audio/vorbis" - vorbis audio
"audio/g711-alaw" - G.711 alaw audio
"audio/g711-mlaw" - G.711 ulaw audio
*/
codecMap.put("h264", "video/avc");
codecMap.put("h265","hevc");
}
public static String findVideoCodecName(String ffcodename)
{
if(codecMap.containsKey(ffcodename))
{
return codecMap.get(ffcodename);
}
return "";
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static boolean isSupportCodec(String ffcodecname)
{
boolean supportvideo = false;
MediaCodecList mediaCodecList =new MediaCodecList(MediaCodecList.ALL_CODECS);
MediaCodecInfo[] mediaCodecInfos=mediaCodecList.getCodecInfos();
for(int i = 0; i < mediaCodecInfos.length; i++)
{
String[] types = mediaCodecInfos[i].getSupportedTypes();
for(int j = 0; j < types.length; j++)
{
if(types[j].equals(findVideoCodecName(ffcodecname)))
{
supportvideo = true;
break;
}
}
if(supportvideo)
{
break;
}
}
return supportvideo;
}
如果需要对视频进行硬解码,还需要给AVPacket添加解码头信息
image.pngimage.png
image.png
image.png
经过分析数据发现,原始的AVPacket数据和过滤后的AVPacket数据差别是,过滤后的数据前面会加上0001
参考:https://blog.csdn.net/leixiaohua1020/article/details/39767055
网友评论