我正在尝试使用AVMutableComposition在精确的时间播放一系列声音文件.
当视图加载时,我创建合成,目的是在1秒内均匀地播放4个声音.声音的长短不应该无关紧要,我只想在0,0.25,0.5和0.75秒时将它们发射:
AVMutableComposition *composition = [[AVMutableComposition alloc] init];
NSDictionary *options = @{AVURLAssetPreferPreciseDurationAndTimingKey : @YES};
for (NSInteger i = 0; i < 4; i++)
{
AVMutableCompositionTrack* track = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
NSURL *url = [[NSBundle mainBundle] URLForResource:[NSString stringWithFormat:@"sound_file_%i", i] withExtension:@"caf"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:options];
AVAssetTrack *assetTrack = [asset tracksWithMediaType:AVMediaTypeAudio].firstObject;
CMTimeRange timeRange = [assetTrack timeRange];
Float64 t = i * 0.25;
NSError *error;
BOOL success = [track insertTimeRange:timeRange ofTrack:assetTrack atTime:CMTimeMakeWithSeconds(t, 1) error:&error];
if (!success)
{
NSLog(@"unsuccesful creation of composition");
} …Run Code Online (Sandbox Code Playgroud) core-audio avfoundation ios avcomposition avmutablecomposition
我想从视频中获取第一个缩略图.
我尝试了以下方法:
一
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:_moviePath] options:nil];
AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
gen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);
NSError *error = nil;
CMTime actualTime;
CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
UIImage *thumb = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);
NSLog(@"the error is %@: image is %@: url is %@: ",error,_mainThumbnail,[NSURL fileURLWithPath:_moviePath] );
Run Code Online (Sandbox Code Playgroud)
但是,我的日志是:
the error is (null): image is (null):
url is file:///private/var/mobile/Applications/D1293BDC-EA7E-4AC7-AD3C-1BA3548F37D6/tmp/trim.6F0C4631-E5E8-43CD-BF32-9B8F09D4ACF1.MOV:
Run Code Online (Sandbox Code Playgroud)
二
AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:_moviePath] options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator …Run Code Online (Sandbox Code Playgroud) 我正在实施自定义相机,为此我想设置曝光持续时间。
我设置滑块属性的代码是-
slider.maximumValue = Float(CMTimeGetSeconds(camera.activeFormat.maxExposureDuration))
slider.minimumValue = Float(CMTimeGetSeconds(camera.activeFormat.minExposureDuration))
Run Code Online (Sandbox Code Playgroud)
现在,每当滑块更改时设置曝光时间时就会出现问题。
我的代码看起来像这样 -
change(duration: CMTimeMakeWithSeconds(Double(slider.value), 600), iso: AVCaptureISOCurrent)
Run Code Online (Sandbox Code Playgroud)
但在
func CMTimeMakeWithSeconds(_ seconds: Float64, _ preferredTimescale: Int32) -> CMTime
Run Code Online (Sandbox Code Playgroud)
我很困惑preferredTimescale,它的价值应该是多少,它与 600 一起工作正常,但什么是理想价值。
我想获得用户选择的视频长度.我正在使用苹果UIImagePicker,
这是我目前的代码:
[self dismissModalViewControllerAnimated:YES];
//assign the mediatype to a string
//check the media type string so we can determine if its a video
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
webData = [[NSData alloc]init];
webData = [NSData dataWithContentsOfURL:videoURL];
//[self post:webData];
video = 1;
upload.hidden = NO;
ImagesCopy = [[NSMutableArray alloc]initWithObjects:@"1", nil];
[tableview reloadData];
Run Code Online (Sandbox Code Playgroud)
感谢:D
ios ×5
avfoundation ×2
cmtime ×2
iphone ×2
objective-c ×2
cocoa-touch ×1
core-audio ×1
ios6 ×1
nsdata ×1
swift ×1