我有 IBOutlet UILabel *label;
我想这样做
UILabel *label = [titleLabel copy];
label.text = @"Clone";
titleLabel.text = @"Original";
NSLog(@"label : %@, title : %@",label.text,titleLabel.text);
Run Code Online (Sandbox Code Playgroud)
这抛出异常
*终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因是: ' - [的UILabel copyWithZone:]:无法识别的选择发送到实例0x6a4a450'*第一掷调用堆栈:(0x126f052 0x1823d0a 0x1270ced 0x11d5f00 0x11d5ce2 0x1271bd9 0x2ed6 0x1270e1a 0x2851 0x28264e 0x1e2a73 0x1e2ce2 0x1e2ea8 0x1e9d9a 0x24af 0x1ba9d6 0x1bb8a6 0x1ca743 0x1cb1f8 0x1beaa9 0x215cfa9 0x12431c5 0x11a8022 0x11a690a 0x11a5db4 0x11a5ccb 0x1bb2a7 0x1bca9b 0x21c2 0x2135)
我正在使用AVAssetWriterInputPixelBufferAdaptor为视频编写一些帧,当我写了很多帧时,我的应用程序因内存分配而崩溃.我怎么能防止这种情况?这是代码:
AVAssetWriterInput *writerInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings];
NSDictionary *sourcePixelBufferAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kCVPixelFormatType_32ARGB], kCVPixelBufferPixelFormatTypeKey, nil];
AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor
assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput
sourcePixelBufferAttributes:sourcePixelBufferAttributesDictionary];
CVPixelBufferRef buffer = NULL;
buffer = (CVPixelBufferRef)[self pixelBufferFromCGImage:[tmpImg CGImage] size:size];
if (buffer)
{
if(![adaptor appendPixelBuffer:buffer withPresentationTime:presentTime])
NSLog(@"FAIL");
else
NSLog(@"Success:%d",i);
CFRelease(buffer);
}
Run Code Online (Sandbox Code Playgroud)
当使用Xcode Instruments时,泄漏似乎发生在
if(![adaptor appendPixelBuffer:buffer withPresentationTime:presentTime])
Run Code Online (Sandbox Code Playgroud)
(AVAssetWriterInputPixelBufferAdaptor)
真的可以使用一些帮助或指向一个工作示例的指针.谢谢!
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[NSFileManager defaultManager] fileExistsAtPath:pathString])
{
infoDict = [[NSMutableDictionary alloc] initWithContentsOfFile:pathString];
}
else
{
infoDict = [[NSMutableDictionary alloc]initWithObjects:[NSArray arrayWithObjects:@"BeginFrame",@"EndFrame", nil] forKeys:[NSArray arrayWithObjects:[NSNumber numberWithBool:YES],[NSNumber numberWithBool:YES], nil]];
if ([infoDict writeToFile:pathString atomically:YES])
{
NSLog(@"Created");
}
else
{
NSLog(@"Is not created");
NSLog(@"Path %@",pathString);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码.我检查文件是否已创建,如果没有 - 我创建了一个NSMutableDictionary并将其写入文件路径,但 writeToFile方法返回NO.哪里有问题?如果我用NSFileManager 它创建这个文件是有效的,但是当我想写一个字典时却没有.
我有一个委托方法,但它对我没有帮助。请参考以下方法
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Run Code Online (Sandbox Code Playgroud) 如何在块中更改int值,我有这个:
__block long long size = -1;
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation * rep = [myasset defaultRepresentation];
size = [rep size];
//here showed normal value
NSLog(@"needed size : %lld",size);
};
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetslibrary assetForURL:self.tmpVideoURL
resultBlock:resultblock
failureBlock:nil];
//but here remaind -1
NSLog(@"out block value : %lld",size);
Run Code Online (Sandbox Code Playgroud) 请告诉我这段代码泄漏的地方......
//这里我用文档目录中的图像制作了视频
- (void) testCompressionSession:(NSString *)path
{
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
}
NSArray *array = [dictInfo objectForKey:@"sortedKeys"];
NSString *betaCompressionDirectory = path;
NSError *error = nil;
unlink([betaCompressionDirectory UTF8String]);
NSLog(@"array = %@",array);
NSData *imgDataTmp = [NSData dataWithContentsOfFile:[projectPath stringByAppendingPathComponent:[array objectAtIndex:0]]];
NSLog(@"link : %@",[projectPath stringByAppendingPathComponent:[array objectAtIndex:0]]);
CGSize size = CGSizeMake([UIImage imageWithData:imgDataTmp].size.width, [UIImage imageWithData:imgDataTmp].size.height);
//----initialize compression engine
NSLog(@"size : w : %f, h : %f",size.width,size.height);
AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:betaCompressionDirectory]
fileType:AVFileTypeQuickTimeMovie
error:&error];
NSParameterAssert(videoWriter);
if(error)
NSLog(@"error = %@", [error …Run Code Online (Sandbox Code Playgroud) 如何从视频中提取,持续时间,编解码器,大小和更多信息?
ios ×5
iphone ×5
core-video ×2
objective-c ×2
video ×2
xcode ×2
avfoundation ×1
metadata ×1
nsobject ×1
uikit ×1
uiwebview ×1