FFmpeg使用c语言sdk实现打印视频的信息

主要使用函数

ffmpeg中的所有编解码库,网络协议注册到程序里面来:av_register_all()

打开一个多媒体文件:avformat_open_input()

关闭一个多媒体文件:avformat_close_input()

打印meta信息:av_dump_format()

实例

vim meta_info.c

#include <libavutil/log.h>
#include <libavformat/avformat.h>

int main(int argc, char *argv[])
{
  int ret;
  // 文件上下文
  AVFormatContext *fmt_ctx = NUll;
  
  // 初始化logo
  av_log_set_level(AV_LOG_INFO);
  
  // 全局注册ffmpeg的函数
  av_register_all();
  
  // 打开多媒体文件
  ret = avformat_open_input(&fmt_ctx, "./test.mp4", NULL, NULL);
  if (ret < 0){
    av_log(NULL, AV_LOG_ERROR, "找不到文件:%s", av_err2str(ret));
    
    return -1;
  }
  
  // 第一个产生是文件上下文, 第二个参数默认0就可以 , 最后一个代表是输入流还是输出流
  av_dump_format(fmt_ctx, 0, "./test.mp4", 0);
  
  avformat_close_input(&fmt_ctx);
  
  
  return 0;
}

clang -g -o meta_info meta_info.c pkg-config --libs libavformat libavutil

posted @ 2019-12-31 10:57  FANDX  阅读(367)  评论(0编辑  收藏  举报