Ubuntu 16.04.3下FFmpeg編譯與開發環境搭建測試程序

測試環境 ffmpeg 安裝成功與否的例子:

  1. #include <stdio.h>
  2. #include <libavformat/avformat.h>
  3. #include <libswscale/swscale.h>
  4. #include <libavfilter/avfilter.h>
  5. #define dbmsgc(fmt, args ...) printf("cong:%s[%d]: "fmt"\n", __FUNCTION__, __LINE__,##args)
  6. //#define dbmsg(fmt, args ...) printf("cong:%s:%s[%d]: "fmt"\n",__FILE__, __FUNCTION__, __LINE__,##args)
  7. int main(int argc, char **argv)
  8. {
  9. int i=0;
  10. AVFormatContext *pFormatCtx = NULL;
  11. avcodec_register_all();
  12. #if CONFIG_AVDEVICE
  13. avdevice_register_all();
  14. #endif
  15. avfilter_register_all();
  16. av_register_all();
  17. if(avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)!=0)
  18. return -1; // Couldn't open file
  19. if(avformat_find_stream_info(pFormatCtx, NULL)<0)
  20. return -1; // Couldn't find stream inform
  21. av_dump_format(pFormatCtx,0, 0, 0);
  22. return 0;
  23. }
6..編寫Makefile
  1. FFMPEG=/usr/local/ffmpeg
  2. CC=gcc
  3. CFLAGS=-g -I$(FFMPEG)/include
  4. LDFLAGS = -L$(FFMPEG)/lib/ -lswscale -lswresample -lavformat -lavdevice -lavcodec -lavutil -lavfilter -lm
  5. TARGETS=test
  6. all: $(TARGETS)
  7. test:test.c
  8. $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -std=c++11 #注意這裏的-std=c++11
  9. clean:
  10. rm -rf $(TARGETS)

7.make

8../test
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章