码迷,mamicode.com
首页 > 移动开发 > 详细

IOS 视频缩略图的生成

时间:2016-07-28 15:45:58      阅读:365      评论:0      收藏:0      [点我收藏+]

标签:

使用AVFoundation框架可以生成视频缩略图,用到的类:

》》AVAsset:

  用于获取多媒体的相关信息,如多媒体的画面和声音等。

》》AVURLAsset:  

  AVAsset的子类,用于根据NSURL生成AVAsset对象

》》AVAssetImageGenerator:

  用于截取视频指定帧的动画

一般步骤:

1、根据视频的URLchuang见AVURLAsset对象

2、根据AVURLAsset对象创建AVAssetImageGenerator对象

3、调用AVAssetImageGenerator对象的copyCGImageAtTime:actualTime:error:来获取该视频指定时间点的视频截图

  第一个参数:指定获取哪个时间点的视频截图,该参数是一个CMTime结构体:(CMTime. value/timescale = seconds)

typedef struct
{
    CMTimeValue    value;        /*! @field value The value of the CMTime. value/timescale = seconds. */
    CMTimeScale    timescale;    /*! @field timescale The timescale of the CMTime. value/timescale = seconds.  */
    CMTimeFlags    flags;        /*! @field flags The flags, eg. kCMTimeFlags_Valid, kCMTimeFlags_PositiveInfinity, etc. */
    CMTimeEpoch    epoch;        /*! @field epoch Differentiates between equal timestamps that are actually different because
                                                 of looping, multi-item sequencing, etc.  
                                                 Will be used during comparison: greater epochs happen after lesser ones. 
                                                 Additions/subtraction is only possible within a single epoch,
                                                 however, since epoch length may be unknown/variable. */
} CMTime;  

    获取CMTime相关函数:

CMTime CMTimeMake(
                int64_t value,        /*! @param value        Initializes the value field of the resulting CMTime. */
                int32_t timescale)    /*! @param timescale    Initializes the timescale field of the resulting CMTime. */
                            __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_4_0);

CMTime CMTimeMakeWithSeconds(
                Float64 seconds,      
          int32_t preferredTimeScale)
                 __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_4_0);

  第二个参数:获取截图的实际时间点(要用“&”传指针)

  第三个参数:获取错误信息(要用“&”传指针)

IOS 视频缩略图的生成

标签:

原文地址:http://www.cnblogs.com/zhhl/p/5714752.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!