初学者 ffmpeg + SDL2.0 安装与应用概要点

# ffmpeg - 2.8.6 与 SDL2.* 学习笔记
一、源代码下载和安装 
   1. 利用Git 工具从 https://github.com/kewlbear/FFmpeg-iOS-build-script 下载自动化编译ffmpeg脚本
       a. 可以适当修改 TARGET 版本,如:7.0
       b. 在命令行中执行sh脚本,等待自动化下载ffmpeg 源代码,并编译 IOS 版本的 frameword
       c. 最终将会得到【FFmpeg-iOS】目录,里边为库文件,和头文件
   2. 利用Git 工具从 https://github.com/manifest/sdl-ios-framework.git 下载自动化编译脚本
       a. 事先 安装好 hg、git、svn 这些工具
       b. 安装好 rubygems、colorize(sudo gem install colorize)
       c. 在命令行环境下 进入 【dl-ios-framework】目录,执行rake,则自动编译构建SDL2.frameword


二、ffmpeg 视频解码 简单开始,以及关键流程
包含头文件如下:
#import "libavutil/avutil.h"
#import "libavutil/opt.h"
#import "libavutil/imgutils.h"    //图像工具
#import <libavcodec/avcodec.h>
#import <libavformat/avformat.h>


    1. 新建工程,并将ffmpeg 静态库加入到工程中,引用 include 头文件,注意修改工程配置 头文件搜索目录路径
    CoreMotion,CoreMedia,QuartzCore, MediaPlayer, GameController, OpenGLES, AudioToolBox, AVFoundation, VideoToolBox, libz, libiconv, libbz, Foundation, CoreGraphic, UIKit, MobileCoreService, ImageIO


    2. 定义 ffmpeg av解码上下文变量,示例代码如下:
        AVFormatContext *pFormatCtx = NULL; // 视频文件上下文
    AVCodecContext  *pCodecCtx = NULL;  // 视频解码器上下文
    AVCodec         *pCodec = NULL;     // 视频解码器结构
    int              videoStream;       // 视频流索引


    3. 注册所有视频格式和解码器
        av_register_all();


    4. 打开本地视频文件
        if(avformat_open_input(&pFormatCtx, "视频文件全路径", NULL, NULL)!=0)
        return -1; // Couldn't open file


    5. 检索视频流信息
    if(avformat_find_stream_info(pFormatCtx, NULL)<0)
        return -1; // Couldn't find stream information


    6. 打印视频流信息(可有可无)
        av_dump_format(pFormatCtx, 0, "视频文件全路径", 0);


    7. 查找视频流索引位置
    for(int index = 0; index < pFormatCtx->nb_streams; index++)
        if( pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
            videoStream = i; // 找到视频流索引位置
            break;
        }


    8. 获取视频解码上下文环境
    pCodecCtx = pFormatCtx->streams[videoStream]->codec;


    9. 获取视频解码器结构
    pCodec=avcodec_find_decoder(pCodecCtx->codec_id);


    10. 初始化视频解码帧结构和显示帧结构
    AVFrame * pDecodecFrame = av_frame_alloc();
    AVFrame * pDisplayFrame = av_frame_alloc();


    11. 初始化视频帧图像缩放上下文环境(网上的资料比较老,PIX_FMT_YUV420P 在新版ffmpeg中为 AV_PIX_FMT_YUV420P)
    SwsContext * pSwsContext = sws_getContext (
      pCodecCtx->width,
      pCodecCtx->height,
      pCodecCtx->pix_fmt,
      pCodecCtx->width,
      pCodecCtx->height,
      AV_PIX_FMT_YUV420P,
      SWS_BILINEAR,
     
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值