Thread: Creating Video Encoder/Decoder Question

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    34

    Creating Video Encoder/Decoder Question

    Hi guys,

    I wanted to create a programs that encode and decode videos using existing codecs (h.264, xvid, etc...), but I couldn't find much information on the web.

    So how does such program work? So internally, is codec like a compression standard like ZIP and RAR, and encoding and decoding work similar to how files are compressed and extracted?

    I was wondering if the codec publishers provide APIs for encoding/decoding (if so then in what language), or if us developers have to come up with our own. So if I understand it correctly, I think the codec is a component that already implements mathematical algorithm, and we can simplly use the implemented algorithm to create Video encoder or Video player, right?

    I have limited knowledge on the subject, but I would love to ramp up on it more, so I'd appreciate if people with on the subject could point me to the right resouces. Thanks!
    Last edited by chiefmonkey; 05-07-2009 at 10:24 AM.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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 standardized, but the exact interfaces are not.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    the are some open source codecs that you can download from web to look at the source code.

    you can take a look at the VirtualDub application which source is available for download, this application is able to decode/encode a lot of existing file/media formats

    about standard API - there is one for codecs that are installed on windows to be used with DirectX technology... Codecs libraries/SDK that are not targeted to this specific platform could expose any API they think suitable. In most cases it is C or C++ set of APIs that include:
    - Library initialization routine
    - Codec selection (for multi-codec SDKs)
    - Specific codec initialization (like memory allocation according to the maximum frame size, h264 decoder configuration based on the VosVol info etc)
    - Frame writing routine (some need to receive the whole frame, some codecs are ready to receive partial frames as soon as each part is available to the application)
    - Frame ready callback if encoding/decoding is implemented asynchronously
    - Deinitialization routines

    Encoders can/should additionally provide some API for additional online configuration (during the encoding) like bandwidth control, VideoFastUpdate picture request etc
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I do not suggest VirtualDub since it uses the outdated VFW.
    Most applications today, for Windows, uses DirectShow means which means you would have to write a DirectShow filter. There are examples of tutorials of that, I believe, in the platform sdk.
    Any encoder/decoder should probably be written in C/C++ since they are time consuming tasks and benefit greatly from the speed C and C++ delivers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Elysia View Post
    Any encoder/decoder should probably be written in C/C++ since they are time consuming tasks and benefit greatly from the speed C and C++ delivers.
    You forgot to add "any software encoder/decoder"... because encoder/decoder targeted for hardware chips will hardly use assembler of the specific chip
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Oh, right. Any hardware encoder will have to use whatever language is available. Typically assembler, C or C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Apr 2009
    Posts
    34
    Awesome, thank you guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Creating a file with random numbers question??
    By Hoser83 in forum C Programming
    Replies: 28
    Last Post: 02-16-2006, 02:11 PM
  3. simple question on creating a window
    By black in forum Windows Programming
    Replies: 5
    Last Post: 12-29-2005, 12:10 PM
  4. I have a video question
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 02-15-2003, 10:13 PM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM