Slashdot Mirror


Writing Video Codecs for Win32?

Gldm asks: "I've been working on a video codec as part of a college computer science project, but I've been stuck at an impasse for several months now: I can't figure out how to get video data from the OS to compress or test anything with. All the software applications I have (Premiere, Virtualdub, and AVIcap) want to use Microsoft's Video For Windows API, but I can't find any books on how to get a codec to interface with it. I've tried Microsoft's own docs, but they're not very helpful. The only example source I've found is huffyuv but it's written and commented so poorly, I can't understand it. I've tried emailing the author but he never replied. I thought it would be simple to do this but apparently VFW is some kind of ancient byzantine labyrinth of messages and function calls and data types I don't understand. If anyone knows a book on the VFW API that still exists and maybe something that very clearly explains exactly how you go about building a DLL please let me know. Or if you have experience programming for this API please please email me."

"I've tried asking my CS department for help, but they barely acknowledge the existence of GUIs and usually have us do everything in SunOS on their ancient 50mhz machines using gcc, which is not practical for this project. Nobody in the department knows any Windows programming and I've been unable to teach myself how to do it. I'm really frustrated because all I need is some kind of pointer to the pixels in a frame, its size and color format, and a pointer of where to put the compressed output."

11 of 31 comments (clear)

  1. suggestion by tps12 · · Score: 5, Funny

    Homework questions are traditionally posted to Usenet. Try comp.lang.c++, for starters. Don't forget to include a note that you don't read the newsgroup regularly, so would appreciate being CCed via email, so you won't miss any responses. Good luck!

    --

    Karma: Good (despite my invention of the Karma: sig)
    1. Re:suggestion by Dahan · · Score: 2

      Sounds like you misunderstand moderation... you moderate posts, not people. His post is funny, so it should be modded as such. If he posts a troll, fine, mod it as troll. Seems like you're the slashbot, with your attitude of wanting to mod down anyone you disagree with or dislike.

  2. going to say the obvious by seann · · Score: 2, Funny

    Why not try to do a Linux version, with a linux capture source.
    You could even fake it, by maping /dev/videoIN to ~/.pr0n/rawvideofile
    and then create the appropreate compressor from there on.
    and when your done
    write a video driver to replace the device you made

    or some jazz.

    --
    I'm a big retard who forgot to log out of Slashdot on Mike's computer! LOOK AT ME.
  3. Try DirectShow by Cecil · · Score: 3, Informative

    It's (kindof) a part of Microsoft's DirectX, and is definitely the next generation of Video Codecs. Please, don't proliferate the horrible VFW API any further. Do yourself and everyone else a favour and move to DirectShow.

    Microsoft's page is here, and you might also find some useful stuff at this website.

  4. On Linux... by WasterDave · · Score: 5, Insightful

    Yeah, I know you want to do it on Windows, but hear me out - I'm doing this at the moment.

    For source, a program called transcode will turn just about anything into 4:2:0 YUV. If you don't know what 4:2:0 YUV is, go back to MSDN now.Transcode is at http://www.theorie.physik.uni-goettingen.de/~ostre ich/transcode/ and I think the command line you want is something along the lines of "transcode -i /dev/dvd -y yuv4mpeg,null -o whatever". RTFM. Oh, the output is a format called YUV4MPEG, google for it, and open it in a hex editor, it's kinda obvious.

    Make your codec spit out YUV4MPEG too then pipe it into mplayer http://www.mplayerhq.hu/homepage/, with some distinctly non challenging flags ... so something like "mycodec | mplayer -vo x11".

    Easy peasy, and no shithead API's.

    Dave

    --
    I write a blog now, you should be afraid.
  5. Do a static file transform first. by crapulent · · Score: 3, Informative
    It appears that you have little experience working with Windows. If this is the case, then I suggest you start out with a simple file transform application. Read an encoded AVI, write the decoded AVI out in a RAW format. This will give you the ability to view the output of your codec in a media player without having to delve too much into COM objects and all the other Windows programming stuff.

    If you really want to write a codec, you don't necessarily have to use the VFW calls. The audio and video codec management under VFW is old stuff, from the 16 bit Win 3.1 days. It's supported through wrappers in DirectX/DirectShow. What you might want to do instead is create a DirectShow filter, specifically a Transform Filter. If you are not familiar with the DirectShow architecture, you will want to read up on this first. Once you are familiar with the terminology (graphs, filters, pins, etc.) then write a transform filter. You can derive it from a base class supplied in the SDK and this will take care of making a DLL that knows how to register itself, etc. The section Writing Transform Filters has all the details in a step-by-step list, including build directions. This page is found through the path MSDN Home > MSDN Library > DirectX > DirectShow > Using DirectShow > Writing DirectShow Filters. From the linked page:

    This section describes how to write a transform filter, defined as a filter that has exactly one input pin and one output pin. To illustrate the steps, this section describes a hypothetical transform filter that outputs run-length encoded (RLE) video. It does not describe the RLE-encoding algorithm itself, only the tasks that are specific to DirectShow.

  6. Try again (feeling less bloody minded). by WasterDave · · Score: 2

    Ok, so I'm feeling less bloody minded. Isn't a direct draw surface a directly addressable piece of memory? How about you get some example code for making the internal codecs render to a DD surface (almost certainly COM, if you're unlucky it may have to be via a dispatch interface), play it back a frame at a time and use that as input?

    Dave

    --
    I write a blog now, you should be afraid.
  7. Re:Responses to everyone (9/3/02 21:00 PST) by cpeterso · · Score: 2

    I've got a working transform function that's been ok for several months now. I've tested it with random generated data, my athlon xp1800 manages about 150fps. I also wrote SMP support for it so my friend's dual athlon mp1900 gets about 340fps.

    When you saying "random data", do you mean truly random images? That doesn't sound like a very typical use scenario. And wouldn't truly random data be impossible to compress?

    Also, will your code eventually be available for other people to download and try out? Your project sounds very interesting. I started experimenting with image compression, with the idea of creating a video codec that did not use inter-frame compression. Eventually, some other hobby projects took higher priority, so I haven't done much more work.

  8. How to timestamp your code by yerricde · · Score: 2

    I'd like to publish source eventually but I'm wary of having it stolen and then getting sued by someone else claiming it's "theirs"

    Don't worry. Here's all you have to do to prove that you possessed a file:

    1. Package your source distribution as a gzip'd tarball.
    2. Compute the MD5 or SHA-1 hash of that tarball.
    3. Send the ascii-armored hash to a digital notary, which will digitally sign it and date it.
    4. Save your hash.
    5. When accused of plagiarism, verify the notary's signature. Now you have proof that you sent that file's hash on that date, which proves in turn that you possessed the file on that date.
    --
    Will I retire or break 10K?
  9. Re:16-bit VfW Developer's Kit available at ... by steveha · · Score: 2

    VfW is 16-bit. That's one of the things that sucks about it.

    I wrote a VfW video capture driver once, and the cleverest thing I did was to have it start up a 32-bit process to do all the real work.

    steveha

    --
    lf(1): it's like ls(1) but sorts filenames by extension, tersely
  10. Re:16-bit VfW Developer's Kit available at ... by steveha · · Score: 2

    It's simple: if you are compiling anything VfW for Windows ME, 98, 95, or older, it's 16-bit code. If you are compiling for anything NT-based: NT, 2000, or XP, then it would actually be 32-bit code. But of course VfW is very deprecated.

    You don't really need to check. If you wanted to check, you would have to check the include files that you are compiling with, and the makefile (see which compiler and what compile switches it is using).

    If you were asking how I made part of the driver 32-bit, I had a special .exe file that was built 32-bit. It was called something like "pump.exe". The 16-bit code simply called the function that starts up a new process, passing in the filename of the pump. Then I could pass messages to the pump, and it would handle them. The trickiest part was getting pointers that I could pass from 16-bit code to 32-bit code; all I remember right now is that I used the thunking tools to do that. Once I had the pointers I passed them in messages. I had one message that meant "capture a frame of video into this buffer here", for example.

    For a codec, you probably don't want to do anything that complicated. I did it because I was writing a capture driver, and I really needed to be in 32-bit mode to talk to that particular hardware.

    steveha

    --
    lf(1): it's like ls(1) but sorts filenames by extension, tersely