Вот подробно описано:
http://dimonvideo.ru/articles/1683