Saturday, March 28, 2009

Using ffmpeg to capture screen of flv file

ffmpeg is a powerful utility for audio and video processing. However, you have to compile the source code yourself. This web page tells how to compile the source code of ffmpeg to become executables.

One very simple use of ffmpeg is to capture screen from a flv file. Actually, this is to save a video frame to file.

For example, this command :
ffmpeg -i MyFile.flv -ss 00:00:31 -vframes 1 -y MyImage.jpg
will capture a frame from the file MyFile.flv at the time 00:00:31 to the file MyImage.jpg
If you want to capture 101 frames, here is the command:
ffmpeg -i MyFile.flv -ss 00:00:31 -vframes 101 -y MyImage-%03d.jpg
The will capture the 101 frames to the files MyImage-001.jpg to Myimage-101.jpg.
However, under Windows, there is some special processing for the percent sign. Therefore, the command has to be adjusted as follow:
ffmpeg -i MyFile.flv -ss 00:00:31 -vframes 101 -y MyImage-%%03d.jpg
In short, double percent signs have to be used under Windows.


Thursday, March 26, 2009

Change Color of the Tabs in Firefox 3.0.6

In Firefox 3.0.6 the background colors of the selected active tab and the un-selected inactive tabs are very similar. The color of the selected tabs cannot stand-out to catch your eyes. Here is a way to change the colors.
Firstly, go to the chrome directory of your profile in Firefox 3.0.6. Create or edit the file userChrome.css and add the following lines :
tab { -moz-appearance: none !important; } tab[selected="true"] { background-color: #FF6A6A !important; color: blue !important; } tab:not([selected="true"]) { background-color: #CCFFFF !important; color: black !important; }
Then, re-start the firefox.

This will make the active tab have red background with blue text and the inactive tabs have light cyan background with black text.



Saturday, March 21, 2009

Line numbering source code snippet with Javascript function on body load

Yesterday's blog I am talking about performing line numbering using Javascript for-loop hard coding. Since you have to count the line numbering beforehand in order to hard code it, this is quite troublesome. Here is a more automatic method, no need to count the line number manually.

Here is a program code snippet using this line numbering method :
program Hello_World ; begin writeln('Hello World !'); { This source code snippet is line numbered using a Javascript function which replace every line with a <li> and then use the HTML order list tag in order to make it appear as line numbering. As a result, there is a "dot" after each line number. Noted : This method does not work in IE6 when the convert-line-breaks option is turn off in blogspot. Therefore, I simply disable this method for all IE. So, if you are using IE to read this web page, there is no line numbering for this program snippet. } end.
The steps of this method are :
  1. Use a HTML TTT tag with a class XXX where TTT is either a pair of (pre + code) tags or just a div tag.
  2. Put the source code inside the TTT tags
  3. Use a Javascript function to process every lines inside the TTT tags
  4. Make the HTML to call this function in the body tag onload attribute.
The class XXX in the TTT tag is used for easy setup for CSS style sheet. Using the above example, the blue line border and the alternate gray line background image are the CSS style sheet settings.
Also, this class XXX can help as an identifier for the Javascript function to identify this special piece of information for processing. When the browser load this HTML, the function will do the following:
  1. Search all TTT elements in the HTML with the class XXX.
  2. Start processing the innerHTML information of this element
  3. Firstly, add an order list tag <ol> at the beginning with a class XXX.
  4. For each line, add a list item tag <li> at the beginning of the line
  5. At last, close the order list using this tag </ol>
  6. Then, replace the innerHTML using this new piece of information.
When the function is ready, call the function in the onload attribute of the HTML body tag. Using this way, when the HTML is loaded by the browser, this function will be automatically called. The function will scan the whole document to search for all TTT elements to add the order list processing for your source code snippets.
When applying this method in blog post of blogspot, something additional has to be done :
  • Firstly, it will be more easy to put the Javascript function in an external Javascript js file in an outside server, rather than putting inline in the HTML blogspot settings.
  • When the convert line breaks option is turn on, blogspot will replace the hard return with <br> in Firefox 3.0.6 (<BR> in IE6) in the source code snippet. In other words, the source code snippet is no longer line-by-line as seen in the blogspot editor. Instead, the original "lines" are separated by either <br> or <BR> in the innerHTML. The Javascript function has to take care of this during the processing.
  • When the convert line breaks option is turn off in blogspot, no <BR> will be inserted. Then, in IE6, there is not way to "identify" something to convert to <li>. So, I have to disable using this method when detecting a IE browser.
Using this method, the disadvantages are:
  1. One disadvantage is about the browser. As you may have noticed, if this page is read by Firefox 3.0.6, the alternate gray line background image does not match the source code text lines. It is quite difficult to control the line height of the HTML order list tag using CSS under Firefox 3.0.6 (I am still looking into this issue). But, when reading with IE6 or Google Chrome 1.0.154.53, there is no such problem. Maybe this is a bug in Firefox.
  2. Moreover, since the source code is inside the order list tag, it is quite difficult to cut-and-paste the source code in Firefox to Notepad or Writepad. When paste to PSPad, the line number is also pasted. However, if using Google Chrome 1.0.154.53, the line number is also hightlighted during copy. But, there is no line number after paste. The source code looks fine !
  3. In addition, as tested on 2009-03-21, one serious drawback of this method under IE6 is that the indentation leading space are all gone in IE6.
  4. At last, as mention before, this method is disabled when detecting a IE browser because my blogspot has turn off the convert-line-breaks option starting 2009-03-22. This is because I cannot detect a "lin" after turning off the convert-line-break option.

Friday, March 20, 2009

Line numbering source code snippet using Javascript for-loop hard coding

Here is a quick-and-dirty method of adding line numbers to the source code snippet.

program Hello_World ;

begin

   writeln('Hello, World !');

   { This method of line numbering is not so smart.
     The line numbers on the left is generated
     using a Javascript for-loop with hard-coding the
     number of loops which is 12. }

end.

The method is very simple : use a HTML table tag with only 1 row of 2 cells. The right cell is the code snippet. In the left cell, use Javascript to call a for-loop to document.writeln the line number.

The text inside both cells is inside a HTML pre tag. As long as they are of the same fonts and line heights, the line number will match the source code snippet.

Following coding snippet is contained inside a table of one cell :

program Hello_World ; begin writeln('Hello, World !'); { This method of line numbering is not so smart. The line numbers on the left is generated using a Javascript for-loop with hard-coding the number of loops which is 12. } end.

Using the same method, the line numbers are added :

program Hello_World ; begin writeln('Hello, World !'); { This method of line numbering is not so smart. The line numbers on the left is generated using a Javascript for-loop with hard-coding the number of loops which is 12. } end.

Now, the table consists of 2 cells in a row. The left cell is for line numbers.

The disadvantages of this method are:

  1. One disadvantage of this method is that the number of loop is hard-coded. You have count the total number of lines in your source code snippet and put this number in the for-loop.
  2. Another disadvantage is with the browser and blogspot.
    If the convert-line-breaks option is turn on in blogspot and you are using Firefox to read this page, the above table should be very perfect. The Pascal program end statement is at the line-12. But, if you are using IE6, the program end statement is at line-8. This is because the IE6 does not shown the blank lines from Blogger. There should be each of one blank line in between the statements program, begin, writeln, the block comment and the end statements. So, in order to take care of readers using IE6 and the convert-line-breaks is yes in blogspot, you have to count the number of blank lines and do a re-calculation on the final maximum number of lines for using in the for-loop.
    However, it the convert-line-breaks is NO, there is no such problem.
    Now, I have turn off the convert-line-breaks in my blog in blogsport and this page does not have this problem.


Wednesday, March 18, 2009

2 to the power

Here is a table of 2 to the power :

Power Of 2 Decimal Values ---------- ------------------------------------------------
  1. 1
  2. 2 ← 1 bit to store 0 or 1
  3. 4
  4. 8 ← 3 bit octet
  5. 0x10 16 ← 4 bit, half-byte to store hexadecimal
  6. 32
  7. 64
  8. 128 ← 7 bit for ASCII encoding
  9. 0x100 256 ← 1 byte = 8 bit, 0 - 255 ----------------
  10. 512
  11. 1,024 ← 1K (Kilo)
  12. 2,048
  13. 4,096
  14. 8,192
  15. 16,384
  16. 32,768
  17. 0x10000 65,536 ← 2 byte, 64K, double-byte Unicode -------
  18. 131,072
  19. 262,144
  20. 524,288
  21. 1,048,576 ← 1M (Mega), more than 1 million
  22. 2,097,152
  23. 4,194,304
  24. 8,388,608 ← 8M, 23 bit mantissa for float in IEEE754
  25. 0x1000000 16,777,216 ← 3 byte, 24 bit, 16M color --------------
  26. 33,554,432
  27. 67,108,864 ← 64M
  28. 134,217,728 ← 128M
  29. 268,435,456 ← 256M
  30. 536,870,912 ← 512M
  31. 1,073,741,824 ← 1G (Giga)
  32. 2,147,483,648
  33. 0x100000000 4,294,967,296 ← 4 byte ---------------------------------
  34. 8,589,934,592 ← 8G
  35. 17,179,869,184
  36. 34,359,738,368
  37. 68,719,476,736
  38. 137,438,953,472
  39. 274,877,906,944
  40. 549,755,813,888
  41. 1,099,511,627,776 ← 5 byte, 1T (Tera) ----------------------
  42. 2,199,023,255,552
  43. 4,398,046,511,104
  44. 8,796,093,022,208
  45. 17,592,186,044,416
  46. 35,184,372,088,832
  47. 70,368,744,177,664
  48. 140,737,488,355,328
  49. 281,474,976,710,656 ← 6 byte ---------------------------------
  50. 562,949,953,421,312
  51. 1,125,899,906,842,624 ← 1P (Peta)
  52. 2,251,799,813,685,248
  53. 4,503,599,627,370,496 ← 52 bit mantissa for double in IEEE754
  54. 9,007,199,254,740,992
  55. 18,014,398,509,481,984 ← stepping into 17 digits
  56. 36,028,797,018,963,968
  57. 72,057,594,037,927,936 ← 7 byte ---------------------------------
  58. 144,115,188,075,855,872
  59. 288,230,376,151,711,744
  60. 576,460,752,303,423,488
  61. 1,152,921,504,606,846,976 ← 1E (Exa), stepping into 19 digits
  62. 2,305,843,009,213,693,952
  63. 4,611,686,018,427,387,904
  64. 9,223,372,036,854,775,808
  65. 18,446,744,073,709,551,616 ← 8 byte ---------------------------------
  66. 36,893,488,147,419,103,232
  67. 73,786,976,294,838,206,464
  68. 147,573,952,589,676,412,928 ← stepping into 21 digits
  69. 295,147,905,179,352,825,856
  70. 590,295,810,358,705,651,712
  71. 1,180,591,620,717,411,303,424 ← 1Z (Zetta)
  72. 2,361,183,241,434,822,606,848
  73. 4,722,366,482,869,645,213,696 ← 9 byte ---------------------------------
  74. 9,444,732,965,739,290,427,392
  75. 18,889,465,931,478,580,854,784
  76. 37,778,931,862,957,161,709,568
  77. 75,557,863,725,914,323,419,136
  78. 151,115,727,451,828,646,838,272
  79. 302,231,454,903,657,293,676,544
  80. 604,462,909,807,314,587,353,088
  81. 1,208,925,819,614,629,174,706,176 ← 10 byte , 1Y (Yotta) -------------------
  82. 2,417,851,639,229,258,349,412,352


Duplicate Open Current Folder in a New Window

Sometimes after I opened a folder in Win7, I would like to duplicate open the same folder again in another explorer window. Then, I can ope...