我们将对帧数据做一些处理,比如将每一帧的 图像转为jpg或者bmp或者ppm等格式保存下来。

举例:在ffmpeg-2.8.8文件夹下编写test.c程序

/*
test.c
*/
#include<stdio.h>
#include<libavcodec/avcodec.h>
#include<libavformat/avformat.h>
#include<libswscale/swscale.h> int main(int argc, char *argv[])
{
AVFormatContext *pFormatCtx = NULL;
if (argc < )
{
printf("Please provide a movie file\n");
return -;
} av_register_all();
if (avformat_open_input(&pFormatCtx,argv[], NULL, NULL) != )
{
return -;
}
if (avformat_find_stream_info(pFormatCtx, NULL) < )
{
return -;
} av_dump_format(pFormatCtx, , argv[], );
avformat_close_input(&pFormatCtx);
return ;
}

注册ffmpeg库

av_register_all(); 

这会将所有可用的文件格式和编解码器注册到我们的库中,以便在打开具有相应格式/编解码器的文件时自动使用。 注意,我们只需要 av_register_all()一次,所以在 main()中调用。 如果你喜欢,可以只注册某些文件格式和编解码器,但是这样比较麻烦。

打开文件

AVFormatContext *pFormatCtx = NULL;
if (avformat_open_input(&pFormatCtx,argv[], NULL, NULL) != )
{
return -;
}

我们从第一个参数获取文件名。 此函数读取文件头并将有关文件格式的信息存储在我们给出的 AVFormatContext 结构中。 最后三个参数用于指定文件格式,缓冲区大小和格式选项,但通过将其设置为NULL或0,libavformat将自动检测这些。 此函数只查看头文件,所以接下来我们需要检查文件中的流信息:

if (avformat_find_stream_info(pFormatCtx, NULL) < )

此函数获取有效的数据流,没有就返回 -1。接下来编写一个方便的调试功能,可以显示我们资源的数据信息

av_dump_format(pFormatCtx, , argv[], );    //打印资源信息

makefile如下:

DIR_INC = -I/usr/local/include
DIR_LIB = -L/usr/local/lib LIBS = -lavformat\
-lavcodec\
-lva-x11 \
-lva \
-lxcb-shm \
-lxcb-xfixes \
-lxcb-render \
-lxcb-shape \
-lxcb -lX11 \
-lasound \
-lz \
-lswresample \
-lswscale \
-lavutil \
-lm \
-pthread FLAGS = -Wall -ggdb test : test.c
gcc test.c ${FLAGS} ${DIR_INC} ${DIR_LIB} ${LIBS} -o test .PHONY:clean
clean:
rm test

运行:

最新文章

  1. Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数
  2. 8.7 jquery-dom manipulation
  3. Sublime Text3
  4. C,C++经典笔试题(答案)转自:http://blog.163.com/jianhuali0118@126/blog/static/377499702008230104125229/
  5. linux新内核的时钟机制代码
  6. BASE64,MD5,SHA,HMAC加密與解密算法(java)
  7. 无责任比较thrift vs protocol buffers
  8. Jquery Ajax Get示例
  9. FOJ 1591 —— Coral的烦恼
  10. CSS控制文本在一行内显示,若有多余字符则使用省略号表示
  11. 《你不知道的JavaScript》整理(六)——强制类型转换
  12. Amazon Alexa登录授权(Android)
  13. 解决: Homestead 环境下, yarn install --no-bin-links, NPM run dev, 命令报错
  14. 大家好,又是新的一天。今天给大家带来一些新的知识:选择器的种类和css的三种样式
  15. git pull的理解 以及 git conflict的解决
  16. Python3解析dex文件
  17. Unity shader学习之阴影
  18. cmd 常用操作
  19. Struts2国际化——完整实例代码
  20. TensorFlow从1到2(十)带注意力机制的神经网络机器翻译

热门文章

  1. c# 读取文件目录下的信息
  2. Linux中的RCU的那点事
  3. ubuntu Ifconfig只显示一个lo
  4. Java自学-JDK环境变量配置
  5. JavaScript之变量(声明、解析、作用域)
  6. Fiddler抓本机包
  7. java 不同时间格式转化
  8. MyBatis面试题整理
  9. mysql连接查询:3个数据表操作研究
  10. Oracle数据库中 =:和 :=