iPhone Life magazine

iPhone 3G S / 4 Video Camera Enhancement News

WARNING: this article can be highly technical and is definitely NOT meant for people that haven't ever tried hacking the camera of their iPhone 4 or 3G S. If I don't run into other obstacles (I find out something very important), the next one I publish will be meant for newcomers to iPhone 4 or 3G S enhancement. If you, however, are a seasoned hacker and/or a programmer interested in writing apps for Cydia and/or have previously used my hacking tools before and would like to know what the new versions contain, you will want to read on. AGAIN: this article is NOT meant for complete newcomers!

The new versions

The 3G S version number has been increased to 1.5 and the iPhone 4-specific one to 1.2. They're (still) in my private Cydia repository at winmobiletech.com/cy/. Just browse my repository: there're only two packages there (these apps) so you'll easily find them. The source code of the new versions is, as usual, freely available (download HERE and HERE for the iPhone 4 and 3 GS, respectively.)

Some programming: Cydia and the Documents directory (storing persistent settings)

First, Cydia, as it's the shortest subject of all. If you've used the previous versions, you may have noticed Advanced view didn't save their settings persistently, while, when deploying the app from Xcode, it did.

The sole reason for this is as follows: as you may already know, applications installed from Cydia are not stored under /var/mobile/Applications/, unlike with apps deployed by Xcode or installed over-the-air / via iTunes from AppStore. This also means the documents directory will be elsewhere and the directory prefix computed with the following code:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
documentsDir = [[paths objectAtIndex:0] retain];

if ([[NSFileManager defaultManager] fileExistsAtPath:[documentsDir stringByAppendingString:@"/backup.plist"]])
  NSData* serializedData = [NSData dataWithContentsOfFile:[documentsDir stringByAppendingString:@"/backup.plist"]];


will be useless.

To make your code compatible with both scenarios (both Xcode [+ AppStore] and Cydia), you'll need to change documentsDir to @"/var/mobile/Library/<YOUR APP'S NAME>" if you notice you aren't under /var/mobile/Applications/ (practically with a simple if (![documentsDir hasPrefix:@"/var/mobile/Applications/"]) decision). Also, make sure you also create the directory if it's still not existing. The following code shows exactly like this; note the long, unique appname (“ip4-VideoCameraPlus”) I used to avoid overwriting other apps' files:

if (![documentsDir hasPrefix:@"/var/mobile/Applications/"])
{
documentsDir = @"/var/mobile/Library/ip4-VideoCameraPlus"; // create dir if it doesn't exist
if (![[NSFileManager defaultManager] fileExistsAtPath:documentsDir])
[[NSFileManager defaultManager] createDirectoryAtPath:documentsDir withIntermediateDirectories:NO attributes:nil error:nil];
}

if ([[NSFileManager defaultManager] fileExistsAtPath:[documentsDir stringByAppendingString:@"/backup.plist"]])
  NSData* serializedData = [NSData dataWithContentsOfFile:[documentsDir stringByAppendingString:@"/backup.plist"]];



That's all – now, out code will store its data in both cases without problems and in the standard way.

Let's go on to the most important stuff, the new changes in the new versions (apart from the above bugfix).

iPhone 3G S (and, to some degree, iPhone 4): Available resolutions

Probably the most controversy around the 3G S video camera arose because of the people's not correctly measuring the real, effective resolution of the hacks they've developed. While there are several reports that expressed their doubts about most hacks' delivering any resolution increase (some of these posts are HERE, HERE, HERE, HERE, HERE), the majority of folks who posted have still firmly believed they do / did have at least some resolution enhancement. This simply wasn't the case in 99% of the cases.

The problem is that, unless you use the entire(!) surface of the 3G S sensor (this also applies to the iPhone 4!), you'll have an effective resolution of 640*480 (VGA). If you, on the other hand, do use the full sensor, your framerate will seriously drop and, on the 3G S, depending on the firmware version, you'll also have other problems.

Battery life – which mode to use to conserve as much battery life as possible?

I've also made some serious battery life tests to find out the most (and least) power-friendly modes. (Also note that the bigger the battery drain, the more the heating of the phone.) The figures are as follows:

iPhone 4, half an hour-long tests (the less, the better):

Default: 13%
Wide 1080p VGA: 10%
Wide 1080p XGA: 11%
Wide, Full Sensor: 13%

As you can see, the values are pretty similar. The two modes with the biggest effective resolution are the most power-hungry but the difference to the low-resolution “1080p” modes is still pretty small. As one can expect, creating an XGA stream instead of a (smaller) VGA one also requires a bit more CPU (11 vs. 10) at the same data rate.

iPhone 3G S:

The differences have been much bigger with the 3G S.

First, if you still have an OS version prior to 4.3 on your phone, using the Full Sensor mode will easily chew through your battery. If you do it at all, that is – the “Clicking”/freezing problem is a real pain in the back and, under 4.3, that mode is far better unless you need live view / make videos of subjects less than 2-3 metres away.

Full sensor mode battery usage and differences between 4.3 and earlier iOS versions

A 80 minute-long recording test have resulted in my 4.2.1 3GS' battery level decrease to 31%, while, at the same time, my 4.3.3 3GS with its vastly different Full sensor mode still had 54%. (Note: I also need to admit the battery in my 4.2.1 phone is about 23% worse because of aging [purchased it right after the 2009 Summer launch, while the other 3G S has been manufactured in early 2010] / heavier usage. Nevertheless, if you do count this difference in battery capacity in [31 * 1.23 = 38%], the difference in figures are still quite much.) This is one of the reasons you may want to consider upgrading to 4.3.x. Another reason is that the Full sensor mode doesn't suffer from “Clicking” at all when used under 4.3.x.

However! Under 4.3.x, you won't have live view and the focus will always be at infinity. (You can't even try re-focusing by tapping the screen where you think your subject would be shown – your tap won't be registered.)

3G S: En/disabling live view in Full Sensor mode

Incidentally, you can enable live view – and manual focusing capabilities – under 4.3.x too. Just make sure you change the default 640*480 preview size to the current Capture parameters; that is, 1080*800. This will, however, result in an absolutely useless recording – it'll “click” and freeze almost every second(!) and will often even reset your phone. That is, stay away from setting the preview size to allow live view! It simply won't work under this iOS versions.

Speaking of getting rid of live view in OS versions prior to 4.3, I've done everything to achieve this. Interestingly, these settings don't seem to have any effect on anything – unlike with the iPhone 4 in pre-4.3 OS'es. Even extremely high or low (as low as 0) values haven't resulted in the live view's changing or being disabled. This is diametrically opposed to how the iPhone 3G S behaves under 4.3.x.

3G S: Other recording modes

The (in Simple view) other recording mode, 480p, has far less power usage: about 10% (each 30 minutes). (Measured on the 4.3.3 iPhone 3G S manufactured in early 2010; on the 4.2.1 iPhone measured – and actively used since - more than half a year before, multiply the above figure by about 1.24.)

I've also benchmarked the (now-removed) 1080p mode storing its (effectively VGA-resolution) content into an XGA stream. The figure is only slightly larger than that of the iPhone 4: 14% for 30 minutes.

3G S: Why did I remove the 1080p mode from the 3G S?

I've removed this mode because, unlike on the iPhone 4, there are simply not any advantages to using it. On the iPhone 4, you have two major advantages when using any of the two 1080p modes: 1.) much wider field-of-view and 2.) much better low-light performance. (On the expense of the vastly reduced, VGA resolution, even when storing it in a XGA output file.) On the 3G S, there simply aren't any advantages compared to the stock VGA mode; consequently, I removed this mode. Either use 480p or the full-sensor mode.

iPhone 3GS: User tweaks

I've also thoroughly tested other users' tweaks. The vast majority of them either produce effectively VGA resolution video, at times, stretched or just a re-iteration of the full sensor mode, without any improvement (e.g., the lack of “clicking”). Unfortunately, Jekku's (numerous) hacks also belong to these categories. For example, his hack in his (as you can easily guess based on the post date, pre-4.3-related) November 6, 2010 at 10:48 am post HERE telling to use the sensor size of 2016×1512 and the capture size 1024*786. Unfortunately, based on my exact resolution measurements, this mode belongs to the group of (effectively) VGA -resolution videos, no matter the target (output) file's resolution. Test resolution chart videos are HERE (4.3.3) and HERE (4.2.1).

The only real improvement I run into was Fyta's (see post dated at November 2, 2010 at 11:41 pm HERE), who asked to use the sensor size of 1024*786 and the capture size (the same) 1024*786. It's of indeed somewhat better effective resolution (indeed around XGA) but nowhere as good as that of full sensor mode. There is no point in using it as it clicks heavily under both major operating systems. Under pre-4.3, it's so slow that, among other things, the “Stop shooting” tap needs several seconds to have any effect! Note that, under 4.3.3, it needs XGA preview dimensions to show live view. (But you will definitely want to stay away from it.) Test videos are HERE (4.3.3) and HERE (4.2.1).

iPhone 3G S Resolution measurements

I've previously mentioned I've run some serious resolution tests with true resolution charts. It was with the help of these tests that I've found out the “1080p” modes effectively having only VGA resolution. Please see THIS recently-published article for more info on the ISO 12233 resolution chart I used and how its shots should be scrutinized.

Let me show some real-world examples.

Full sensor mode (1.75 Mbps MOV original):



As you can see, the resolution is EXCELLENT. The lines merge at around 8, meaning about 800 lines' resolution.

Default 480p video resolution (original video HERE):



The results are quite poor: The lines merge at around 4.5-5, meaning about 450-500 lines' resolution.

The now-removed 1080p mode (original video HERE) also at 1.75 Mbps:


The results are exactly the same (despite the seemingly higher resolution because of the VGA input) and quite poor: The lines merge at around 4.5-5, meaning about 450-500 lines' resolution.

iPhone 4 Resolution measurements

I've already published the excellent(!) stock 720p results HERE, but let me show you it once again:



(iPhone4; original MOV video file HERE)

These are excellent results: the lines merge at between 7 and 8, meaning about 700-800 lines' resolution.

Let's take a look at how the full sensor mode delivers at the maximal (in Simple view, default) resolution of 1102*826 (original video HERE):



Not bad, right? Roughly the same as in 720p mode (and on the 3G S when using Full sensor mode there too).

It's also worth checking out what happens if you decrease the recording size from 1102*826 to XGA (original MOV):



As you can see, the effective resolution has decreased but really only a bit.

Finally, the two 1080p modes: one recorded at VGA and the other at the significantly larger (1024*768) XGA resolution. Try to guess which is which (as usual, I've zoomed in both the source videos to make them approximately the same size so don't pay attention to their apparent size difference)!





A hard question, isn't it? Sure it is – also emphasizing there's simply not much point in sticking with a large-format stream when the input is VGA-sized only. (I only keep the Wide-1080p-XGA format for people that really want it, while I do know it's of little use.)

Well, let me tell you: the first crop is from the higher-sized XGA stream and the second from the VGA one. Original video files HERE and HERE, respectively.

Note that the second video shows VGA resolution “1080p” recording at 1/32th of the full data rate; that is, 41015 bps. Compare it to THIS video, which is taken with the same effectively VGA input using 1/32th data rate, but, this time, encoding much larger video frames each time.

If you watch the two videos carefully, you'll see that compression artifacts abound in the XGA one while, in the VGA-resolution one, they quickly disappear after a quick movement (e.g., my re-focusing the entire scene, which I have deliberately done in every single demo video to see the effects of the [possibly] reduced data rate).

Yes, this is the main advantage of not storing VGA input in an XGA output file: you can use a far lower encoding rate for the same visual quality. What is more, importing VGA-sized movie files into, say, iMovie (which can't handle H.264 natively and, therefore, must transcode the video) will take far less time, and the list continues...

In the following (and, hopefully, final) article, I will show you more (similar) examples of different data rates. In the meantime, just stick with the rule of thumb explained above: for low-res videos (specifically the 1080p - VGA), you can use inherently less data rates than for high-res ones ([the, otherwise, not very recommended] 1080p – XGA; full sensor and the default, stock 720p).

Email icon
Want more? Get our weekly newsletter:

Werner Ruotsalainen is an iOS and Java programming lecturer who is well-versed in programming, hacking, operating systems, and programming languages. Werner tries to generate unique articles on subjects not widely discussed. Some of his articles are highly technical and are intended for other programmers and coders.

Werner also is interested in photography and videography. He is a frequent contributor to not only mobile and computing publications, but also photo and video forums. He loves swimming, skiing, going to the gym, and using his iPads. English is one of several languages he speaks.