FFMPEG结构体分析一:AVFormatContext
来源:互联网 发布:pmp考试 知乎 编辑:程序博客网 时间:2024/05/17 13:12
一、概述
关于AVFormatContext的分析已经有一篇文章了,地址如下: http://blog.csdn.net/leixiaohua1020/article/details/14214705。这里仅仅做一些文字上的补充和贴一段示例代码。
二、主要内容
AVFormatContext是FFMPEG解封装(flv,mp4,rmvb,avi)功能的结构体,重要的变量如下:
struct AVInputFormat *iformat:输入数据的封装格式
AVIOContext *pb:输入数据的缓存
unsigned int nb_streams:视音频流的个数
AVStream **streams:视音频流
char filename[1024]:文件名
int64_t duration:时长(单位:微秒ms,转换为秒需要除以1000000)
int bit_rate:比特率(单位bps,转换为kbps需要除以1000)
AVDictionary *metadata:元数据
关于AVFormatContext的使用示例:
#include <stdio.h>//包含库extern "C"{#include "libavcodec/avcodec.h"#include "libavformat/avformat.h"#include "libswscale/swscale.h"#include "SDL/SDL.h"};int main(int argc, char* argv[]){//FFmpeg相关变量AVFormatContext*pFormatCtx;//AVFormatContext主要存储视音频封装格式中包含的信息char* filepath = "1.mp4";//文件路径av_register_all();//初始化libformat库和一些别的工作pFormatCtx = avformat_alloc_context();//分配formatcontext所需内存if (avformat_open_input(&pFormatCtx, filepath, NULL, NULL) != 0){printf("Couldn't open input stream.\n");return -1;}printf("文件名: %s \n", pFormatCtx->filename);//文件名printf("流个数: %d \n", pFormatCtx->nb_streams);//视频流、音频流个数printf("时长: %d 秒\n", pFormatCtx->duration/1000000);//时长printf("总比特率: %d kbps\n", pFormatCtx->bit_rate);//总比特率,这个时候是0,因为现在还获取不到。if (avformat_find_stream_info(pFormatCtx, NULL)<0){//读取流信息printf("Couldn't find stream information.\n");return -1;}printf("总比特率: %d kbps\n", pFormatCtx->bit_rate/1000);//总比特率,这个时候可以获取了。avformat_close_input(&pFormatCtx);//关闭输入return 0;}运行结果:
左边是代码运行的结果,右边是1.MP4文件的详细信息。
0 0
- FFMPEG结构体分析一:AVFormatContext
- FFMPEG结构体分析:AVFormatContext
- FFMPEG结构体分析:AVFormatContext
- FFMPEG结构体分析:AVFormatContext
- FFMPEG结构体分析:AVFormatContext
- FFMPEG结构体分析 AVFormatContext
- FFMPEG结构体分析:AVFormatContext
- FFMPEG结构体分析:AVFormatContext
- FFMPEG结构体分析:AVFormatContext
- FFMPEG结构体分析:AVFormatContext
- FFMPEG结构体分析:AVFormatContext
- FFMPeg代码分析:AVFormatContext结构体
- FFMPeg代码分析:AVFormatContext结构体
- (13) FFMPEG结构体分析:AVFormatContext
- FFmpeg中结构体AVFormatContext
- ffmpeg之AVFormatContext结构体
- FFMpeg学习笔记 AVFormatContext结构分析
- Ffmpeg结构体——AVFormatContext
- 快速充电技术介绍
- POJ 1159 Palindrome
- AES文件加密解密
- (11)番外篇——发现了牛人的博客,准备追一下
- akka入门-消息派发器
- FFMPEG结构体分析一:AVFormatContext
- Linux重定向
- Oracle通过Job调用存储过程
- phonegap文件,目录操作以及网络上传,下载文件(含demo)
- PullToRefresh原理解析,pulltorefresh解析
- 使用VM sphere client安装虚拟机出现的问题
- ArcGIS教程:确定空间关系
- Java 垃圾回收最容易被误解的7件事
- Simulation Implement strStr()