获取mediainfo

首先调用av_register_all将所有的编码器和解码器注册好

来看下具体的注册实现

void av_register_all(void)
{ff_thread_once(&av_format_next_init, av_format_init_next);
}
// 看下av_format_init_next的实现
// 可以看到函数内部是实现了将编码器和解码器使用指针进行串联的操作
// 如果有输出或者输入列表,将输出或输入列表也进行串联
static void av_format_init_next(void)
{AVOutputFormat *prevout = NULL, *out;AVInputFormat *previn = NULL, *in;ff_mutex_lock(&avpriv_register_devices_mutex);// 编码器串联for (int i = 0; (out = (AVOutputFormat*)muxer_list[i]); i++) {if (prevout)prevout->next = out;prevout = out;}//实现输出列表的串联if (outdev_list) {for (int i = 0; (out = (AVOutputFormat*)outdev_list[i]); i++) {if (prevout)prevout->next = out;prevout = out;}}//实现解码器的串联for (int i = 0; (in = (AVInputFormat*)demuxer_list[i]); i++) {if (previn)previn->next = in;previn = in;}//实现输入列表的串联if (indev_list) {for (int i = 0; (in = (AVInputFormat*)indev_list[i]); i++) {if (previn)previn->next = in;previn = in;}}ff_mutex_unlock(&avpriv_register_devices_mutex);
}

调用avformat_open_input

调用 avformat_open_input根据输入的音视频内容构造 AVFormatContext结构体,函数功能如下:

/**打开一个流,并读取头部信息* Open an input stream and read the header. The codecs are not opened.* The stream must be closed with avformat_close_input().*  ps可以用户提供,如果为NULL该函数会进行内存申请* @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).*           May be a pointer to NULL, in which case an AVFormatContext is allocated by this*           function and written into ps.*           Note that a user-supplied AVFormatContext will be freed on failure.指向要打开的多媒体文件* @param url URL of the stream to open.不指定,使用自动侦测* @param fmt If non-NULL, this parameter forces a specific input format.*            Otherwise the format is autodetected.* @param options  A dictionary filled with AVFormatContext and demuxer-private options.*                 On return this parameter will be destroyed and replaced with a dict containing*                 options that were not found. May be NULL.** @return 0 on success, a negative AVERROR on failure.** @note If you want to use custom IO, preallocate the format context and set its pb field.*/
int avformat_open_input(AVFormatContext **ps, const char *url, ff_const59 AVInputFormat *fmt, AVDictionary **options);

调用av_dump_format打印文件信息

/*** Print detailed information about the input or output format, such as* duration, bitrate, streams, container, programs, metadata, side data,* codec and time base.** @param ic        the context to analyze* @param index     index of the stream to dump information about* @param url       the URL to print, such as source or destination file* @param is_output Select whether the specified context is an input(0) or output(1)*/
void av_dump_format(AVFormatContext *ic,int index,const char *url,int is_output);

调用av_dump_format(pFmtCtx, 0, pSrcName, 0);实现对基本信息的打印,这里为了方便观看,可以自己实现一个函数,对多媒体数据进行打印。

这为了更好理解媒体信息记录的格式,自己实现了一个简单的打印接口,仅用于参考

//
// Created by andrew on 2020/11/8.
//#include <iostream>
#include <string>
extern "C" {#include <libavformat/avformat.h>
#include <libavutil/log.h>
#include <libavutil/dict.h>
}
using namespace std;// 声明一下 因为原函数是在.c中声明的结构体
struct AVDictionary {int count;AVDictionaryEntry *elems;
};// 打印媒体信息的简单示例
void my_av_input_dump_format(AVFormatContext *ic, int index,const char *url, int is_output){string pSrt = (is_output != 0) ? "output":"input";cout << "音视频输入输出类型:" << pSrt <<endl;cout << "index = " << index << endl;if(is_output){cout << "fromat name:" << ic->oformat->name << endl;}elsecout << "fromat name:" << ic->iformat->name << endl;// urlcout << "from :" << url << endl;//ic->metadataint i = 0;i =  ic->metadata->count;for (i = 0; i < ic->metadata->count; i++){cout << "    " <<ic->metadata->elems[i].key << ":" <<ic->metadata->elems[i].value << endl;}
}int main(int argc, char *argv[]){//    设置日志等级av_log_set_level(AV_LOG_DEBUG);if(argc< 2){av_log(NULL, AV_LOG_ERROR, "you should input media file!\n");return -1;}
//    所有获取音视频信息都要首先注册av_register_all();int errCode = -1;AVFormatContext *pFmtCtx = NULL;const char *pSrcName = argv[1];if((errCode = avformat_open_input(&pFmtCtx, pSrcName, NULL, NULL)) < 0){av_log(NULL, AV_LOG_ERROR, "avformat open input failed.\n");exit(1);}//官方接口
//    av_dump_format(pFmtCtx, 0, pSrcName, 0);my_av_input_dump_format(pFmtCtx, 0, pSrcName, 0);//释放资源avformat_close_input(&pFmtCtx);return 0;
}

执行输出结果:

音视频输入输出类型:input
index = 0
fromat name:mov,mp4,m4a,3gp,3g2,mj2
from :/work/test/test.mp4major_brand:isomminor_version:512compatible_brands:isomiso2avc1mp41track:0artist:段奥娟album:comment:163 key(Don't modify):ZWxeTBkln0EQUjdDVUZQXrJzMh33POt0FgWTvjgge2X8BzXmyZaXb9C8+H2VGrdLG7XRTMrkXzzfV9VNH7sp0KlFimbjkVbsWksXY5YrzqFNXeJX1gvrBWCV+m3aYddkvy0HxucdcxCoCrYsrnzxL97sgxi0M2VHh6PREC3j6Uz4hfWkIMGhul9aszAuzEvbUUIQXSZRHgpkVW3g3oTEwqY5CexOWMIgIZAjlFIMxafAnGU8ujxA+ufq/l/r+dQMW9OmRQVt2n4Gz1t83TrPZg==title:元気满分encoder:Lavf57.71.100
[AVIOContext @ 0x55bf28f2d080] Statistics: 200364 bytes read, 0 seeks
libgcov profiling error:/work/ffmpeg_doc/cmake-build-debug-coverage/src/CMakeFiles/ffmpeg_mediainfo.dir/ffmpeg_avformat/ffmpeg_mediainfo.cpp.gcda:overwriting an existing profile data with a different timestamp

FFmpeg中实现对多媒体信息的获取与打印av_dump_format相关推荐

  1. ffmpeg中获取mv/mb_type/dct_coeff/qp和MBSize等数据(H.264)

    ffmpeg是一个很复杂的库,在我看来,比JM要复杂很多,刨除其包含各种编解码方案,算法的全面性,以及其各种平台的汇编优化等因素,其运行逻辑结构和函数之间的调用关系等都要复杂很多.今天我们不泛泛而谈, ...

  2. Android多媒体信息获取

    Android多媒体涉及视频.音频.图片,首先有几个概念: 1.Android中所有的多媒体文件除了存储在物理硬盘上,还会将文件信息(路径.id.类型.)保存到数据库中,这样当我们想要获取这些文件的信 ...

  3. Qt使用QMediaPlayer类获取多媒体信息

    Qt自带的库中能达到获取多媒体信息效果的看来看去好像只有QMediaPlayer能达到这个效果,虽然看起来有些笨. void Player::OnMetaDataAvailableChanged(bo ...

  4. Android平台Chromium net中的代理配置信息获取

    在计算机网络中,代理服务器 扮演着发起请求的客户端与服务器之间的中间人的角色.客户端连接到代理服务器,请求一些服务,比如文件,网页,或其它可以从服务器获得的资源,代理服务器以简化和控制复杂度的形式获取 ...

  5. kafka java获取topic_通过编程方式获取Kafka中Topic的Metadata信息

    如果我们需要通过编程的方式来获取到TopicMetadataRequest请求到 def findLeader(topic: String): Unit = { val consumer = conn ...

  6. C#中通过WMI的Win32_DiskDrive对象获取磁盘驱动器信息简介

    1.简介 在WMI中,通过Win32_DiskDrive对象可以获取磁盘驱动器的相关信息: ManagementClass mc = new ManagementClass("Win32_D ...

  7. php执行who命令,Linux_在Linux系统中使用who和whoami命令获取用户信息,who用法:who [选项]... [ 文件 | - phpStudy...

    在Linux系统中使用who和whoami命令获取用户信息 who用法:who [选项]... [ 文件 | 参数1 参数2 ] 显示当前已登录的用户信息. -a, --all             ...

  8. JAVA核心知识点--HttpClient获取302响应中的Location头信息

    HttpClient获取302响应中的Location头信息 public static String getLocationUrl(String url) {RequestConfig config ...

  9. 魔方APP项目-07-客户端提交登录信息、在APICloud中集成防水墙验证码,前端获取显示并校验验证码、服务端校验验证码、保存用户登录状态,APICloud提供的数据存储、客户端保存用户登陆数据

    用户登录 一.客户端提交登录信息 html/login.html,代码: <!DOCTYPE html> <html> <head><title>登录& ...

最新文章

  1. 正则表达式(括号)、[中括号]、{大括号}的区别小结
  2. stm32的rxne和idle中断_HAL库的STM32F767的DMA通过IDLE中断接收数据但不能访问
  3. linux tomcat 安装教程,关于Linux下配置安装Tomcat8的步骤
  4. @计算机专业大学生,毕业后如何明确自己的职业方向,该走那条路?
  5. Go 标准库: log
  6. Catalyst 5.8: the Perl MVC Framework
  7. zabbix的邮件报警
  8. CAJ如何转成PDF
  9. 【附PDF下载】2021年上半年信息系统项目管理师上午综合知识真题
  10. 省级面板数据(2000-2019)十一:农业(固定资产+农产品产量、播种面积)(stata版)
  11. Stata: 断点回归(RDD)中的近似置换检验和伴随次序统计简介
  12. ftl不存在为真_判断一件书法作品是否具备收藏价值可以归纳为四个字:真、优、高、古。...
  13. python文件批量改名
  14. 空气净化器的研究概况
  15. 加入域时“找不到网络路径”的解决办法
  16. Hexo博客安装卡在“INFO install dependencies”解决方法
  17. 利用CSS实现渐变色边框
  18. Learning a Discriminative Feature Network for Semantic Segmentation
  19. Gooou高尔夫管理系统
  20. python计算圆柱的体积_圆柱与球相交体体积计算及扩展问题

热门文章

  1. PLinq Lookup ParallelQuery
  2. 爱晚红枫的博客配色----绿野仙踪
  3. strcat()的实现
  4. NYOJ 762 第k个互质数(二分 + 容斥)
  5. Golang之理解错误输出
  6. Jquery----实现抽奖效果(根据姓名抽奖)
  7. 重装JDK后Tomcat和Eclipse的配置
  8. 【linux】虚拟机安装centos后ping ip地址出现错误:Network is unreachable
  9. C++用法的学习心得
  10. 关于Unity游戏开发方向找工作方面的一些个人看法