Sažetak


Video koder je program koji seriju slika komprimira u jednu datoteku. Najpopularniji koderi su tzv. lossy koderi koji koriste karakteristike ljudskog vida kako bi postigli što manju veličinu konačne datoteke uz što manje žrtvovanje kvalitete slike. Theora koder je jedan od takvih te se po kvaliteti uspoređuje za MPEG4 koderom.

Theora koder koristi YUV sustav boja koji je pogodan za komprimiranje slike no javlja se potreba za pretvaranjem u RGB sustav boja kako bi se slika mogla koristiti na teksturi na grafičkom sklopovlju.
Postupak pretvorbe je složen i dugotrajan te je potrebno uvesti razne optimizacije.
Uvedeno je korištenje cjelobrojnih operacija umjesto operacija sa pomičnim zarezom te binarno ograničavanje pretvorenih vrijednosti u rasponu [0,255].
Dodatno je moguće ubrzati pretvorbu koristeći program za sjenčanje slikovnih elemenata no takvo što grafičko sklopovlje mora podržavati.

Pošto Theora koder zapisuje slike kao razlike u odnosu na prošlu sliku, nije moguće predvidjeti vrijeme potrebno za dekodiranje slike što otežava prikaz u glavnoj dretvi te može dovesti do odbacivanja slika.
Stoga je bilo potrebno odvojiti proces dekodiranja od procesa prikaza na način da se dekodiranje preseli na drugu dretvu što je izrazito praktično ukoliko su operacijskom sustavu dostupni više od jednog procesora.

Zbog sikronizacije i glatkog prikaza bilo je potrebo uvesti priručni spremnik slika u koji dekoderska dretva unaprijed dekodira i pohranjuje slike dok glavna dretva po potrebi dohvaća dekodirane slike i prikazuje ih na teksturi.

Ukoliko video datoteka sadrži audio zapis, trenutna pozicija reproduciranog zapisa se može koristiti za sikronizaciju prikaza slika. U protivnom se koristi obični brojač vremena.

Theora zapis ne sadrži informacije o pozicijama ključnih slika stoga ako korisnik želi preskočiti N sekundi potrebno je pronaći odgovarajuću ključnu sliku korištenjem binarnog pretraživanja.

Program je dizajniran tako da ne ovisi o bilo kojem sustavu prikaza stoga mu je spektar primjene izrazito širok. Dosad se koristio u par komercijalnih projekata te sa svim kvalitetama predviđa se dobra iskoristivost projekta u budućnosti.

Abstract


A video codec is a program that compresses a series of images into one larger file. The most popular codecs are so-called lossy codecs which encode video having in mind the characteristics of human vision to achieve the best possible quality vs. compression ratio. Theora codec is one of them and is often compared to MPEG4 by this ratio.
The Theora codec uses the YUV color system which is best suited for image compression. This however causes problems with display systems that support only RGB, and therefore a conversion method must be introduced.

The YUV --> RGB conversion process is complex, time expensive and requires lots of optimizations on a lower level.
In this program, floating point operations in the conversion process have been replaced with integer operations and bitwise operations were used to clamp the converted values to [0,255] range.
It is possible to further optimize this process by using hardware accelerated fragment shaders but not all systems support them.

Since theora codec encodes frames as differences from the previously displayed frame, it is not possible to predict how long it will take to decode a given image which complicates linear frame display in the main thread and causes a lot of dropped frames.
Therefore it was necessary to separate the decoding process from the frame displaying process by separating the decoding to another processing thread. This becomes especially useful if the operating system has access to more then one processor.

Due to synchronization issues and smooth frame display it was necessary to introduce a frame cache buffer that the decoding thread fills by decoding frames in advance while the main display thread fetches frames one by one and displays them.
If the OGG file contains audio data, the current playback location can be used for A/V synchronization. Otherwise a simple timer object will do.
The Theora bit-stream doesn't contain key-frame position information so if the user wants to fast-forward through a video, the system has to find the desired frame by using a bisection search.
The program is designed to be system independent so it can be used regardless of the displaying system used (OpenGL, DirectX, SDL, X11 etc.) and therefore it's potential usage is very promising.
So far it has been used in several commercial project and having all it's features in mind, it is likely it will be used in many more projects.