This project is a simplified version of a larger project. It is a simple DirectX-based webcam recorder; it records both video and audio into an AVI file while previewing the video on screen.
The project is written in C# using .Net Framework 2.0. It uses DirectPlay to communicate with the webcam and microphone and to capture and manipulate the streams. It uses DirectShow, in particularly VMR9, in order to preview the video on the screen. The source code is attached.
This project has a problem: although it behaves correctly, the file that it outputs is not synchronized correctly - the video and audio are not synchronized.
I have tried many different options to make the video and audio synced, while maintaining the video preview, to no avail. I have tried setting a master stream ([url removed, login to view]), creating and/or syncing all streams on any clock (IReferenceClock, [url removed, login to view], SyncUsingStreamOffset), interlaceaving the output (IConfigInterleaving.put_Mode([url removed, login to view])), and mangling the buffers ([url removed, login to view]); all experiments are in the source, either in use or commented out.
It seems that if I decrease the resolution, the video becomes synched; however, this is not a valid solution. I need to maintain high-highest resolution possible. Same is true for using a simpler webcam that outputs lower resolution than required (at least 640x480); if you can't test using a camera with such capabilities, DO NOT assume your solution works; if you need to, I can test it using my webcam. I am allowed to drop some frames (down to 10fps minimum) if this is a bottleneck, although my MacBookPro should be more than enough and the video is still out-of-sync.
I have also tried using different codecs, but the requirements is to use an LGPL codec, hence no MP3, MPEG, WMV, DivX, or XVid. If need be, I can probably opt for Vorbis+Theora+OGG.
You should fix this using the existing framework set up; if you wish to change any assumption or framework, please contact me for approval; not all changes are permissible for this project.