前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MediaCodec判断是否可以采用硬解码

MediaCodec判断是否可以采用硬解码

作者头像
曾大稳
发布2018-09-11 10:53:36
2.1K0
发布2018-09-11 10:53:36
举报
文章被收录于专栏:曾大稳的博客曾大稳的博客
代码语言:javascript
复制
import android.media.MediaCodecList;

import java.util.HashMap;
import java.util.Map;

public class VideoSupportUitl {

    private static Map<String, String> codecMap = new HashMap<>();
    static {
        codecMap.put("h264", "video/avc");
    }

    public static String findVideoCodecName(String ffcodename){
        if(codecMap.containsKey(ffcodename))
        {
            return codecMap.get(ffcodename);
        }
        return "";
    }

    public static boolean isSupportCodec(String ffcodecname){
        boolean supportvideo = false;
        int count = MediaCodecList.getCodecCount();
        for(int i = 0; i < count; i++)
        {
            String[] tyeps = MediaCodecList.getCodecInfoAt(i).getSupportedTypes();
            for(int j = 0; j < tyeps.length; j++)
            {
                if(tyeps[j].equals(findVideoCodecName(ffcodecname)))
                {
                    supportvideo = true;
                    break;
                }
            }
            if(supportvideo)
            {
                break;
            }
        }
        return supportvideo;
    }
}

具体的类型对应关系可以查看相关文档,这里在Android源码MediaCodec.createDecoderByType()里面有一些相关的对应支持类型。

代码语言:javascript
复制

/**
    * Instantiate the preferred decoder supporting input data of the given mime type.
    *
    * The following is a partial list of defined mime types and their semantics:
    * <ul>
    * <li>"video/x-vnd.on2.vp8" - VP8 video (i.e. video in .webm)
    * <li>"video/x-vnd.on2.vp9" - VP9 video (i.e. video in .webm)
    * <li>"video/avc" - H.264/AVC video
    * <li>"video/hevc" - H.265/HEVC video
    * <li>"video/mp4v-es" - MPEG4 video
    * <li>"video/3gpp" - H.263 video
    * <li>"audio/3gpp" - AMR narrowband audio
    * <li>"audio/amr-wb" - AMR wideband audio
    * <li>"audio/mpeg" - MPEG1/2 audio layer III
    * <li>"audio/mp4a-latm" - AAC audio (note, this is raw AAC packets, not packaged in LATM!)
    * <li>"audio/vorbis" - vorbis audio
    * <li>"audio/g711-alaw" - G.711 alaw audio
    * <li>"audio/g711-mlaw" - G.711 ulaw audio
    * </ul>
    *
    * <strong>Note:</strong> It is preferred to use {@link MediaCodecList#findDecoderForFormat}
    * and {@link #createByCodecName} to ensure that the resulting codec can handle a
    * given format.
    *
    * @param type The mime type of the input data.
    * @throws IOException if the codec cannot be created.
    * @throws IllegalArgumentException if type is not a valid mime type.
    * @throws NullPointerException if type is null.
    */
   @NonNull
   public static MediaCodec createDecoderByType(@NonNull String type)
           throws IOException {
       return new MediaCodec(type, true /* nameIsType */, false /* encoder */);
   }

ffmpeg里面

代码语言:javascript
复制
((const AVCodec*)(avCodecContext->codec))->name;

即可拿到name,然后jni交互调用即可。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-07-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档