May, 2008

  • Jie Li's GeekWorld

    Why the clock under Windows 2K/XP/2K3 show “four quick seconds and one slow second”?

    • 2 Comments

    If you click the clock at the right-bottom corner of Windows, it will open a small animated clock, which has seconds showed on it. But if you watch it carefully for a few moment, you will notice that every four seconds are the same length, but the fifth one is much longer than that. What happened?

    The reason is quite interesting. As we know, in Windows C++ coding, we use WM_TIMER to set the time trigger for many events. The resolution of WM_TIMER is at about 50ms, which cannot be used under time-critical real time processing. But for a clock, it is enough. In the code of clock application, the following code is used to set the Timer(You can also get these pieces of code from VC98 CDROM Samples, if you still have it, I doubt):

    SetTimer (hWnd, TimerID, OPEN_TLEN, 0L);

    OPEN_TLEN is the length of the timer, it is a constant. So when we look at clock.h, you will get the number, which is 450.

    What does this 450 mean? This means, every 450ms the timer will be triggered, it will detect time changes and redraw the clock.

    So, we can draw a small table to make it clear, the first row is the number of trigger, the second row is the time:

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
    450 900 1350 1800 2250 2700 3150 3600 4050 4500 4950 5400 5850 6300 6750 7200 7650 8100 8550 9000 9450 9900

    You will notice that within the first second, the timer gets triggered twice, and it will be updated at the 3rd trigger. The same situation is for 2nd, 3rd and 4th second. But within the fifth second, which is marked as red, the timer gets triggered for three times, and the clock will be updated at 4th trigger.

    So this is why the fifth second update is much longer than the other four.

    Why this have to be 450? Well, I’m not a developer nor a program manager, I don’t know their decision. But I guess this is a consideration about performance and resources. After all, how many people will use that clock as an accurate timer?

    BTW – the clock application under Vista/2K8 is completely rewritten, so you may not have that problem. But if you watch it for a minute, you will still notice a quite “quick” second. :)

  • Jie Li's GeekWorld

    Crash when loading/encoding video by Windows Media Encoder

    • 0 Comments

    If you are a Zune Lover and want to use some free stuff to make high quality WMVs for your Zunes, you may have the same problem with me – after you make a avi backup of your DVD and want to convert it to WMV then put it to your Zune, wmencoder just crashed and report something like “faulting module wmenceng.dll” in event log. (BTW, Zune player program does not do an excellent job for my video collections, esp. the old ones – I used to be an video encoding fan years ago)

    No matter you are using GUI or the command line script(WMCmd.vbs), the result is the same.

    So what happened?

    The problem is caused by incompatibility  of wmencoder and your Video/Audio codec. Some of the 3rd party DirectShow decoders interface are poorly written, therefore created abnormal streams that wmencoder cannot identify(you may ask the question that why it crashes instead of reporting an error, well, crash sometimes is better to prevent further attack).  Most of the time, this is caused by some certain version of "ffdshow”.

    So if you are suffering from this problem, first, reinstall or find another build of ffdshow, or just modify settings in your ffdshow configuration interface to make sure it won’t decode certain streams, like mp3.

    Then, problem solved.

    And – if you are on Vista, don’t forget to apply the vista patch of windows media encoder, otherwise it won’t work at all.

Page 1 of 1 (2 items)