AVAsset

Facts about AVAsset

  • Made up of “Tracks” : Could be audio or video track.
  • Provides information about the collection of audio tracks and video tracks as a whole, including title, duration, size, etc.
  • Not tied to any file format
  • Initializaing an asset doesn’t mean it’s ready to use. Therefore use a block for asynchronous usage.

A. Preparing AVAsset

1. Typical Scenario

// 1. Get File Manager
NSFileManager *filemgr = [NSFileManager defaultManager];

// 2. Get vid.mov inside tmp directory
NSString *fileName = [NSTemporaryDirectory() stringByAppendingPathComponent:@"vid.mov"];

// 3. Get a NSURL version of the filename
NSURL *url = [NSURL fileURLWithPath: fileName];

// 4. Create an asset with the URL
AVURLAsset *anAsset = [[AVURLAsset alloc] initWithURL:url options:nil];

2. Initialize for precise timing

For just playing, probably no need for passing the option. However if I want to add the asset to an AVMutableComposition, I may need to.

NSDictionary *options = @{ AVURLAssetPreferPreciseDurationAndTimingKey : @YES };
AVURLAsset *anAssetToUseInAComposition = [[AVURLAsset alloc] initWithURL:url options:options];

B. Using AVAsset

Running initWithURL:options: does not mean that the asset is prepared to be accessed. Therefore must use loadValuesAsynchronouslyForKeys:completionHandler: to access the asset asynchronously.

1. Accessing the Asset’s duration

// ..
// Continued from above...
AVURLAsset *anAsset = [[AVURLAsset alloc] initWithURL:url options:nil];
NSArray *keys = @[@"duration"];
[asset loadValuesAsynchronouslyForKeys:keys completionHandler:^() {
    // This block is run after the "duration" value is loaded
    NSError *error = nil;
    AVKeyValueStatus tracksStatus = [asset statusOfValueForKey:@"duration" error:&error];
    switch (tracksStatus) {
        case AVKeyValueStatusLoaded:
            [self updateUserInterfaceForDuration];
            break;
        case AVKeyValueStatusFailed:
            [self reportError:error forAsset:asset];
            break;
        case AVKeyValueStatusCancelled:
            // Do whatever is appropriate for cancelation.
            break;
   }
}];

2. Getting an image capture

AVAsset anAsset = <#Get an asset#>;
if ([[anAsset tracksWithMediaType:AVMediaTypeVideo] count] > 0) {
    AVAssetImageGenerator *imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:anAsset];
    // Implementation continues...
}

Getting Started With Octopress

A. Setting up

1. Clone Octopress to local machine

Clone the original octopress repo with the name I want for my blog. Running this will create an “ezrasuki.github.io” folder.

git clone git://github.com/imathis/octopress.git ezrasuki.github.io

2. Install Octopress

bundle install
rake install

3. Configure Octopress

Open _config.yml and edit some attributes I want to change.

url: ezrasuki.github.io
title: .ezra.suki.
subtitle: Adventure of Ezrasuki
author: Ezrasuki
simple_search: http://google.com/search
description:

B. Writing a post locally

From the blog root directory (In my case, the ezrasuki.github.io folder I created by cloning), run this task:

rake new_post["Hello World"]

It will create a .markdown file under source/_posts, with a name that looks like: 2013-09-07-hello-world.markdown. Open and edit so it looks something like this:

---
layout: post
title: "Hello World"
date: 2013-09-07 23:18
comments: true
categories: [Test, Helloworld]
---

This is the content. You can write in markdown.

Note that “categories” are basically tags.

C. Preview blog

When done, generate HTML from the markdown with:

rake generate

To preview the post locally, run the following command, which will start a http://localhost:4000 server you can visit.

rake preview

C. Deploy to Github

There are many options for hosting, but I am hosting it on Github because it’s free.

1. Create a Github repo

Create a repo with the name of your blog. It should look like this: [your github username].github.io. Mine is ezrasuki.github.io

2. Connect Octopress with the Github repo

Octopress has a rake command which automatically takes care of all this. Run:

rake setup_github_pages

It will ask you the github repo url. Copy the clone URL from the Github repo and paste it here. It should look something like https://github.com/ezrasuki/ezrasuki.github.io.git.

3. Deploy

A. Deploy generated blog files

Finally, deploy all the local changes (including the new post) to Github pages repo by running:

rake deploy

B. Deploy source files

This only deploys the master branch, which contains the generated blog content. You may also want to push the source branch. The source branch contains everything except for the generated blog files. This includes: 1. Octopress source code 2. Markdown files for posts

Therefore it is a good idea to commit these too, in order to keep track of this side as well. Run the following:

git commit -am "Committing source"
git push origin source

Note that git push origin master has been already executed automatically when we ran rake deploy earlier. Again, that was for pushing the final static content. And this time, git push origin source is for pushing the source files.

AVFoundation Overview

What is AVFoundation?

  1. AVAsset

Core Image Basics

Core Image provides a mechanism for filtering and manipulating images and videos. Think Instagram filter effects.

Example filters

  • cropping
  • color effects
  • blurring
  • warping
  • transformations
  • gradients

Take a CIImage and apply CIFilter to draw on CIContext

Example

// 1. Get a CIImage
CIImage *image = [CIImage imageWithContentsOfURL:myURL];

// 2. Create a CIFilter
CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"];

// 3. Apply the filter to the image
[filter setValue:image forKey:kCIInputImageKey];

// 4. More CIFilter customization
[filter setValue:[NSNumber numberWithFloat:0.8f] forKey:@"InputIntensity"];

// 5. Get the resulting image from CIFilter
CIImage *result = [filter valueForKey:kCIOutputImageKey];

// 6. Create CIContext
CIContext *context = [CIContext contextWithOptions:nil];

// 7. Finally, render CIImage onto Core Graphics Image, which then can be displayed or saved.
CGImageRef cgImage = [context createCGImage:result fromRect:[result extent];

// 8. Convert CGImage to UIImage, so we can draw it onto view
UIImage *resultUIImage = [UIImage imageWithCGImage: cgImage];

// 9. Get the CGRect to draw on
CGRect imageRect =[[UIScreen mainScreen] bounds];

// 10. Draw the UIImage onto the CGRect region
[resultUIImage drawInRect:imageRect];

Hello World

Hello World

Blockquote example

This is an example of a blockquote.

This is the first post This is a link


Image Example

image example placeholder


Code Example

This is an example of a javascript code

var sayHello = function(){
  for(var j = 0; j < 100 ; j++){
      console.log("Hello World " + j);
  }
}