经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » C 语言 » 查看文章
FFmpeg 开发环境搭建及第一个程序 Hello FFmpeg 编写
来源:cnblogs  作者:静影沉璧  时间:2019/4/24 11:56:24  对本文有异议

1. FFmpeg 的安装

  1. ./configure
  2. make
  3. make install

默认会将 FFmpeg 安装至 /usr/local 目录下(可通过 configure 使用 “-prefix=目录” 修改安装目录),
安装完成后分别会在 /usr/local 下的 bin、include、lib、share 四个目录下生成 FFmpeg 的二进制可执行文件、头文件、编译链接库、文档。
后面开发我们会用到 include、lib 里的头文件和编译链接库。

2. FFmpeg 版 Hello world

  1. //testFFmpeg.c
  2. #include <stdio.h>
  3. #include <libavcodec/avcodec.h>
  4. #include <libavformat/avformat.h>
  5. int main(int argc, char *argv[])
  6. {
  7. printf("hello FFmpeg\n");
  8. AVFormatContext *pFormatCtx = avformat_alloc_context();
  9. if (avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)) {
  10. fprintf(stderr, "open input failed\n");
  11. return -1;
  12. }
  13. if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
  14. fprintf(stderr, "find stream info failed\n");
  15. return -1;
  16. }
  17. int videoStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
  18. printf("nb:%d, url:%s, time:%ld, duration:%ld, bitRate:%ld, videoStream:%d\n",
  19. pFormatCtx->nb_streams, pFormatCtx->url, pFormatCtx->start_time, pFormatCtx->duration,
  20. pFormatCtx->bit_rate, videoStream);
  21. return 0;
  22. }

3. Makefile 编写

  1. all:helloFF
  2. CC=gcc
  3. CLIBSFLAGS=-lavformat -lavcodec -lavutil -lswresample -lz -llzma -lpthread -lm
  4. FFMPEG=/usr/local
  5. CFLAGS=-I$(FFMPEG)/include/
  6. LDFLAGS = -L$(FFMPEG)/lib/
  7. helloFF:helloFF.o
  8. $(CC) -o helloFF helloFF.o $(CLIBSFLAGS) $(CFLAGS) $(LDFLAGS)
  9. helloFF.o:test.c
  10. $(CC) -o helloFF.o -c test.c $(CLIBSFLAGS) $(CFLAGS) $(LDFLAGS)
  11. clean:
  12. rm helloFF helloFF.o

FFmpeg 版本

  1. [ubuntu@ubuntu-virtual-machine testFFmpeg]$ ffmpeg -version
  2. ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
  3. built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
  4. configuration:
  5. libavutil 56. 22.100 / 56. 22.100
  6. libavcodec 58. 35.100 / 58. 35.100
  7. libavformat 58. 20.100 / 58. 20.100
  8. libavdevice 58. 5.100 / 58. 5.100
  9. libavfilter 7. 40.101 / 7. 40.101
  10. libswscale 5. 3.100 / 5. 3.100
  11. libswresample 3. 3.100 / 3. 3.100

原文链接:http://www.cnblogs.com/ichenwin/p/10761084.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号