I am using AVAssetWriter to compress a video, the code works in both iPhone 5 and 4 in iOS7. I am attempting to use the AVVideoProfileLevelKey of AVVideoProfileLevelH264High41 to attain better compression than that of Baseline or Main profiles. The code works in iOS7 with an iPhone 5, but breaks on an iPhone 4 with the following error. Most of these profiles listed in the error below additionally do not work.
Does anyone know if High profiles for compression don't work on iPhone 4, Apples documentation only states that it requires iOS6 or higher.
> 2013-12-10 18:26:37.637 VideoCompression[677:3707] *** Terminating app
> due to uncaught exception 'NSInvalidArgumentException', reason: '***
> `-[AVAssetWriterInput initWithMediaType:outputSettings:sourceFormatHint:]` For compression
> property ProfileLevel, video codec type avc1 only allows the following
> values: H264_Baseline_1_3, H264_Baseline_3_0, H264_Baseline_3_1,
> H264_Baseline_4_1, H264_Main_3_0, H264_Main_3_1, H264_Main_3_2,
> H264_Main_4_0, H264_Main_4_1, H264_Main_5_0, H264_High_5_0,
> H264_Baseline_AutoLevel, H264_Main_AutoLevel, H264_High_AutoLevel'
> *** First throw call stack: (0x2fd76f4b 0x3a1066af 0x2ec5d833 0x2ec5d70b 0x2ec5d67d
0xbd001 0xbba59 0x3a5e9d1b 0x3a5ea293 0x3a5ea6f7
> 0x3a5fc8f9 0x3a5fcb79 0x3a72bdbf 0x3a72bc84) libc++abi.dylib:
> terminating with uncaught exception of type NSException
NSDictionary *codecSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInteger:[bitrateTF.text intValue]], AVVideoAverageBitRateKey,
[NSNumber numberWithInt:[maxkeyframeintervalTF.text intValue]],AVVideoMaxKeyFrameIntervalKey,
**AVVideoProfileLevelH264High41,AVVideoProfileLevelKey,**
videoCleanApertureSettings, AVVideoCleanApertureKey,
videoAspectRatioSettings, AVVideoPixelAspectRatioKey,
nil];
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
AVVideoScalingModeResizeAspectFill, AVVideoScalingModeKey,
codecSettings,AVVideoCompressionPropertiesKey,
[NSNumber numberWithInt:[widthTF.text intValue]], AVVideoWidthKey,
[NSNumber numberWithInt:[heightTF.text intValue]], AVVideoHeightKey,
//AVVideoScalingModeFit,AVVideoScalingModeKey,
nil];
self.assetWriterVideoInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings];
self.assetWriterVideoInput.transform = self.transformAssetWriter;
[self.assetWriter addInput:self.assetWriterVideoInput];
You can't encode in ProfileLevelH264High41 with iPhone4, it is only supported from iPhone4S
Related
I'm creating my first RestKit application. I'm trying to map to_many relation to core data.
Speakers JSON
{
id: 1,
session_ids: [1,87]
},
{
id: 2,
session_ids: [2,88]
},
Mapping
sessionEntitiyMapping = [RKEntityMapping mappingForEntityForName:#"Session" inManagedObjectStore:self.managedObjectStore];
[sessionEntitiyMapping addAttributeMappingsFromDictionary:#{
#"id": #"session_id",
}];
sessionEntitiyMapping.identificationAttributes = #[ #"session_id" ];
speakerEntityMapping = [RKEntityMapping mappingForEntityForName:#"Speaker" inManagedObjectStore:self.managedObjectStore];
[speakerEntityMapping addAttributeMappingsFromDictionary:#{
#"name": #"name",
#"id": #"speaker_id",
}];
[speakerEntityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"session_ids"
toKeyPath:#"sessions"
withMapping:sessionEntitiyMapping]];
speakerEntityMapping.identificationAttributes = #[ #"speaker_id" ];
Error
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFNumber 0x8569690> valueForUndefinedKey:]: this class is not key value coding-compliant for the key id.'
I think the problem is that you are using a primitive in your model, i.e session_id has NSInteger type. Unfortunately you are disallowed to use it, please use NSNumber instead.
I am using the AssetsLibrary framework to retrieve all asset groups in the iPhone. I have some code snippet like this:
NSMutableArray *groups = [[NSMutableArray alloc] initWithCapacity:5];
void (^groupEnumerator)(ALAssetsGroup*, BOOL*) = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
NSLog(#"Adding group %#", [group valueForProperty:ALAssetsGroupPropertyName]);
[groups addObject:group];
}
};
ALAssetsLibrary* library = [AssetsManager defaultAssetsLibrary];
[library enumerateGroupsWithTypes: ALAssetsGroupSavedPhotos
usingBlock:groupEnumerator
failureBlock:^(NSError * err) {NSLog(#"Erorr: %#", [err localizedDescription]);}];
And I found a weird behavior:
1) When I run my app in the iOS simulator (use command + R in Xcode), the groupEnumerator will be executed and group names will be printed in the console
2) I wrote some unit test for my app, when I run the unit test (use command + U in Xcode), which calls the above code snippet as it is called in my app, the groupEnumerator seems not get executed at all and none of the group name will be printed, and the failureBlock doesn't get called too and I don't get any error when running the tests but the group enumeration doesn't work as it does in the app.
I check Apple's documentation, and I know this method (enumerateGroupsWithTypes:usingBlock:failureBlock:) is asynchronous, however, even if I wait for a long time in my unit test, I don't see the groupEnumerator get executed.
I am testing against iOS 5.0 with Xcode 4.2.
Any help is appreciated. Thanks.
Stuck on this problem for several days, couldn't figure out the exact cause of this issue.
And instead of using OCUnit in Xcode 4, I had to switch to use gh-unit, which solves this issue actually. It seems related with the way Xcode 4 runs the test target.
http://gabriel.github.com/gh-unit
I have put the following code in...;
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:#"text/plain",kSKPSMTPPartContentTypeKey,
#"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %#",field.text,
kSKPSMTPPartMessageKey,#"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];
...and I receive an NSException error saying;
*** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate:
<NSInvalidArgumentException> +[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil. Or, did
you forget to nil-terminate your parameter list?
What does this mean? What do I have to do to fix this issue?
Thanks,
James
You are trying to format a string in your dictionary initialization and it expects the format to be object, key, object, key, etc... To fix try creating your formatted string on another line for clarity and then adding it as part of the objects and keys as so
NSString *message = [NSString stringWithFormat:#"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %#",
field.text];
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:
#"text/plain", kSKPSMTPPartContentTypeKey,
message, kSKPSMTPPartMessageKey,
#"8bit", kSKPSMTPPartContentTransferEncodingKey,nil];
Maybe you meant something like this:
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:#"text/plain", kSKPSMTPPartContentTypeKey, [NSString stringWithFormat:#"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %#",field.text], kSKPSMTPPartMessageKey, #"8bit", kSKPSMTPPartContentTransferEncodingKey,nil];
You are missing an argument. I count 8 total arguments including nil. That means one of your key value pairs is not complete.
Try firsty create string:
NSString *partMessageKey = [NSString stringWithFormat:#"Hello,\n You've just received a new message from the iDHSB iPhone App.\n Here it is: %#",field.text];
then put this string to dictionary as object.
I testing following code on simulator ,it works fine but when I select the device and run then it gives exception .
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
tempPeoples= [NSMutableArray arrayWithCapacity:0];
for(int i=0;i<nPeople;i++){
ABRecordRef i1=CFArrayGetValueAtIndex(allPeople, i);
NSString* name = (NSString *)ABRecordCopyValue(i1,kABPersonFirstNameProperty);
[tempPeoples addObject:name];
// [peoples addObject:i1];
}// end of
following exception occurs
2011-01-06 12:12:42.384 Appointment[2849:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSCFArray insertObject:atIndex:]: attempt to insert nil'
2011-01-06 12:12:42.397 Appointment[2849:207] Stack: (
843263261,
825818644,
842812211,
842812115
Please help
You're adding a nil to an array (as the message says)
By a process of deduction, I see that you are adding objects to an array at this line
[tempPeoples addObject:name];
So it is likely that, for this snippet of code, this is where the error happens.
Probably, Not all of the Contacts have a first name, which is likely to be the case for contacts that are businesses rather than people.
You could put a breakpoint in the code and run it through a debugger to see what conditions cause this.
I tried use "PLCrashReport" to collect the crash info then make the app more stable, but turns out that the report is like this(dont even has a call stack,how am I suppose to use it?):
The "Exception:" part,Exception: (null): (null), which should be "exceptionName" and "exceptionReason", at most time are "null", dont know why, sometimes there will be a normal value but also I think not quite useful...
Crashed on 2009-11-13 23:43:04 +0800
- Signal SIGSEGV (code SEGV_ACCERR, address=0xffffffffc0f4186b)
Exception: (null): (null) - Thread 0:
Crashed: 1
Stack (54 frames):,\n 806128664,\n 807756495,\n 816280840,\n 816247
068,\n 817901396,\n 807756495,\n 816280840,\n 817911108,\n 816247068,\n 816285160,\n 816406620,\n 807756495,\n 806130012,\n 119241,\n 812165747,\n 812164839 ,\n 812379009,\n 818127880,\n 807885435,\n 807923065,\n 818122176,\n 818130772,\n 816625560,\n 816626608,\n 816627024,\n 816641892,\n 816651496,\n 816654628 ,\n 816654224,\n 146455,\n 807923363,\n 816119156,\n 816119004,\n 818227300,\n 807923363,\n 816119156,\n 816119004,\n 816524332,\n 816525956,\n 816521588,\n 816212028,\n 816151252,\n 816147980,\n 827758796,\n 827769116,\n 837343488,\n 821391952,\n 807840887,\n 807836793,\n 807834407,\n 827752032,\n 816118388,\n816157144,\n 20421
What's a stack trace?
Whenever one of your methods gets called, it puts this onto the stack. A stack trace is a way of finding out which class and method your app crashed in, which often narrows down the bug to a single line.
Of course to do this, the stack trace needs to be readable, rather than a whole load of hex numbers.
Check out atos.
To prevent this happening again, you could interpret this Call Stack using atos.
See the Stack Traces page of the Cocoa Dev wiki for a discussion and code on how to convert these numbers into meaningful methods.
You'll need to figure out a way of integrating this with the crash reporter. I use UKCrashReporter and I've modified Uli's code so that if there's an uncaught exception it adds the readable stack trace onto the crash report.
Code Sample
I've taken inspiration from the ESStackTrace class and here's what I do:
-(void)logAndSaveStackTrace {
NSString *stackTrace = [[self userInfo] objectForKey:NSStackTraceKey];
NSString *atosCommand;
if (stackTrace) {
// If the stack trace key is present, pull out the addresses and convert to method names using atos.
atosCommand = [NSString stringWithFormat:#"/usr/bin/atos -p %d %# | tail -n +3 | head -n +%d | c++filt | cat -n",
[[NSProcessInfo processInfo] processIdentifier],
stackTrace,
([[stackTrace componentsSeparatedByString:#" "] count] - 4)];
} else {
// If there isn't a stack trace key or it's nil, try and work out the stack using the internal callStackReturn addresses method.
NSArray *stackTraceArray = [self callStackReturnAddresses];
atosCommand = [NSString stringWithFormat:#"/usr/bin/atos -p %d %#",
[[NSProcessInfo processInfo] processIdentifier],
[stackTraceArray componentsJoinedByString:#" "]];
}
NSString *readableStackTrace = [ShellTask executeShellCommandSynchronously:atosCommand];
NSString *exceptionMessageForCrashReport = [NSString stringWithFormat:#"An exception of type %s occured.\n%s\nStack trace:\n%#",
[[self name] cStringUsingEncoding:NSUTF8StringEncoding],
[[self reason] cStringUsingEncoding:NSUTF8StringEncoding],
readableStackTrace];
[[NSUserDefaults standardUserDefaults] setObject:exceptionMessageForCrashReport forKey:#"uncaughtExceptionReport"];
[[NSUserDefaults standardUserDefaults] synchronize];
// Log the exception to the console too.
NSLog(#"%#", exceptionMessageForCrashReport);
}
Dependencies Ahoy!
Of course, one of the problems with this approach is that you're introducing a dependency on atos. I've been told that it's installed as standard on 10.5 and later, but this might be wrong. Eventually I'm going to make a little installer which adds atos if my app can't find it.
I haven't used it but I'm pretty sure you're not getting any detail because you had a segmentation fault that took out everything down to the registers. The PLCrashReport instance can't report because it died along with everything else.
The PLCrashReport instances runs within the Application itself so if the app goes down hard you won't get any detail.