博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Read ALAsset movie file and write into the disk
阅读量:6916 次
发布时间:2019-06-27

本文共 3686 字,大约阅读时间需要 12 分钟。

Read the asset from the Library and get decompresIn the above post the size of the asset file is too big so here is another way to decompress the fileThis is also taken from the stack over flow,http://stackoverflow.com/questions/5687341/iphoneprogrammatically-compressing-recorded-video-to-share- (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL                                    outputURL:(NSURL*)outputURL                                      handler:(void (^)(AVAssetExportSession*))handler{    [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];    exportSession.outputURL = outputURL;    exportSession.outputFileType = AVFileTypeQuickTimeMovie;    [exportSession exportAsynchronouslyWithCompletionHandler:^(void)      {         handler(exportSession);         [exportSession release];     }];}
Export movie/image asset file into the diskThis is taken from the stack overflow and slightly modified - (BOOL) exportDataToURL: (NSString*) filePath error: (NSError**) error andAsset:(ALAsset*)asset{    NSError **errorInternal = nil;    [[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];    NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:filePath];    if (!handle) {        return NO;    }        static const NSUInteger BufferSize = 1024*1024;    ALAssetRepresentation *rep = [asset defaultRepresentation];    uint8_t *buffer = calloc(BufferSize, sizeof(*buffer));    NSUInteger offset = 0, bytesRead = 0;        do {        @try {            bytesRead = [rep getBytes:buffer fromOffset:offset length:BufferSize error:error];            [handle writeData:[NSData dataWithBytesNoCopy:buffer length:bytesRead freeWhenDone:NO]];            offset += bytesRead;        } @catch (NSException *exception) {            free(buffer);                        return NO;        }    } while (bytesRead > 0);        free(buffer);    return YES;}
Read the file from assets-library and write into ur custom fileAlthough u can see many same solutions available same as given below...This method take the Asset and fileName to create that file into the tempdirectory. It returns the path of the tempdirectory/file where it stores the This is the same as reading a file from the Assets library (Photo library). -(NSString*) writeVideoFileIntoTemp:(NSString*)fileName andAsset:(ALAsset*)asset{    NSString * tmpfile = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];                ALAssetRepresentation * rep = [asset defaultRepresentation];                NSUInteger size = [rep size];        const int bufferSize = 1024*1024; // or use 8192 size as read from other posts                 NSLog(@"Writing to %@",tmpfile);        FILE* f = fopen([tmpfile cStringUsingEncoding:1], "wb+");        if (f == NULL) {            NSLog(@"Can not create tmp file.");            return;        }                Byte * buffer = (Byte*)malloc(bufferSize);        int read = 0, offset = 0, written = 0;        NSError* err;        if (size != 0) {            do {                read = [rep getBytes:buffer                          fromOffset:offset                              length:bufferSize                                error:&err];                written = fwrite(buffer, sizeof(char), read, f);                offset += read;            } while (read != 0);                                }        fclose(f);    return tmpfile;}

 

转载于:https://www.cnblogs.com/kiss007/archive/2013/01/31/2887497.html

你可能感兴趣的文章
ASP.NET仿新浪微博下拉加载更多数据瀑布流效果
查看>>
如何使用cisco的iou工具
查看>>
如何使用TP-LINK无线路由器
查看>>
Cisco 瘦ap刷成胖ap
查看>>
fragment中套用PagerSlidingTabStrip,切换底部时viewpager消失的解决
查看>>
《阿甘正传》观后感 --别停下你的脚步,做最好的自己
查看>>
工程规范
查看>>
Linux进程管理优化及性能评估工具介绍
查看>>
我的友情链接
查看>>
LDD
查看>>
ESXI授权
查看>>
beetl-eclipse-plugin 原型
查看>>
logstash 解析多行日志
查看>>
国内开源镜像网站汇总
查看>>
部署kubernetes集群
查看>>
reactive programming 2.3 loop
查看>>
关于<span>标签设置大小
查看>>
win8系统如何设置眼睛保护色
查看>>
std::vector erase
查看>>
IIS 日志文件位置
查看>>