How to study objective C under windows

October 6, 2010
Screenshot of Cygwin

Image via Wikipedia

Objective C seems to gain popularity nowadays. My only exposure to this language is through random snippets I saw here and there, mostly written by friends of mine, chasing the dream of becoming the next iPhone millionaire. And I have to say: I find it ugly. I mean really really ugly!

People say though, that once you get used to it, it seems natural and it has advantages (read: late binding) that make it a powerful tool for creating applications.

Well, after all its just another programming language. So I thought I’d give it a try.  Preferably without owning a mac.

Here is how I did it:

  • Download cygwin – install it with the default settings.
  • That’s about it! Cygwin comes with an objective C compiler, so you are good to go once you install it.

How to write a first objective c test program:

#import <stdio.h>
int main(int argc, char *argv[]) {
    printf("Hello, from objC!\n"); 
}

Create a file named “hello.m” in your cygwin home directory containing the above code. Then open a cygwin prompt and write the command: gcc -o hello hello.m

And there you have it, a free development environment to try out the language. Your next step (pun intended) might be a good tutorial or a book describing the language. I suggest something that covers the language only, not the common APIs (GNUstep, Cocoa, whatever). If you think you can stand the language itself, you can then try to learn the APIs and create that iPhone app you were dreaming about!


How to seek to the end of a video stream using ffmpeg

October 6, 2010
FFmpeg

Image via Wikipedia

This was really simple, but took me about a day to find out. A google search didn’t help this time so I post it here and maybe it is going to help someone else.

It turns out that the format context has a handy member: duration. This may or may not be valid, so it needs to be checked before using it. The following two lines of code will do the trick:

av_seek_frame(pFormatCtx, -1, pFormatCtx->duration, 0);
avcodec_flush_buffers(pCodecCtx);

When using -1 as a stream index, the time is measured in ffmpeg’s time base, which is the same unit the duration member is in.


Follow

Get every new post delivered to your Inbox.