Archive for the ‘iPhone’ Category

Using FFMpeg to Encode Movies for the iPhone

Tuesday, December 30th, 2008

FFmpeg (http://www.ffmpeg.org/) is a great tool for encoding movies in any format and works nicely for encoding movies for the iPhone. The main issue we ran into was finding the right parameters for FFMpeg. As is the case with most open source projects, the documentation for FFMpeg is sparse. From Apple’s documentation we knew the specifications for encoding were:

  • MP4 file format
  • H.264 Baseline Profile Level 3.0 video, up to 640 x 480 at 30 fps. Note that B frames are not supported in the Baseline profile.
  • MPEG-4 Part 2 video (Simple Profile)

Our own requirements were to produce two encodings, a full size one for the web and a secondary one that was optimized for the iPhone. We tried several different combinations, gathered from various forums and blogs, before we were able to find the right set. The parameters that worked successfully for us are:

/usr/local/bin/ffmpeg -i $INPUT -acodec libfaac -vcodec libx264 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +mixed_refs -me_method umh -subq 5 -trellis 1 -refs 5 -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bufsize 2M -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 13 -vb 1500k -ab 128k $OUTPUT_WEB -vcodec libx264 -s 480x320 -ab 64k -vb 480k $OUTPUT_IPHONE

DivX Component for QuickTime not compatible with iPhone Simulator

Tuesday, December 30th, 2008

If you updated your iPhone SDK to 2.2 and find that movies no longer play in the iPhone Simulator, it is probably because of the QuickTime DivX component. With the most recent SDK (2.2) this particular component is incompatible with the iPhone Movie Player. You will likely see a message like:

[code lang="objc"]Error loading /Library/QuickTime/DivX Decoder.component/Contents/MacOS/DivX Decoder:  dlopen(/Library/QuickTime/DivX Decoder.component/Contents/MacOS/DivX Decoder, 262): Symbol not found: _SCDynamicStoreCopyConsoleUser

Referenced from: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/LangAnalysis.framework/Versions/A/LangAnalysis

Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.sdk/System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration[/code]

Unfortunaltely, the only way to fix this is to delete the two offending files: DivXEncoder and DivXDecoder. These files should be in /Library/QuickTime

If you are still having trouble playing movie files, check that the file format is mp4 and conforms to the following specification (from Apple’s documentation for MPMoviePlayerController):

  • H.264 Baseline Profile Level 3.0 video, up to 640 x 480 at 30 fps. Note that B frames are not supported in the Baseline profile
  • MPEG-4 Part 2 video (Simple Profile)

Provisioning Profiles on the iPhone

Wednesday, December 10th, 2008

Setting up XCode correctly with the provisioning profiles turns out to be more difficult that it ought to be. The most confusing aspect is that the configuration settings need to be identical for both the project and the target. To get to the project level settings you would right click on the project and select “Get Info”. Similarly, to get to the target level settings you would right click on the target and select “Get Info”. Three of the crucial steps are:

  1. Set the Base SDK property to the latest
  2. Choose the correct provisioning profile for both the “Code Signing Identity” and the “iPhone OS Device”
  3. Make sure you are updating settings for the configuration you want to use i.e. Debug, Release or Distribution. These options can be chosen from the top left drop down in the settings panel. For example, you would typically have a separate provisioning profile for distribution and you should choose this for the code signing property value
  4. Copy the chosen provisioning profile to the device on which you are attempting to install the application

Some other things to keep in mind are: a value for “Code Signing Resource Rules Path” is no longer required if the base SDK is 2.2! Adding a value for this property for SDK 2.2 results in an error during install.

Finally, there are two steps to correctly set up the provisioning profile on the device

  1. Download the provisioning profile from your iPhone portal to your mac and drop it on to iTunes. It should automatically be copied over to ~/Library/MobileDevices/Provisioning Profiles
  2. Also, copy it to each device on which you want to install the application through the Organizer in XCode