相关疑难解决方法(0)

试图了解CMTime

我见过一些例子 CMTime(三个独立的链接),但我还是不明白这一点.我正在使用AVCaptureSession和AVCaptureVideoDataOutput,我想设置输出的最大和最小帧速率.我的问题是我只是不理解CMTime结构.

显然CMTimeMake(value,timeScale)应该每1/timeScale秒给我一个值帧,总共得到value/timeScale秒,或者我错了吗?

为什么在任何地方都没有记录这个以解释它的作用?

如果它真的像那样工作,我怎么能让它有无限数量的帧?

如果真的很简单,我很抱歉,但还没有点击过.

ios avcapturesession cmtime

47
推荐指数
2
解决办法
2万
查看次数

使用AVMutableComposition进行精确计时

我正在尝试使用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

6
推荐指数
1
解决办法
1764
查看次数

从视频中截取缩略图始终返回null

我想从视频中获取第一个缩略图.

我尝试了以下方法:

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)

iphone cocoa-touch objective-c ios ios6

5
推荐指数
1
解决办法
5146
查看次数

CMTimeMakeWithSeconds 中的首选时间刻度

我正在实施自定义相机,为此我想设置曝光持续时间。

我设置滑块属性的代码是-

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 一起工作正常,但什么是理想价值。

avfoundation ios cmtime swift

3
推荐指数
1
解决办法
5675
查看次数

在解雇UIImagePicker后获取视频长度?

我想获得用户选择的视频长度.我正在使用苹果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

iphone objective-c nsdata ios

1
推荐指数
1
解决办法
1536
查看次数