zoukankan      html  css  js  c++  java
  • avcodec_find_encoder/avcodec_find_encoder_by_name

    关键函数

    /**
     * Find a registered encoder with a matching codec ID.
     * 利用编码器ID查找编码器(AVCodec.id)
     * @param id AVCodecID of the requested encoder
     * @return An encoder if one was found, NULL otherwise.
     */
    AVCodec *avcodec_find_encoder(enum AVCodecID id);
    
    /**
     * Find a registered encoder with the specified name.
     * 利用编码器名称查找编码器(AVCodec.name)
     * @param name name of the requested encoder
     * @return An encoder if one was found, NULL otherwise.
     */
    AVCodec *avcodec_find_encoder_by_name(const char *name);
    

    编码器说明

    • 编码器存储方式是数组
      AVCodec *codec_list[]={NULL, NULL}

      # configure文件
      ENCODER_LIST=$(find_things_extern encoder AVCodec libavcodec/allcodecs.c)
      DECODER_LIST=$(find_things_extern decoder AVCodec libavcodec/allcodecs.c)
      CODEC_LIST="
          $ENCODER_LIST
          $DECODER_LIST
      "
      
      // codec_list的初始化
      static AVOnce av_codec_static_init = AV_ONCE_INIT;
      static void av_codec_init_static(void)
      {
          for (int i = 0; codec_list[i]; i++) {
              if (codec_list[i]->init_static_data)
                  codec_list[i]->init_static_data((AVCodec*)codec_list[i]);
          }
      }
      
    • avcodec_find_encoderavcodec_find_encoder_by_name就是通过遍历codec_list来查找指定编码器的,找到这返回指定编码器,否则返回NULL

      // avcodec_find_encoder
      AVCodec *avcodec_find_encoder(enum AVCodecID id)
      {
          return find_codec(id, av_codec_is_encoder);
      }
      
      static AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *))
      {
          const AVCodec *p, *experimental = NULL;
          void *i = 0;
      
          id = remap_deprecated_codec_id(id);
      
          while ((p = av_codec_iterate(&i))) {
              if (!x(p))
                  continue;
              if (p->id == id) {
                  if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) {
                      experimental = p;
                  } else
                      return (AVCodec*)p;
              }
          }
      
          return (AVCodec*)experimental;
      }
      
      // avcodec_find_encoder_by_name
      AVCodec *avcodec_find_encoder_by_name(const char *name)
      {
          return find_codec_by_name(name, av_codec_is_encoder);
      }
      
      static AVCodec *find_codec_by_name(const char *name, int (*x)(const AVCodec *))
      {
          void *i = 0;
          const AVCodec *p;
      
          if (!name)
              return NULL;
      
          while ((p = av_codec_iterate(&i))) {
              if (!x(p))
                  continue;
              if (strcmp(name, p->name) == 0)
                  return (AVCodec*)p;
          }
      
          return NULL;
      }
      
      // 迭代器的方式遍历codec_list
      const AVCodec *av_codec_iterate(void **opaque)
      {
          uintptr_t i = (uintptr_t)*opaque;
          const AVCodec *c = codec_list[i];
      
          ff_thread_once(&av_codec_static_init, av_codec_init_static);
      
          if (c)
              *opaque = (void*)(i + 1);
      
          return c;
      }
      

    libavcodec/allcodecs.c

    /**
     * @file
     * Provide registration of all codecs, parsers and bitstream filters for libavcodec.
     */
    extern AVCodec ff_a64multi_encoder;
    extern AVCodec ff_a64multi5_encoder;
    extern AVCodec ff_aasc_decoder;
    extern AVCodec ff_aic_decoder;
    extern AVCodec ff_alias_pix_encoder;
    extern AVCodec ff_alias_pix_decoder;
    extern AVCodec ff_agm_decoder;
    extern AVCodec ff_amv_encoder;
    extern AVCodec ff_amv_decoder;
    extern AVCodec ff_anm_decoder;
    extern AVCodec ff_ansi_decoder;
    extern AVCodec ff_apng_encoder;
    extern AVCodec ff_apng_decoder;
    ...
    

    本文来自博客园,作者:faithlocus,转载请注明原文链接:https://www.cnblogs.com/faithlocus/p/15669872.html

  • 相关阅读:
    [PHP]解决PHP Call to undefined function ldap_connect()
    [Nginx] Nginx配置PHP应用传递PATH_INFO变量
    [PHP]解决PHP Fatal error: Call to undefined function mcrypt_get_iv_size()
    [CentOS] centos下安装最新稳定版nginx
    [CentOS]查看centos的发行版本情况
    [MySQL]创建用户并指定某一数据库权限
    [PHP] 安装memcached扩展
    [http]301和302的区别
    [javascript] 报错SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
    [GO项目]开源免费在线客服系统-真正免费开源-GOFLY0.3.5发布-极简强大Go语言开发WEB网页客服
  • 原文地址:https://www.cnblogs.com/faithlocus/p/15669872.html
Copyright © 2011-2022 走看看