Java: Guide to write a custom video codec

Tony Bogdanov picture Tony Bogdanov · Apr 11, 2012 · Viewed 13.7k times · Source

I have quite a weird question, but here it is:

Is it possible, and are there any guides for writing a custom video codec in C++ or Java?

Here's the weird part: I don't need to dive into those tons of info about audio and motion picture I don't understand. What I actually need is the technical stuff behind how to make a software layer between a movie player and a movie file.

Here's why: I would like to create a library or ultimately 2 functions - encode / decode - in C++ / Java, which will take the RAW binary input of any type of file and encode / decode it according to a given password or something like that. Then I need to put this processing between a movie player and a movie file. The final result will be a password protected mp4 / avi / mpeg / wmv (doesn't really matter) file, that could be played only with this "codec". The internal logic of the codec is not the issue right now.

How I imagine it is like a stream, movie player request the file and calls my encode() function, it takes a chunk of the file, decodes it (it has been previously encoded) and returns the correct bytes in wmv/mp4 and so on format.

Is any of this possible and how?

Answer

Elnaz picture Elnaz · Apr 12, 2012

A codec generally takes image blocks and context information, transforms and quantizes the data, applies predictions, then encodes the resulting error stream using one of any number of coding schemes.

The API is usually simple. For encode, you send blocks of image data (frames) to the encoder, and it generates a stream of bits. You may be responsible for writing the container (file format) yourself. For decode, you stream bits in and frames come out.

There is absolutely no standard to any of this -- the technologies used in the codecs are sometimes standardised, but the exact interfaces are not.

MediaTool Introduction is a simple Application Programming Interface (API) for decoding, encoding and modifying video in Java: http://wiki.xuggle.com/MediaTool_Introduction#How%5FTo%5FTake%5FSnapshots%5FOf%5FYour%5FDesktop

Java Media frame work tutorial: http://wwwinfo.deis.unical.it/fortino/teaching/gdmi0708/materiale/jmf2_0-guide.pdf

maybe helps you!