FFmpeg:打印音/视频信息(Meta信息)

多媒体文件基本概念

  1. 多媒体文件其实是个容器
  2. 在容器里面有很多流(Stream/Track)
  3. 每种流是由不同的编码器编码的
  4. 从流中读出的数据称为包
  5. 在一个包中包含着一个或多个帧

几个重要的结构体

  1. AVFormatContext
  2. AVStream
  3. AVPacket

FFmpeg操作流数据的基本步骤

打印音/视频信息(Meta信息)

  1. av_register_all() 
  2. avformat_open_input()/avformat_close_input()
  3. av_dump_format() :打印音视频的meta信息

具体来看一下 demo:

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

int main(int argc,char* argv[])
{
    int ret;
    AVFormatContext* fmt_ctx = NULL;

    av_log_set_level(AV_LOG_INFO);

    av_register_all();

    ret = avformat_open_input(&fmt_ctx,"./test.mp4",NULL,NULL);
    if(ret < 0)
    {
        av_log(NULL,AV_LOG_ERROR,"Can not open file: %s\n",av_err2str(ret));
        return -1;
    }

    av_dump_format(fmt_ctx,0,"./test.mp4",0);

    avformat_close_input(&fmt_ctx);

    return 0;
}

编译输出:

wj@ubuntu:~/FFmpeg$ gcc -g -o mediainfo mediainfo.c -lavformat -lavutil
mediainfo.c: In function ‘main’:
mediainfo.c:12:5: warning: implicit declaration of function ‘av_register_all’ [-Wimplicit-function-declaration]
   12 |     av_register_all();
      |     ^~~~~~~~~~~~~~~
wj@ubuntu:~/FFmpeg$ ./mediainfo
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './test.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: isommp423gp5
    creation_time   : 2018-11-02T07:56:26.000000Z
    encoder         : FormatFactory : www.pcfreetime.com
  Duration: 00:05:26.05, bitrate: N/A
    Stream #0:0(und): Video: mpeg4 (mp4v / 0x7634706D), none, 151 kb/s, SAR 1:1 DAR 0:0, 14.90 fps, 14.90 tbr, 14898 tbn (default)
    Metadata:
      creation_time   : 2018-11-02T07:56:26.000000Z
      handler_name    : video
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, 2 channels, 125 kb/s (default)
    Metadata:
      creation_time   : 2018-11-02T07:56:26.000000Z
      handler_name    : sound
    Stream #0:2(und): Data: none (mp4s / 0x7334706D), 0 kb/s (default)
    Metadata:
      creation_time   : 2018-11-02T07:56:26.000000Z
      handler_name    : GPAC MPEG-4 OD Handler
    Stream #0:3(und): Data: none (mp4s / 0x7334706D), 0 kb/s (default)
    Metadata:
      creation_time   : 2018-11-02T07:56:26.000000Z
      handler_name    : GPAC MPEG-4 Scene Description Handler

猜你喜欢

转载自blog.csdn.net/weixin_42136255/article/details/133561038
今日推荐