Calling video CODEC


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Calling video CODEC

  1. #1
    Johan Stäck Guest

    Calling video CODEC

    Hello,

    How can I call a video CODEC directly?
    I want to give the codec the adress of an uncompressed bitmap end get back
    the adress of the compressed result.
    Vice versa for decompression.

    Actually, I do have a way to do decompression, since DrawDibDraw will
    decompress "on-the-fly".

    Greetings,

    Johan Stäck
    Skellefteå, Sweden



  2. #2
    Mike D Sutton Guest

    Re: Calling video CODEC

    > How can I call a video CODEC directly?
    > I want to give the codec the adress of an uncompressed bitmap end get

    back
    > the adress of the compressed result.
    > Vice versa for decompression.
    >
    > Actually, I do have a way to do decompression, since DrawDibDraw will
    > decompress "on-the-fly".


    I've done some quick research on this and found that the codec list is
    stored in the registry key:
    My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
    NT\CurrentVersion\Drivers32\
    which gives you the .dll names for each codec (This is under Win2K, I'd
    imagine that on Win9* (And WinME?) that it would be in "Windows" rather than
    "Windows NT".) The drivers.desc node off the same parent gives you the
    "Friendly names" of each codecs should you need to display them in an option
    list or such like.
    The paths of the DLL's seem to be located in:
    My Computer\HKEY_CLASSES_ROOT\CLSID\{--GUID--}\InprocServer32\
    Each in a different {--GUID--} directory however at least on this system
    them seem to (all?) be located in:
    WINNT\System32\
    And again on Non-NT Os' I'd imagine this to be "Windows\System\".
    Using the dependency walker I had a look through a number of codecs
    installed here and they all have a DriverProc() method which looks like the
    driver/codec version of WindowProc() in a Win32 application. A number of
    them also have encore() and decore() methods however it looks like these are
    only on MPEG based codecs(?).
    DriverProc() turned up some results on search engines and here's a few
    selected links but there's plenty more for you to research:

    Information on how to write a DriverProc():
    http://msdn.microsoft.com/library/de...us/multimed/in
    stdrv_6o4u.asp

    Information on how to call a DriverProc():
    http://msdn.microsoft.com/library/de...us/multimed/in
    stdrv_8q03.asp

    How to call Lead video's codec directly (Method may apply to other codecs
    also):
    http://www.leadtools.com/video-codec_API.htm

    You may want to check out some of the open source codec's about since they
    will give you an under-the-hood view and maybe expose some further
    information on how to use them. Also, if you find any further information
    on the subject I'd be interested on having a copy either.
    Hope this helps,

    Mike


    P.s: None of this is confirmed so don't quote it or flame if I got something
    wrong, this is just a starting point for your research.

    -- EDais --

    - Microsoft Visual Basic MVP -
    WWW: Http://EDais.earlsoft.co.uk/
    Work E-Mail: EDais@btclick.com
    Other E-Mail: Mike.Sutton@btclick.com



  3. #3
    Johan Stäck Guest

    Re: Calling video CODEC

    Mike,

    Thank you for helping!
    After some more research I think that I have found a way.
    It seems that the SDK offers the functionality that I need through functions
    such as
    ICOpen, ICCompress etc.

    The reason for my attempts to handle compression directly is that I will try
    to use my own file format instad of .AVI for a project.
    I want to store certain pieces of information along with each frame, and I
    don't think that I can solve it by using additional streams in an AVI file.

    /Johan



  4. #4
    Mike D Sutton Guest

    Re: Calling video CODEC

    > Thank you for helping!

    You're welcome

    > After some more research I think that I have found a way.
    > It seems that the SDK offers the functionality that I need through

    functions
    > such as
    > ICOpen, ICCompress etc.
    >
    > The reason for my attempts to handle compression directly is that I will

    try
    > to use my own file format instad of .AVI for a project.
    > I want to store certain pieces of information along with each frame, and I
    > don't think that I can solve it by using additional streams in an AVI

    file.

    Be careful when making yet another format though since if it's not
    mainstream then it's going to be a hassle for others to use your format
    since it's hardly supported (Other than your own application) especially if
    all you're effectively doing is wrapping an AVI file. As far as I see it,
    the AVI fill is just the same as the old IFF format and as such based on
    chunks of data -When a file parser reaches a data chunk it doesn't
    understand then it should just skip over it, any players that don't are
    written incorrectly and thus their problem not yours. Due to this chunked
    approach, you should in theory be able to put any amount of extra data in
    the file as you need (Providing it's correctly sequenced, I.e. one chunk
    every frame even if it's 0-length) in whatever format you need, subtitles
    would be an obvious example here, it's just up to the player to work out
    what it should do with these extra frames.
    If the SDK doesn't support more streams then the AVI format is dead easy
    (Especially if you've done IFF work previously) and it wouldn't be difficult
    to interleave your own data into an existing file (Or writing the whole
    thing from scratch). See Http://www.wotsit.org/ for the format
    specification, and there's an AVI info class on my site that parses through
    an AVI file in binary mode which should give you something to work from.
    Hope this helps,

    Mike


    -- EDais --

    - Microsoft Visual Basic MVP -
    WWW: Http://EDais.earlsoft.co.uk/
    Work E-Mail: EDais@btclick.com
    Other E-Mail: Mike.Sutton@btclick.com



  5. #5
    Johan Stäck Guest

    Re: Calling video CODEC

    Thanks Mike,

    I have been busy the last days trying to understand the AVI (RIFF) file
    format.
    Combining some existing AVI files, a hex editor and availible documentation
    I am slowly beginning to understand...

    What I want to do is:
    For every video frame (could be DV frames, but perhaps also encoded with
    other codecs..) I want to have a piece of numerical (perhaps also text)
    data.
    This additional data will be added/modified after the video is originally
    written.

    I feel fairly confident that I can handle this using a proprietary file
    format, but I am still not sure if AVI can do it.
    Or rather: if there are Windows AVI file functions that can do it.
    If I embark on the AVI route, how could I store this extra data associated
    with each frame?

    Regarding my original problem with calling video codecs, I have made some
    progress.
    I have successfully managed to compress a DIB using ICImageCompress.
    At least I *think* I have succeeded, since I now get a BITMAPINFO struct
    with very reasonable contents.
    Took me a while though since what you get from ICImageCompress is a
    *handle*, and it took me some dirty VB programming to take care of that.

    I am now trying to get ICImageDecompress to decompress the result from
    ICImageCompress, so far without success.
    All I seem to get is 0 instead of a valid handle...

    /Johan



  6. #6
    Mike D Sutton Guest

    Re: Calling video CODEC

    > I have been busy the last days trying to understand the AVI (RIFF) file
    > format.
    > Combining some existing AVI files, a hex editor and availible

    documentation
    > I am slowly beginning to understand...
    >
    > What I want to do is:
    > For every video frame (could be DV frames, but perhaps also encoded with
    > other codecs..) I want to have a piece of numerical (perhaps also text)
    > data.
    > This additional data will be added/modified after the video is originally
    > written.
    >
    > I feel fairly confident that I can handle this using a proprietary file
    > format, but I am still not sure if AVI can do it.
    > Or rather: if there are Windows AVI file functions that can do it.
    > If I embark on the AVI route, how could I store this extra data associated
    > with each frame?


    Fire up your hex editor and have a look at the header of an AVI file,
    preferably one with both audio and video so you can see the similar patterns
    in the stream headers.
    Make sure that it is indeed an AVI file by checking the first 12 bytes, they
    should be "RIFF####AVI " (Last char after "AVI" is a space (0x20)) where
    #### is any number (Basically the file size, but a little off due to padding
    and headers)
    Once you've got that you're looking for a stream list "LIST####strl" and if
    you've got both audio and video then there should be (At least) two although
    there may be a big JUNK (Or JUNQ in the case of Adobe Premiere) tag
    in-between to align it to a 2K boundary.
    This list defines information about a stream within the file, the common two
    are "vids" and "auds" for video and audio respectively and you can find
    which you're looking at by checking out the stream header "strh###XXXX"
    which comes right after the stream list and XXXX is the stream type. After
    that comes data specific to the stream type then you get the stream format
    chunk "strf####" which again is specific to the stream type; in the case of
    video you get a BITMAPINFO structure and with audio you get a WAVEFORMAT
    structure.
    Fast forward now down to the movie list "LIST####movi" which defines the
    start of the movie (If you have any trouble finding it, the AVIInfo app on
    my site reports this for you)
    You should then see something like ##db, ##dc, ##pc or ##wb (Sometimes
    they're bracketed into a "LIST####rec " structure though, just to make your
    life difficult
    The ## of these movie chunks is the stream number and the 2 char suffix is
    the stream type (Largely useless since you know what the stream type is from
    the header, but we have to keep it in there for consistency's sake.)
    Finally you'll need to know about the index chunk, "idx1####" which is
    located at the bottom of the file and points to offsets in the AVI file for
    each frame which AVI players use to seek quickly (Although sometimes not
    really that quickly, huh, Media player...) through the file. Here you'll
    just find the same chunk header as in the movi list such as "dc01" or "wb01"
    followed by the flags for this chunk, the chunk offset and finally the chunk
    length all as DWords.

    So, in theory all you should need to do to interleave your own stream data
    into the file is:
    1) Add a new stream list, stream header, stream format and aligning JUNK tag
    to the header defining whatever information you need to about the file.
    2) Read the index into an array for easy access since you'll be making a lot
    of incremental modifications to it, leave spaces for your own stream chunks
    too.
    3) Iterate through the movie frames and insert a frame chunk of your own
    stream where it's needed and offset any following chunks in the index by the
    size of the frame. Remember to insert offsets to your own frames into the
    index also with corresponding offsets and sizes (The offset will just be the
    next chunk from where you are now since you've not offset it yet.)
    Keep track of the total number of bytes you've added to the file.
    4) Write the file out making sure to change the various chunk sizes
    otherwise parsers and players will have problems traversing the file.

    It sounds like a lot but it's not really, thankfully the IFF format is very
    logical and easy to manipulate, if I've missed anything out then the format
    specification should be able to fill in the gaps, if not then give me a
    should and I'll have a dig around and see what I can come up with.

    > Regarding my original problem with calling video codecs, I have made some
    > progress.
    > I have successfully managed to compress a DIB using ICImageCompress.
    > At least I *think* I have succeeded, since I now get a BITMAPINFO struct
    > with very reasonable contents.
    > Took me a while though since what you get from ICImageCompress is a
    > *handle*, and it took me some dirty VB programming to take care of that.
    >
    > I am now trying to get ICImageDecompress to decompress the result from
    > ICImageCompress, so far without success.
    > All I seem to get is 0 instead of a valid handle...


    Unfortunately I've not done any VFW programming before so I can't really
    help you there however I'm sure Dean or Ray (Amongst others) could probably
    offer more assistance in that area. The specification does mention some API
    methods though which may be worth looking into however I'd expect it to
    probably be very old so I'd not be sure on how much of it is still supported
    or used.
    Hope this helps,

    Mike


    -- EDais --

    - Microsoft Visual Basic MVP -
    WWW: Http://EDais.earlsoft.co.uk/
    Work E-Mail: EDais@btclick.com
    Other E-Mail: Mike.Sutton@btclick.com



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center