多媒体文件基本概念
- 多媒体文件其实是个容器
- 在容器里面有很多流(Stream/Track)
- 每种流是由不同的编码器编码的
- 从流中读出的数据称为包
- 在一个包中包含着一个或多个帧
几个重要的结构体
- AVFormatContext
- AVStream
- AVPacket
FFmpeg操作流数据的基本步骤
打印音/视频信息(Meta信息)
- av_register_all()
- avformat_open_input()/avformat_close_input()
- 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 : mp42minor_version : 1compatible_brands: isommp423gp5creation_time : 2018-11-02T07:56:26.000000Zencoder : FormatFactory : www.pcfreetime.comDuration: 00:05:26.05, bitrate: N/AStream #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.000000Zhandler_name : videoStream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, 2 channels, 125 kb/s (default)Metadata:creation_time : 2018-11-02T07:56:26.000000Zhandler_name : soundStream #0:2(und): Data: none (mp4s / 0x7334706D), 0 kb/s (default)Metadata:creation_time : 2018-11-02T07:56:26.000000Zhandler_name : GPAC MPEG-4 OD HandlerStream #0:3(und): Data: none (mp4s / 0x7334706D), 0 kb/s (default)Metadata:creation_time : 2018-11-02T07:56:26.000000Zhandler_name : GPAC MPEG-4 Scene Description Handler