关于[有图有真相]ffmepg在iOS上应用 后续制作Library,之前跟大家提了一下,这个是非常有必要告知给大家的,其实我觉得博文只是一种方式,最重要的是有意义的互动,就是我哪里做的不好,需要改进什么,大家提出的每一点建议都能让我们共同进步,这个世界没有人拖后腿,也没有人愿意,就看大家是否愿意w-w,双赢;很多时候大家认为只有w-l,实际上cong长远上来说这是l-l。
GenerateFrameImage-Library http://download.csdn.net/detail/knockheart/5543791
直入主题
1.新建项目Framework&Library
2.本文以GenerateFrameLibrary做示例
3.将引用的框架和外部类库导入
图中报红的库删掉重新导入便可
4.新建你的接口
GenerateFrameImage.h
//
// GenerateFrameImage.h
// GenerateFrameImage
//
// Created by lifei on 13-6-6.
// Copyright (c) 2013年 tci. All rights reserved.
//
#import <Foundation/Foundation.h>
@class VideoFrameExtractor;
@interface GenerateFrameImage :NSObject
{
NSString *filePath;
VideoFrameExtractor *video;
}
/* Initialize with movie at moviePath. Output dimensions are set to source dimensions. */
-(id)initWithFileUrl:(NSString *)moviePath;
- (NSArray*) getImages:(int)frameNum startSec:(float)secStart endSec:(float) secEnd;
-(void) setOutputImgSize:(int)width imgHeight:(int) height;
-(double) duration;
@end
GenerateFrameImage.m
// // GenerateFrameImage.m // GenerateFrameImage // // Created by lifei on 13-6-6. // Copyright (c) 2013年 tci. All rights reserved. // #import "GenerateFrameImage.h" #import "VideoFrameExtractor.h" @implementation GenerateFrameImage -(id)initWithFileUrl:(NSString *)moviePath{ self = [super init]; if (self) {
//here is what you want to do filePath = moviePath; video = [[VideoFrameExtractor alloc]initWithVideo:filePath]; //dufault output image size video.outputWidth = 426; video.outputHeight = 320; // print some info about the video DLog(@"video duration: %f",video.duration); DLog(@"video size: %d x %d", video.sourceWidth, video.sourceHeight); } return self; } -(double) duration{ return video.duration; } -(void) setOutputImgSize:(int)width imgHeight:(int) height{ video.outputWidth = width; video.outputHeight = height; } - (NSArray*) getImages:(int)frameNum startSec:(float)startSec endSec:(float) endSec{ //init ImagesArray NSMutableArray * imagesArray = [[NSMutableArray alloc]init]; //init a image object // UIImage *image=[[UIImage alloc] init]; if(frameNum ==0){ DLog(@"The Num is Zero"); return nil; } //is startSec bigger than endSec if(startSec > endSec){ DLog(@"The startSec is bigger than endSec"); return nil; } if (startSec > video.duration || endSec > video.duration) { DLog(@"The startSec or endSec is bigger than video's length"); return nil; } //get the time interval double timer = endSec - startSec; double startTime = startSec; //get the average plusTime double plusTime = timer/frameNum; DLog(@"The endSec time: %f s",timer); // seek to point seconds if(startSec <= video.duration && endSec <= video.duration){ for( int i=0 ;i< frameNum;i++){ NSLog(@"StartTime == %f",startTime); [video seekTime:startTime]; [video stepFrame]; //trans the image to data with type of .Png NSData *data=UIImagePNGRepresentation(video.currentImage); [imagesArray addObject:data]; [data release]; startTime+=plusTime; } return imagesArray; }else{ NSLog(@"The time is biger than the video length"); return nil; } } @end
7.生成完的.a文件和几个.h头文件你就是的类库主要组成了,只要在使用的时候将它们加入工程,并引用即可
这里说的比较简单,可参考:我的另一篇博文基于FFmpeg自定义Library,GenerateFrameImage的使用说明