Skip to content

Instantly share code, notes, and snippets.

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>
//typedef (^AudioWriteComplection)(Bool, NSError);
@interface AVAsset (AudiExtract)
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.requestedTimeToleranceAfter = kCMTimeZero;
generator.requestedTimeToleranceBefore = kCMTimeZero;
for (Float64 i = 0; i < CMTimeGetSeconds(asset.duration) * FPS ; i++){
@autoreleasepool {
CMTime time = CMTimeMake(i, FPS);
NSError *err;
CMTime actualTime;
CGImageRef image = [generator copyCGImageAtTime:time actualTime:&actualTime error:&err];
@jayeshk
jayeshk / SaveVideoToAsset.m
Last active November 25, 2016 17:09
Save resource video file to photo library using asset library.
NSURL* videoURL = [[NSBundle mainBundle] URLForResource:@"demo-clip" withExtension:@"mp4"];;
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
ALAssetsLibraryWriteVideoCompletionBlock completionBlock =
^(NSURL *savedURL, NSError *error) {
if (error) {
NSLog( @"Error while saving video Photo Library: %@", error );
} else {
NSLog( @"Successfuly saved video to Photo Library %@", savedURL.absoluteString);
}
};
@jayeshk
jayeshk / AssetsLibraryAssets.m
Last active November 24, 2016 11:32
AssetsLibrary print list of assets
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group != NULL) {
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
NSLog(@"asset: %@", result);
}];
}
} failureBlock:^(NSError *error) {
NSLog(@"Error -- %@", error);
}];