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."
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.
Random and weird software I've written.
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:
On writing for linux instead (anonymous 1, Seann):
/ -/0471 310158/qid=1031113475/sr=8-1/ref=sr_8_1/102-492848 4-5485757?v=glance&s=books&n=507846
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
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.
Introducing the new Occam Fusion! Now with sqrt(-1) fewer blades!