Tuesday, September 20, 2011

App Store Tip


HTTP Live Streaming in iOS


HTTP Live Streaming is a streaming standard proposed by Apple. See draft 5.
Files involved are
  • .m4a for audio (if you want a stream of audio only).
  • .ts for video. This is a MPEG-2 transport, usually with a h.264/AAC payload. It contains 10 seconds of video and it is created by splitting your original video file, or by converting live video.
  • .m3u8 for the playlist. This is a UTF-8 version of the WinAmp format.
Even when it's called live streaming, usually there is a delay of one minute or so during which the video is converted, the ts and m3u8 files written, and your client refresh the m3u8 file.
All these files are static files on your server. But in live events, more .ts files are added, and the m3u8 file is updated.
Since you tagged this question iOS it is relevant to mention related App Store rules:
  • You can only use progressive download for videos smaller than 10 minutes or 5 MB every 5 minutes. Otherwise you must use HTTP Live Streaming.
  • If you use HTTP Live Streaming you must provide at least one stream at 64 Kbps or lower bandwidth (the low-bandwidth stream may be audio-only or audio with a still image).

Example

Get the streaming tools

To download the HTTP Live Streaming Tools do this:
Command line tools installed:

 /usr/bin/mediastreamsegmenter
 
/usr/bin/mediafilesegmenter
 
/usr/bin/variantplaylistcreator
 
/usr/bin/mediastreamvalidator
 
/usr/bin/id3taggenerator

Descriptions from the man page:
  • Media Stream Segmenter: Create segments from MPEG-2 Transport streams for HTTP Live Streaming.
  • Media File Segmenter: Create segments for HTTP Live Streaming from media files.
  • Variant Playlist Creator: Create playlist for stream switching from HTTP Live streaming segments created by mediafilesegmenter.
  • Media Stream Validator: Validates HTTP Live Streaming streams and servers.
  • ID3 Tag Generator: Create ID3 tags.

Create the video

Install Macports, go to the terminal and sudo port install ffmpeg. Then convert the video to transport stream (.ts) using this FFMpeg script:

# bitrate, width, and height, you may want to change this
BR
=512k
WIDTH
=432
HEIGHT
=240
input
=${1}
# strip off the file extension
output
=$(echo ${input} | sed 's/\..*//' )
# works for most videos
ffmpeg
-y -i ${input} -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -s ${WIDTH}x${HEIGHT} -vcodec libx264 -b ${BR} -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 7 -trellis 0 -refs 0 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -maxrate ${BR} -bufsize ${BR} -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 30 -qmax 51 -qdiff 4 -level 30 -aspect ${WIDTH}:${HEIGHT} -g 30 -async 2 ${output}-iphone.ts

This will generate one .ts file. Now we need to split the files in segments and create a playlist containing all those files. We can use Apple's mediafilesegmenter for this:
mediafilesegmenter -t 10 myvideo-iphone.ts
This will generate one .ts file for each 10 seconds of the video plus a .m3u8 file pointing to all of them.

Setup a web server

To play a .m3u8 on iOS we point to the file with mobile safari. Of course, first we need to put them on a web server. For Safari (or other player) to recognize the ts files, we need to add its MIME types. In Apache:

 AddType application/x-mpegURL m3u8
 
AddType video/MP2T ts

In lighttpd:

 mimetype.assign = ( ".m3u8" => "application/x-mpegURL", ".ts" => "video/MP2T" )

To link this from a web page:

<html>
<head>
   
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
</head>
<body>
   
<video width="320" height="240" src="stream.m3u8" />
</body>
</html>

Wednesday, August 31, 2011

Xcode and #pragma mark


#pragma mark directives in code to help with organization as implementation files grow.
#pragma mark is simple to use,

for example, insert the following to call out initialization code:


#pragma mark -

#pragma mark Initialization


Once this is in place, the Functions Menu (in the navigation bar) which shows a list of locations within a source file (e.g. definitions of classes, functions and methods) will display a new marker with the label "Initialization." The code in line 1 will add a line separator inside the Functions Menu, in this example, with the line appearing above the "Initialization" marker.

The figure that follows shows an example of how you might use #pragma mark to divide up various sections of your code.



Two notes:
  1. You cannot have a space after the "-" in the #pragma mark -

  2. If your code does not appear as expected (e.g. the separator does not appear), check that ‘Sort list alphabetically’ is not checked in the Code Sense preference settings.

Tuesday, August 23, 2011

How To Install iOS 5 (Beta) On Your iPhone, iPad or iPod Touch? (Developers Only)


imagesfdsf1 How To Install iOS 5 (Beta) On Your iPhone, iPad or iPod Touch? (Developers Only)
iOS 5 beta is now available for developers to install on their iPhone, iPad or iPod touch devices. 

How to install iOS 5 beta?

1) Head to Apple Developer Center and open iOS Dev Center page.
2) Click on iOS Beta SDK link.
3) Download “Xcode and iOS SDK 5 Beta ” and install it.
4) Download “iTunes 10.5 Beta” and install it.
5) Download “iOS 5 beta (x)” – iPhone, iPad and iPod Touches have own iOS 5 beta files, so download the that suits your devices.
6) Plugin your device to your Mac.
7) Take backup of your data in iTunes 10.5 beta If you haven’t already done this before.

Register your iPhone/iPad/iPodTouch: If you haven’t already registered your devices with Apple Developer iOS Provisioning Portal then first you have to register your device. Just go to “Provisioning Portal” on Apple Developer portal and click on “Devices” to add your devices.

9) Now run the iOS 5 beta file that you downloaded. (It ends with .dmg). It will show the file that ends with *.ipsw. For now just remember where the file exists.
10) Open XCode. Open “Organizer” within XCode. Window -> Organizer
11) On the left part of window you will see your device. Select it. If it’s not already in development mode, you will see option to “Use for Development”.
12) Click on “Software Version”, Select “Others” and select the iOS 5 beta file that ends with “*.ipsw” extension.

Screen shot 2011 06 07 at 1.49.51 PM 300x129 How To Install iOS 5 (Beta) On Your iPhone, iPad or iPod Touch? (Developers Only)

13) Now click on “Restore ”
14) It will take few minutes and your device will be ready to use with iOS 5

How to Install iOS 5 Beta on the iPhone Without Apple Dev Account



A Gizmodo reader has discovered a “backdoor” that allows you to install iOS 5 on the iPhone and enjoy all of its features without having to register its UDID with Apple first…
This workaround takes advantage of a Voice Over security flaw within the activation screen. Here’s how to do it:

First, you’ll need the iOS 5 firmware, which you’ll find with a quick Google search. Now, update your device in iTunes by holding the ‘Option’ key while you click the ‘Check for Update’ button, then select your iOS 5 IPSW file. When your device reboots, you’ll be greeted by a new activation screen.

Now follow these steps:
1. Triple click the home button. This will activate Voice Over.
2. Triple click the home button and Emergency Call will appear.
3. Click on Emergency Call and, while it’s switching, swipe your three fingers down.
4. The Notification Center will appear!
5. Click on the Weather widget. The Weather app will load.
6. Click on the home button to exit to the iPhone’s springboard.
Your device should now be activated and fully functional with the iOS 5 firmware.
While this is incredibly cool, and a great way to get your hands on iOS 5 early, we don’t recommend you try this on your primary device. If anything goes wrong, you’re stuck with an iOS 5 beta that you can’t activate, and an iOS device that will be nothing more than an expensive paperweight until this Fall.

Monday, August 8, 2011

How to Play Video in iPhoneOS4


Step 1: Create a View base application using template. Give the application name “VideoPlayiPhoneOS4”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the VideoPlayiPhoneOS4ViewController class for you. Expand Resources and notice the template generated a separate nib,VideoPlayiPhoneOS4ViewController.xib, for the “VideoPlayiPhoneOS4”.

Step 4: We need to add MediaPlayer.framework in the Frameworks folder. Select-> Frameworks folder -> Add ->Existing Frameworks -> then select MediaPlayer.framework.

Step 5: In the VideoPlayiPhoneOS4ViewController.h file , we have created instance of MPMoviePlayerController class, that manage the playback of a movie from a file or from the network, and create a instance of NSURL class . So make the following changes in the file.

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface VideoPlayiPhoneOS4ViewController : UIViewController {
    MPMoviePlayerController *moviePlayer;
        NSURL *movieURL;
       
}

Step 6: Open the VideoPlayiPhoneOS4ViewController.m file and make the following changes:

-(void)viewWillAppear:(BOOL)animated
{
        NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil];
        NSURL *url = [NSURL fileURLWithPath:urlStr];
        moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
        [self.view addSubview:moviePlayer.view];
        moviePlayer.view.frame = CGRectMake(0, 0, 300, 400);
        [moviePlayer play];
}

Step 7: Now compile and run the application in the Simulator.



You can Download SourceCode from here VideoPlayiPhoneOS4

Friday, July 29, 2011

ICloud APIs



iCloud storage APIs allow IOS application developers to store documents and other data to a central location so users can view or edit from any device without having to sync or transfer files.

There are two ways that applications can take advantage of iCloud storage:
  • Document Storage – Enabling storage and sharing of information in document form.
  • Key-Value Data Storage – Enabling storage and sharing small amounts of data.
Most applications will use iCloud document storage to share documents, which is a feature that users think of when they think of cloud storage. Users care about whether photos, videos, and documents are accessible across devices while the key-value data store is not something a user would never see.
Key-value storage will be used for small amounts of data such as storing application state, settings, and other important information that delivers a better user experience. Although not as apparent to the end-user, key-value storage will be just as important as document storage.
All iCloud storage is managed centrally by the iCloud service, which handles coordination of documents and key-value stores. The iCloud service handles storage searches, change notifications, version control, conflicts, and security for applications that integrate with a user’s iCloud storage account.
Neither document storage or key-value storage in the cloud are anything new. But when it is implemented as part of the IOS platform, it becomes much bigger. Apple is solving everyday problems users face when using their smart phones, by storing data centrally in the cloud.
ICloud APIs will enable developers to build rich applications on the IOS platform, and continue to grow IOS market share.