Miniatura de ALAsset en una marca de tiempo específica
Frecuentes
Visto 1,906 equipos
0
Estoy trabajando en una aplicación de iPhone para cargar archivos de video a una plataforma específica, y una característica que realmente me encantaría es poder presentar, digamos, diez miniaturas diferentes para el mismo video para que el usuario elija.
El problema es que ALAsset solo proporciona una uña del pulgar método, que solo devuelve la miniatura predeterminada. He leído la documentación de ALAssetRepresentation y ALAsset y parece que no puedo encontrar una manera de obtener una miniatura para un soluciones marca de tiempo.
Supongo que una opción sería usar algo similar a libav para obtener miniaturas, pero eso parece un poco "exagerado" para algo como esto. ¿Alguien puede ayudarme con esto?
Saludos cordiales,
Nick
2 Respuestas
4
creo que esto te ayudará, y también puedes ver a través de este mensaje Falta la marca de tiempo de la miniatura del archivo de video en ALAsset
{
if ([theAsset valueForProperty:ALAssetPropertyType] == ALAssetTypeVideo) {
// Black semi-transparent background at the bottom of the item
CGRect containerFrame = CGRectMake(0, frame.size.height - AGIPC_ITEM_HEIGHT, frame.size.width, AGIPC_ITEM_HEIGHT);
UIView *containerForMovieInfo = [[[UIView alloc] initWithFrame:containerFrame] autorelease];
containerForMovieInfo.backgroundColor = [UIColor blackColor];
containerForMovieInfo.alpha = 0.7f;
// Movie icon on left side
CGRect movieFrame = CGRectMake(4, 60, 26, 15);
UIImageView *movieImageView = [[[UIImageView alloc] initWithFrame:movieFrame] autorelease];
if (IS_IPAD()) {
movieImageView.image = [UIImage imageNamed:@"AGIPC-Movie-iPad"];
} else {
movieImageView.image = [UIImage imageNamed:@"AGIPC-Movie-iPhone"];
}
[containerForMovieInfo addSubview:movieImageView];
// Movie duration on right side
if ([theAsset valueForProperty:ALAssetPropertyDuration] != ALErrorInvalidProperty) {
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"mm:ss"];
CGRect durationFrame = CGRectMake(frame.size.width - 26 - 4, 60, 26, 15);
UILabel *durationView = [[[UILabel alloc] initWithFrame:durationFrame] autorelease];
durationView.backgroundColor = [UIColor clearColor];
durationView.textColor = [UIColor whiteColor];
durationView.text = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[[theAsset valueForProperty:ALAssetPropertyDuration] doubleValue]]];
durationView.font = [UIFont systemFontOfSize:10];
[containerForMovieInfo addSubview:durationView];
}
[self addSubview:containerForMovieInfo];
}
}
por último, pero no menos importante, debe crear la imagen de la cámara por su cuenta.
contestado el 23 de mayo de 17 a las 13:05
0
// Get URL from ALAsset* asset:
NSURL* assetURL = [asset valueForProperty:ALAssetPropertyAssetURL];
// Create AVURLAsset using this URL (assetOptions is optional):
NSDictionary* assetOptions = nil;
// assetOptions = @{AVURLAssetPreferPreciseDurationAndTimingKey : @(YES)};
AVAsset* avAsset = [[AVURLAsset alloc] initWithURL:assetURL options:assetOptions];
// Create generator:
AVAssetImageGenerator* generator = [[AVAssetImageGenerator alloc] initWithAsset:avAsset];
generator.appliesPreferredTrackTransform = YES;
// Create array with CMTimes of thumbnails using your own logic.
// (Use +(NSValue*)valueWithCMTime:(CMTime)time to add CMTime in array).
NSArray* times = [self generateThumbnailTimesForVideo:avAsset];
// Generate thumbnail images asynchronously:
[generator generateCGImagesAsynchronouslyForTimes:times
completionHandler:^(CMTime requestedTime,
CGImageRef image,
CMTime actualTime,
AVAssetImageGeneratorResult result,
NSError* error)
{
// This block is performed for each CMTime in times array.
UIImage* thumbnail = [[UIImage alloc] initWithCGImage:image];
}
];
El método síncrono para obtener miniaturas en cualquier momento es
// PS: SYNC method:
CGImageRef imgRef = [generator copyCGImageAtTime:time actualTime:NULL error:&error];
UIImage* thumbnail = [[UIImage alloc] initWithCGImage:image];
Respondido 06 Feb 14, 02:02
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas iphone ios video thumbnails alasset or haz tu propia pregunta.
¿dónde tengo que agregar este método? es urgente, ¿puedes responder por favor? - 1531343 usuario
cuando inicia con activo - (id) inicia con activo: (ALA activo *) el activo .. {} - mantenimiento