On Sun, 22 Jan 2006, Bob Stia wrote: > On Saturday 21 January 2006 05:41, Andrew Stevens wrote: > > > > > > **ERROR: [mplex] Can't find next AC3 frame: @ 349129984 we have 04c3 - > > > broken bit-stream? > > > linux:/workspace # ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > > > AC3 audio frames have a header that starts with a 16-bit byte-aligned > > 'syncword' 0x0b77 and includes a encoded frame-length.
The DVR I rent from Comcast with Microsoft software failed to record last weeks episode of 'Lost', which was new and isn't going to be re-run. Thankfully I was able to download the episode in 540p with AC3 sound. Comcast refunded my DVR free when I called to complain, apparently they have known for some time that the software will randomly fail to record things. It seems no matter how many bananas they give the monkeys at Microsoft, they fail to write working DVR software or the complete works of Shakespeare. Makes me wonder how it is they are employed while I am not. None of my computers can play a 540p mpeg4 file. So, enter mjpegtools to transcode the file to a DVD which I can watch on my TV. But, it looks like whoever captured the show off the HD digital broadcast had a few corrupt bits in the AC3 audio. There also appear to be synchronization errors everywhere they spliced the stream to cut out the commercials. It looks like one frame will be cut short, then the next valid frame will start immediately after. When I try to mux the mpeg system stream, mplex dies with the synchronization error we have become so familiar with recently. > > - Grab the source code and modify the AC3 reader loop so it simply ignores > > some number of broken CRC's and just extrapolates from previous AC3 frames > > instead of giving up immediately. Not rocket-science (see > > mplex/ac3stream.cpp - its obvious whats going on). I looked at doing this, but decided that the io stream class used by the AC3 reader didn't provide the capabilities to do what I wanted. So, I wrote a new, better, IO stream class. It's much more efficient and more capable. At least more capable in ways that appeared, to me, to be important. I then wrote an AC3 re-synchronization program that uses this class. The result works! I was able to have mplayer dump the AC3 into a fifo, have my program read that fifo and send the re-synchronized AC3 to another fifo, and finally have mplex read the re-synchronized audio from that fifo. I produced a DVD which appears to have correct audio sync. Now my wife and I can watch last week's 'Lost', just in time for the DVR to mess up this week's episode. Most of the work was writing the stream I/O library. Specifically the CRC-16 function used to check the CRCs of the AC3 frames. Rather than just copy some code from ac3dec, I wanted to know how it worked and how to derive my own CRC lookup table. To do this I needed to figure out how to perform a CRC without a lookup table. I found one way to do this is to consider the bits of the initial CRC and the data byte to be symbolic variables. Then perform the symbolic bitwise math of 8-bits worth of CRC computation. Then write code that will directly compute the resulting expression. I started doing this with pencil and paper, but quickly got bored after computing about two bits worth. So I wrote a symbolic bitwise math system and used it to compute the result for me. CRC table and C version in hand, I decided it would interesting to write an assembly language version. Actually writing the function was easy enough, but getting gcc interface to the asm block and select registers well was harder. But it proved fruitful, as I found an excellent howto I hadn't read before that told me about the undocumented %b and %h modifiers, which allow one to refer to the high and low bytes of a gcc selected register. I had previously lamented that this appeared impossible. So, I started by trying to watch an episode of Lost that Microsoft's broken software failed to record, and ended up learning how to write better gcc inline assembly. And if you've read this far, and want to try to fix an AC3 stream you have, you can download my ac3 resyncer at http://www.speakeasy.net/~xyzzy/download/ac3resync-1.0.tar.gz ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642 _______________________________________________ Mjpeg-users mailing list Mjpeg-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mjpeg-users