ffmpeg1.1.4 实现ffmpeg demo tutorial01。 mark一下其中库的接口更新以及编译问题

1. demo源码 http://dranger.com/ffmpeg/tutorial01.html (由于版本太低会有诸多问题....)

2.首先建立目录ffmpeg,configure and make ffmpeg 源码。

3.由于tutorial01.c对应的ffmpeg的版本有些旧,有些宏定义和API的名字需要修改

  1. #include "avcodec.h"    ---> #include "libavcodec/avcodec.h"   
  2. #include "avformat.h" ---> #include "libavformat/avformat.h"  
  3.   
  4. CODEC_TYPE_VIDEO ---> AVMEDIA_TYPE_VIDEO  
  5.   
  6.   if(av_open_input_file(&pFormatCtx, argv[1], NULL, 0, NULL)!=0)  --->  
  7.   if(avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)!=0)  
  8.   
  9.   dump_format(pFormatCtx, 0, argv[1], 0); ---> av_dump_format(pFormatCtx, 0, argv[1], 0);   
  10.   
  11.   avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, packet.data, packet.size); --->  
  12.   avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); 
还有img_convert 函数的修改:
(1)

出现undefined reference to `img_convert'错误。解决方法:使用下面两个函数代替img_convert(。。。。):

img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
     pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height,
     PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
// other codes
// Convert the image from its native format to RGB
sws_scale(img_convert_ctx, ( const uint8_t* const *)pFrame->data, pFrame->linesize,
      0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);

在#include <stdio.h>下面加上:static struct SwsContext *img_convert_ctx;

以及 include swscale 库。

(2)对tutorial01.c增加一下内容

  1. #include "libswscale/swscale.h"  
  2. #include "libswscale/swscale_internal.h"  
  3. int img_convert(AVPicture *dst, int dst_pix_fmt,  
  4.                 const AVPicture *src, int src_pix_fmt,  
  5.                 int src_width, int src_height)  
  6. {  
  7.     int w;  
  8.     int h;  
  9.     SwsContext *pSwsCtx;  
  10.   
  11.     w = src_width;  
  12.     h = src_height;  
  13.     pSwsCtx = sws_getContext(w, h, src_pix_fmt,  
  14.                             w, h, dst_pix_fmt,  
  15.                             SWS_BICUBIC, NULL, NULL, NULL);  
  16.   
  17.     sws_scale(pSwsCtx, src->data, src->linesize,  
  18.             0, h, dst->data, dst->linesize);  
  19.   
  20.     //这里释放掉pSwsCtx的内存  
  21.   
  22.   
  23.     return 0;  
  24. }  
  25.   
  26.    
         上面是用新版的API接口重写了img_convert函数。另外,由于用到了libswscale库,必须在编译命令里加 -lswscale。

      gcc -o tutorial01 tutorial01.c -lavutil -lavformat -lavcodec -lz -lavutil -lswscale  -lm

4. 编译报错:

  1. /home/liaowm/workspace/iPlayer/jni/ffmpeg/libavformat/udp.c:657: undefined reference to `pthread_cancel'  
  2. /home/liaowm/workspace/iPlayer/jni/ffmpeg/libavformat/udp.c:658: undefined reference to `pthread_join'  
  3. /usr/local/lib/libavformat.a(udp.o): In function `udp_open':  
  4. /home/liaowm/workspace/iPlayer/jni/ffmpeg/libavformat/udp.c:545: undefined reference to `pthread_create'  
  5. /usr/local/lib/libavcodec.a(pthread.o): In function `frame_thread_free':  
  6. /home/liaowm/workspace/iPlayer/jni/ffmpeg/libavcodec/pthread.c:756: undefined reference to `pthread_join'  
  7. /usr/local/lib/libavcodec.a(pthread.o): In function `thread_free':  
  8. /home/liaowm/workspace/iPlayer/jni/ffmpeg/libavcodec/pthread.c:251: undefined reference to `pthread_join'  
  9. /usr/local/lib/libavcodec.a(pthread.o): In function `frame_thread_init':  
  10. /home/liaowm/workspace/iPlayer/jni/ffmpeg/libavcodec/pthread.c:873: undefined reference to `pthread_create'  
  11. /usr/local/lib/libavcodec.a(pthread.o): In function `thread_init':  
  12. /home/liaowm/workspace/iPlayer/jni/ffmpeg/libavcodec/pthread.c:339: undefined reference to `pthread_create'
是由于没有链接到pthread相关的库造成的,因此,再次修改编译命令,增加 -lpthread。

5.编译错误undefined reference to `BZ2_bzDecompressInit'等错误,还要加上-lbz2库。

最终:  gcc -o tutorial01 tutorial01.c -lavutil -lavformat -lavcodec -lz -lavutil -lswscale -lpthread -lbz2 -lm

编译通过。

6.执行 ./tutorial01  filename。

7.可能会出现“段错误”的问题,调试发现问题出现在format_open_input()函数。(参照源码中format_open_input()函数,可能需要初始化指针。)

8 bingo!

SDL(http://www.libsdl.org/download-1.2.php)的源码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值