Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
Programming IT Technology

Writing Video Codecs for Win32? 31

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."

This discussion has been archived. No new comments can be posted.

Writing Video Codecs for Win32?

Comments Filter:
  • suggestion (Score:5, Funny)

    by tps12 ( 105590 ) on Tuesday September 03, 2002 @06:55PM (#4191953) Homepage Journal
    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!
  • 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.
  • Try DirectShow (Score:3, Informative)

    by Cecil ( 37810 ) on Tuesday September 03, 2002 @07:08PM (#4192010) Homepage
    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 [microsoft.com], and you might also find some useful stuff at this website [gdcl.co.uk].
  • On Linux... (Score:5, Insightful)

    by WasterDave ( 20047 ) <davep AT zedkep DOT com> on Tuesday September 03, 2002 @07:34PM (#4192163)
    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
  • by crapulent ( 598941 ) on Tuesday September 03, 2002 @09:04PM (#4192643)
    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. [microsoft.com] 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 [microsoft.com] and this will take care of making a DLL that knows how to register itself, etc. The section Writing Transform Filters [microsoft.com] has all the details in a step-by-step list, including build directions. This page is found through the path MSDN Home [microsoft.com] > MSDN Library [microsoft.com] > DirectX [microsoft.com] > DirectShow [microsoft.com] > Using DirectShow [microsoft.com] > Writing DirectShow Filters [microsoft.com]. 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.

  • On writing for linux instead (anonymous 1, Seann):

    Problems with this are
    1. I don't use linux.
    2. I have no desire to use linux.
    3. I have some but probably not enough experience using linux in the past to get something like this to work.
    4. I'm not aware of any standard capture and playback API for linux, though I will look up video for linux for a possible later port.
    5. Even if I get it working on linux, 99% of the people who'd want to use it don't use linux for encoding.
    6. BSD rules. But it still sucks for video as much as linux. =)

    If you can show me a linux API that I can use in less than 300 hours of fumbling around that works with the wintv go, radeon vivo, and gainward geforce4 ti4400 vivo in my test systems as capture devices, then I'll consider it. If it involves delving through kernel rebuilds and obscure device creation and such, forget it.

    On using Directshow (Cecil, crapulent):

    I have researched this and am reasonably confident I CAN produce a directshow filter (since I've already made one for the basic transform that works). However, if you'd care to read my original post more closely, I mentioned that premiere, virtualdub, and avicap all used VFW, and NOT directshow. I do agree that propigating old standards is horrible and should be done away with, but if I want any kind of apps to be able to use this for testing and real world applications, I have to interface with them. They all use the VFW interface, unless you count Graphedit, and I won't even go there. If you can think of a stable encoding app that actually uses directshow filters, please let me know.

    On doing static transforms first (crapulent):

    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. Transforming isn't a problem.

    The problem comes from the "read an avi" part. I don't know how to use the API to get data from the avi, and that's my original question. As for directshow, no apps use it, so even if I wrote a filter, it would be useless for anything but accelerated decode in players, which is pointless without something encoded in the format first, which I can't do.

    I do actually have a working directshow filter right now that implements the base transform, but it only works with graphedit, which likes to crash every few seconds no matter what I'm using.

    On using transcode (WasterDave):

    This sounds interesting and useful. I will look into it, thanks. Oh and yes I do know what 4:2:0 YUV is. =)

    On emailing virtualdub's author (anonymous):

    I tried this once I think, maybe I'll give it another shot as I think it was a long time ago now.

    On huffyuv being slashdotted (anonymous):

    Good. It'll save me the trouble of driving over to berkeley and slapping him with a printout of his own code.

    Other stuff:

    I've come across this book
    http://www.amazon.com/exec/obidos/tg/detail/ -/0471 310158/qid=1031113475/sr=8-1/ref=sr_8_1/102-492848 4-5485757?v=glance&s=books&n=507846
    and ordered it. I hope it's helpful, but if anyone knows another book that is I can use all the help I can get at this point. If anyone from xiph's video project can give me some tips, I do visit your IRC server from time to time, and I'd really appreciate any help you can give. Ditto anyone from xvid, though I don't think you guys have an IRC server that I know of.
    • 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.
      • I mean random data as in values that fit the range (-128 to 127) that pixel values would fall into when stored as bytes in memory. So basicly snow. I'm sure if viewed it would look awful, but yes it will compress in a lossy codec, and just look awful. 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" so I'm not sure what I'm gonna do with it yet. I don't know how to protect myself. Oh and I have inter-frame compression, just not in the way current codecs like the mpeg family do. I have a completely different design.
        • 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 [google.com], 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.
    • The easiest way is to write a windows codec, Xine, mplayer &co can use windows codec.

      So windows is the standard API for linux ...
  • 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

Math is like love -- a simple idea but it can get complicated. -- R. Drabek

Working...