IOS 视频分解图片、图片合成视频
来源:互联网 发布:什么看书软件最好 编辑:程序博客网 时间:2024/05/17 00:18
在IOS视频处理中,视频分解图片和图片合成视频是IOS视频处理中经常遇到的问题,这篇博客就这两个部分对IOS视频图像的相互转换做一下分析。
(1)视频分解图片
这里视频分解图片使用的是AVAssetImageGenerator,利用这个class可以很方便的实现不同时间戳下,视频帧的抓取。注意一般这种视频分解图片帧的方法都是放在子线程中的,而UI更新操作都是放在主线程中的。下面来看看核心代码:
_imageGenerator = [[AVAssetImageGeneratoralloc] initWithAsset:_asset];
images = [[NSMutableArrayalloc]initWithCapacity:10];
_imageGenerator.maximumSize =THUMBNAIL_SIZE;
CMTime duration = _asset.duration;
CMTimeValue intervalSeconds = duration.value /3;
CMTime time = kCMTimeZero;
NSMutableArray *times = [NSMutableArrayarray];
for (NSUInteger i =0; i < 3; i++) {
[timesaddObject:[NSValuevalueWithCMTime:time]];
time =CMTimeAdd(time, CMTimeMake(intervalSeconds, duration.timescale));
}
[_imageGeneratorgenerateCGImagesAsynchronouslyForTimes:times completionHandler:^(CMTime requestedTime, CGImageRef cgImage,
CMTime actualTime,
AVAssetImageGeneratorResult result,
NSError *error) {
if (cgImage) {
UIImage *image = [UIImageimageWithCGImage:cgImage];
[imagesaddObject:image];
}
if (images.count ==3) {
dispatch_async(dispatch_get_main_queue(), ^{
self.imageview1.image = [imagesobjectAtIndex:0];
self.imageview2.image = [imagesobjectAtIndex:1];
self.imageview3.image = [imagesobjectAtIndex:2];
});
}
}];
分解之后的帧效果如下: 图片合成视频效果如下:
(2)图片合成视频
图片合成视频的方法相对来说更加复杂一点,我们主要用到的class是这个:
AVAssetWriterInputPixelBufferAdaptor。不同之处在于这里我们还要设置图片合成视频的各种参数,比如帧率,编码方式等等。
2.1 设置文件封装类型
AVFileTypeQuickTimeMovie
2.2 设置图片格式
kCVPixelFormatType_32ARGB
2.3 设置编码方式、图片尺寸
NSDictionary *videoSettings =@{AVVideoCodecKey :AVVideoCodecH264,
AVVideoWidthKey : [NSNumbernumberWithInt:(int)width],
AVVideoHeightKey : [NSNumbernumberWithInt:(int)height]};
2.4 图片合成开始
CMTime lastTime =CMTimeMake(i, self.frameTime.timescale);
CMTime presentTime =CMTimeAdd(lastTime, self.frameTime);
[self.bufferAdapterappendPixelBuffer:sampleBuffer withPresentationTime:presentTime];
- IOS 视频分解图片、图片合成视频
- IOS视频分解图片、图片合成视频
- 视频分解图片,图片合成视频
- 4、批量读取图片、视频分解、视频合成
- Matlab图片合成视频
- matlab 图片合成视频
- ffmpeg图片合成视频
- FFmpeg 图片合成视频
- iOS 多张图片合成视频
- IOS多张图片合成一个视频
- IOS多张图片合成一个视频
- IOS多张图片合成一个视频
- IOS多张图片合成一个视频
- iOS多张图片合成一个视频
- IOS多张图片合成一个视频
- iOS多张图片合成一个视频
- opencv 视频分解成图片 图片合成视频 批量读取图片
- iOS开发视频分解成图片
- linux中关于时间函数的线程安全
- SAP HANA分布式系统及高可用性(一)
- 平台CMS installshield脚本
- excel 如何提取分类汇总后的数据
- 05-算术运算符
- IOS 视频分解图片、图片合成视频
- websphere集群在DNS主服务器宕机后异常的处理办法
- jQuery(function(){})与(function(){})(jQuery)的区别
- Session和Cookie的区别
- 在 Windows 上快速安装并运行 Laravel 5.x
- 进程间通信-FIFI(命名管道)
- 06-算数运算符练习
- Filter在IE低版本的写法
- jQuery操作Form表单元素