您的位置:首页 > 运维架构 > Linux

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

2016-07-13 10:17 801 查看
编译命令: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 

*/  

#include "stdio.h"  

#include "stdlib.h"  

  

  

#include "libavformat/avformat.h"  

#include "libavdevice/avdevice.h"  

#include "libswresample/swresample.h"  

#include "libavutil/opt.h"  

#include "libavutil/channel_layout.h"  

#include "libavutil/parseutils.h"  

#include "libavutil/samplefmt.h"  

#include "libavutil/fifo.h"  

#include "libavutil/intreadwrite.h"  

#include "libavutil/dict.h"  

#include "libavutil/mathematics.h"  

#include "libavutil/pixdesc.h"  

#include "libavutil/avstring.h"  

#include "libavutil/imgutils.h"  

#include "libavutil/timestamp.h"  

#include "libavutil/bprint.h"  

#include "libavutil/time.h"  

#include "libavutil/threadmessage.h"  

#include "/usr/local/ffmpeg_arm/include/SDL/SDL.h"  

  

#include "libavfilter/avcodec.h"  

#include "libavcodec/avcodec.h"  

  

#if HAVE_SYS_RESOURCE_H  

#include <sys/time.h>  

#include <sys/types.h>  

#include <sys/resource.h>  

#elif HAVE_GETPROCESSTIMES  

#include <windows.h>  

#endif  

#if HAVE_GETPROCESSMEMORYINFO  

#include <windows.h>  

#include <psapi.h>  

#endif  
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
 int w = 720;  

        int h = 576,retu;  

        SDL_Rect rect;  

    av_register_all();  

  

    AVFrame *pFrame_ = NULL;  

  

    /* find the video encoder */  

    AVCodec *videoCodec = avcodec_find_decoder(CODEC_ID_H264);//得到264的解码器类  

    if(!videoCodec)  

    {  

        printf("avcodec_find_decoder error\n");  

        return -1;  

    }  

  

    AVCodecParserContext *avParserContext = av_parser_init(CODEC_ID_H264);//得到解析帧类,主要用于后面的帧头查找  

    if(!avParserContext)  

    {  

        printf("av_parser_init  error\n");  

        return -1;  

    }  

    AVCodecContext *codec_ = avcodec_alloc_context3(videoCodec);//解码会话层  

    if(!codec_)  

    {  

        printf("avcodec_alloc_context3  error\n");  

        return -1;  

    }  

  

  

    //初始化参数,下面的参数应该由具体的业务决定  

    codec_->time_base.num = 1;  

    codec_->frame_number = 1; //每包一个视频帧  

    codec_->codec_type = AVMEDIA_TYPE_VIDEO;  

    codec_->bit_rate = 0;  

    codec_->time_base.den = 25;//帧率  

    codec_->width = 720;//视频宽  

    codec_->height = 576;//视频高  

  

    if(avcodec_open2(codec_, videoCodec, NULL) >= 0)//打开解码器  

    {  
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
AVPacket packet = {0};  

    int dwBufsize = 10;  

    int frameFinished = dwBufsize;//这个是随便填入数字,没什么作用  

  

    av_init_packet(&packet);  

    packet.data = NULL;//这里填入一个指向完整H264数据帧的指针  

    packet.size = 0;//这个填入H264数据帧的大小  

  

    FILE *myH264 = fopen("1.264", "rb");//解码的文件264  

    if(myH264 == NULL)  

    {  

        perror("cant open 264 file\n");  

        return -1;  

    }  

  

    FILE *yuvfile = fopen("my264.yuv", "wb");//成功解码后保存成的YUV文件, 可以用YUV工具打开浏览  

    if(yuvfile == NULL)  

    {  

        perror("cant open YUV file\n");  

        return -1;  

    }  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  嵌入式 io 文档