I got free Monday so I decided to spend some time on any small codec and took VMware codec used by VMware emulator to capture screen output. As Alex discovered, this is merely recorded session of RFB protocol (used in VNC applications) but slightly mangled.
My further investigation show that bytes 1-2 in big-endian order contain number of rectangles updated and if that value is equal to 8 then the first chunk is ServerInitialization struct with marker ‘WMVi’ inserted before pixel format data. Otherwise frame may contain one or several FramebufferUpdate messages with standard HexTile encoding.
I’ve committed decoder to FFmpeg and I hope to find more samples and clarify some details about it (there are seven markers from ‘WMVd’ to ‘WMVh’ but what they mark is known only for ‘WMVi’, palette mode is not tested too).
OOPS, I’ve just discovered three more samples at MPHQ and they are not decoded correctly, so I have some more work to do.
A Work for the Weekend
September 5th, 2006Some more experiments with VC-1
August 31st, 2006For those who interested, here is a very experimental patch to enable decoding of WVC1 codec in FFmpeg. I’m currently searching and downloading sample files but it is already tested a bit.
Instructions:
- Get FFmpeg sources (r614x should work)
- Download and apply patch (cd ffmpeg; patch -p0 < vc1-advanced.patch)
- Run configure and make
As always, non-working samples are welcome.
FAQ
August 29th, 2006I have got some letters and here I will try to summarize them.
You wrote some decoder, where can I find it?
When I reverse-engineer some codec I add decoder to FFmpeg (and soon it goes to other multimedia players) and description to Multimedia Wiki
Do you know how WMV3 video is stored in files?
I just have general ideas how it is stored. See Multimedia Wiki ASF page for details
Help! I have WMV3 sample that does not play {correctly, at all}.
Please follow instructions here. That’s the easiest way to get help (and other people than me may be interested in your samples).
M$ Way: Incompatible with itself
July 25th, 2006If you look in VC-1 standard specification it’s hard to find header specification for Simple/Main Profile (at least I was unable to do so in comittee draft available – only some hints in bitstream container format). Was that intensional or not?
FFmpeg old and not working vc9.c contained header parsing code and reference decoder does this too. This header contains a lot of ‘reserved’ flags which hidden meaning become clearer if you meet with them:
- RES_RTM_FLAG – should be set to ‘1’ but all old WMV3 files have it set to zero. For now you can call it ‘P-frames will be decoded correctly’ flag as old WMV3 has I-frames decoding identical to standard
- PROFILE=2. This is not allowed profile but in vc9.c it was called “Complex Profile” and really is Advanced Profile for old WMV3. I don’t know why but one sample was decoded when I changed profile value to “Main”, other Complex Profile samples produced garbage (but they also had RES_X8 and RES_FASTTX flags set).
There is also new M$ codec – WVC1 which is not decoded by reference decoder.
So here is a small list of huge tasks:
- Find out how to decode P-frames when RES_RTM_FLAG=0 thus enabling decoding of many old WMV3 videos
- Find out how to parse WVC1 movies
- Support Complex Profile (not really important)
VC-1 Forward transform
July 24th, 2006Some notes on forward transform.
For 4×4 transform matrix is:
17 17 17 17
22 10 -10 -22
17 - 17 - 17 17
10 -22 22 -10
And suggested norm is (8/289 ; 8/292; 8/289; 8/292)
The forward transform for (A B C D ) will be:
A1 = (17 * A + 17 * B + 17 * C + 17 * D) * 8 / 289;
B1 = (22* A + 10 * B - 10 * C - 22 * D) * 8 / 292;
C1 = (17 * A - 17 * B - 17 * C + 17 * D) * 8 / 289;
D1 = (10 * A - 22 * B + 22 * C - 10 * D) * 8 / 292;
Of course, don’t forget to round result.
I tested it on Octave and it proved to be correct.
Optimization is also straightforward: compute (A+D) , (B+C), (B-C) and use their sums/differencies.
B-frames: I feel cheated
July 24th, 2006Yesterday I finished B-frames parsing support and to my surprise all of B-frames in test streams were decoded correctly even without motion compensation. I don’t know why all of them are composed from intra-blocks only. And they are not MS-invented BI-frames either.
While I understand that’s legal I still cannot understand why it was done so.
VC-1 Test Bitstreams
July 21st, 2006I’ve written a small and quick demuxer for VC-1 Simple/Main profile test bitstreams (source available Here).
Most of the samples are recordings of Football training. You can see “Windows Media” logotypes on some players’ uniform.
And rarely clips with some singer occur.
Anybody can guess why?
Bad news
July 11th, 2006Yesterday I tried to decode WMV3 Advanced Profile (fourcc: WVC1) and it failed. After I changed decoder to skip 5 bytes (one unknown, and 00 00 00 01 0F indicating that sequence hader is started) it began to decode frames. And failed. The only correctly decoded frames are skipped frames.
So no Advanced Profile reference decoder for now.
VC-1: Pause
July 8th, 2006I won’t be able to work at VC-1 full day for a week, but it does not mean I won’t code at all. Meanwhile I plan to write demuxer for test bitstreams. Annex L in standard specifies format for all profiles but advanced profile bitstreams use their own format: 0x00 0x00 0x01
And here is what I’ve done to present time.
Present decoder status:
- Simple and main profile supported
What is not implemented:
- B/BI-frames (samples needed)
- Reduced range support (the same)
- Loop filtering for P-frames (I don’t think it’s needed now)
Known bugs:
- Chroma in P-frames is wrong
- Sometimes motion creates double borders on objects
VC-1: Checkpoint
July 4th, 2006Yesterday I’ve finished P-frames support in VC-1 decoder. That does not mean it now decodes all files of course. But at least simple/main profile without B-frames and advanced features should be decoded more or less correctly (excluding chroma).
So, it’s time to do the bug squashing:
- Correct chroma mode
- Implement MV intensity compensation (now it mostly produces errors)
- Implement coefficient scaling
- Make all P-frames parse and decode correctly
Looks like VC-1 movies with B-frames are rare so another task is to find samples.