嵌入式linux------ffmpeg移植 解码H264(am335x解码H264到yuv420并通过SDL显示)

  1. 编译命令:arm-linux-gcc -o show2642 264showyuv2.c -I/usr/local/ffmpeg_arm/include/   -L/usr/local/ffmpeg_arm/lib/ -lswresample -lavformat -lavutil -lavcodec -lswscale -lx264   libSDL.a 
  2. */  
  3. #include "stdio.h"  
  4. #include "stdlib.h"  
  5.   
  6.   
  7. #include "libavformat/avformat.h"  
  8. #include "libavdevice/avdevice.h"  
  9. #include "libswresample/swresample.h"  
  10. #include "libavutil/opt.h"  
  11. #include "libavutil/channel_layout.h"  
  12. #include "libavutil/parseutils.h"  
  13. #include "libavutil/samplefmt.h"  
  14. #include "libavutil/fifo.h"  
  15. #include "libavutil/intreadwrite.h"  
  16. #include "libavutil/dict.h"  
  17. #include "libavutil/mathematics.h"  
  18. #include "libavutil/pixdesc.h"  
  19. #include "libavutil/avstring.h"  
  20. #include "libavutil/imgutils.h"  
  21. #include "libavutil/timestamp.h"  
  22. #include "libavutil/bprint.h"  
  23. #include "libavutil/time.h"  
  24. #include "libavutil/threadmessage.h"  
  25. #include "/usr/local/ffmpeg_arm/include/SDL/SDL.h"  
  26.   
  27. #include "libavfilter/avcodec.h"  
  28. #include "libavcodec/avcodec.h"  
  29.   
  30. #if HAVE_SYS_RESOURCE_H  
  31. #include <sys/time.h>  
  32. #include <sys/types.h>  
  33. #include <sys/resource.h>  
  34. #elif HAVE_GETPROCESSTIMES  
  35. #include <windows.h>  
  36. #endif  
  37. #if HAVE_GETPROCESSMEMORYINFO  
  38. #include <windows.h>  
  39. #include <psapi.h>  

  1. #endif  
  2. http://blog.sina.com.cn/s/blog_163f91c5e0102wnyx.html 


    http://blog.sina.com.cn/s/blog_14d8952290102wii0.html


    http://blog.sina.com.cn/s/blog_15e1433c30102wd1v.html


    http://blog.sina.com.cn/s/blog_15e1433c30102wd1x.html
    http://blog.sina.com.cn/s/blog_14d8952290102wii4.html
    http://blog.sina.com.cn/s/blog_15e1433c30102wd20.html
    http://tieba.baidu.com/p/4665234070
    http://tieba.baidu.com/p/4667230793
    http://tieba.baidu.com/p/4667235501
    1.  int w = 720;  
    2.         int h = 576,retu;  
    3.         SDL_Rect rect;  
    4.     av_register_all();  
    5.   
    6.     AVFrame *pFrame_ = NULL;  
    7.   
    8.     /* find the video encoder */  
    9.     AVCodec *videoCodec = avcodec_find_decoder(CODEC_ID_H264);//得到264的解码器类  
    10.     if(!videoCodec)  
    11.     {  
    12.         printf("avcodec_find_decoder error\n");  
    13.         return -1;  
    14.     }  
    15.   
    16.     AVCodecParserContext *avParserContext = av_parser_init(CODEC_ID_H264);//得到解析帧类,主要用于后面的帧头查找  
    17.     if(!avParserContext)  
    18.     {  
    19.         printf("av_parser_init  error\n");  
    20.         return -1;  
    21.     }  
    22.     AVCodecContext *codec_ = avcodec_alloc_context3(videoCodec);//解码会话层  
    23.     if(!codec_)  
    24.     {  
    25.         printf("avcodec_alloc_context3  error\n");  
    26.         return -1;  
    27.     }  
    28.   
    29.   
    30.     //初始化参数,下面的参数应该由具体的业务决定  
    31.     codec_->time_base.num = 1;  
    32.     codec_->frame_number = 1; //每包一个视频帧  
    33.     codec_->codec_type = AVMEDIA_TYPE_VIDEO;  
    34.     codec_->bit_rate = 0;  
    35.     codec_->time_base.den = 25;//帧率  
    36.     codec_->width = 720;//视频宽  
    37.     codec_->height = 576;//视频高  
    38.   
    39.     if(avcodec_open2(codec_, videoCodec, NULL) >= 0)//打开解码器  
    40.     {  
    http://blog.sina.com.cn/s/blog_163f91c5e0102wnyx.html 


    http://blog.sina.com.cn/s/blog_14d8952290102wii0.html


    http://blog.sina.com.cn/s/blog_15e1433c30102wd1v.html


    http://blog.sina.com.cn/s/blog_15e1433c30102wd1x.html
    http://blog.sina.com.cn/s/blog_14d8952290102wii4.html
    http://blog.sina.com.cn/s/blog_15e1433c30102wd20.html
    http://tieba.baidu.com/p/4665234070
    http://tieba.baidu.com/p/4667230793
    http://tieba.baidu.com/p/4667235501
    1. AVPacket packet = {0};  
    2.     int dwBufsize = 10;  
    3.     int frameFinished = dwBufsize;//这个是随便填入数字,没什么作用  
    4.   
    5.     av_init_packet(&packet);  
    6.     packet.data = NULL;//这里填入一个指向完整H264数据帧的指针  
    7.     packet.size = 0;//这个填入H264数据帧的大小  
    8.   
    9.     FILE *myH264 = fopen("1.264""rb");//解码的文件264  
    10.     if(myH264 == NULL)  
    11.     {  
    12.         perror("cant open 264 file\n");  
    13.         return -1;  
    14.     }  
    15.   
    16.     FILE *yuvfile = fopen("my264.yuv""wb");//成功解码后保存成的YUV文件, 可以用YUV工具打开浏览  
    17.     if(yuvfile == NULL)  
    18.     {  
    19.         perror("cant open YUV file\n");  
    20.         return -1;  
    21.     }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值