从AssetLibrary获取视频流并保存到文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从AssetLibrary获取视频流并保存到文件相关的知识,希望对你有一定的参考价值。
ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group,
BOOL
*stop) {
[group setAssetsFilter:[ALAssetsFilter allVideos]];
if
(group.numberOfAssets > 0)
{
NSIndexSet
*videoSet = [
NSIndexSet
indexSetWithIndexesInRange:
NSMakeRange
(0, group.numberOfAssets)];
[group enumerateAssetsAtIndexes:videoSet options:0 usingBlock:^(ALAsset *result,
NSUInteger
index,
BOOL
*stop) {
ALAssetRepresentation *representation = [result defaultRepresentation];
NSString
*savingPath = [
NSHomeDirectory
() stringByAppendingFormat:@
"/Documents/%@"
,representation.filename];
[[
NSFileManager
defaultManager]createFileAtPath:savingPath contents:
nil
attributes:
nil
];
NSFileHandle
*writingHandle = [
NSFileHandle
fileHandleForWritingAtPath:savingPath];
int
bufferSize = 1024;
uint8_t buffer[bufferSize];
unsigned
long
long
read = 0,length = 0;
NSAutoreleasePool
*pool = [[
NSAutoreleasePool
alloc]init];
int
n = 0;
for
(;read < representation.size;)
{
if
(n % 10 == 0)
{
[pool release];
pool =
nil
;
pool = [[
NSAutoreleasePool
alloc]init];
}
length = [representation getBytes:buffer fromOffset:read length:bufferSize error:
nil
];
read += length;
NSData
*fileData = [
NSData
dataWithBytes:(
const
void
*)buffer length:(
NSUInteger
)length];
[writingHandle writeData:fileData];
n++;
}
[writingHandle closeFile];
[pool drain];
}];
}
} failureBlock:^(
NSError
*error) {
}];
以上是关于从AssetLibrary获取视频流并保存到文件的主要内容,如果未能解决你的问题,请参考以下文章
使用 AssetLibrary 从 iPhone 获取最后 10 张照片,iOS 6.1.3 上的 Corelocation 弃用问题
OpenCV+visual studio 2019 实现对avi视频或摄像头 laplace边缘检测。从AVI文件( bsd.avi)中得到视频流,对视频流进行Laplace边缘检测,并输出结果。(代