[FFmpeg-devel] [PATCH] encoder for adobe's flash ScreenVideo2

Leon Ou ouliyong at gmail.com
Mon Mar 21 02:18:15 CET 2011

Hi all,

In the mail list, I find a encoder for adobe’s flash ScreenVideo2 written by
Joshua. After read the code below. I make some changes to this code to
decreases  the size of encoded data for the situation of pool bandwidth.In
Joshua code, the low 3 bits of every channel of RGB are discarded.  But in
my code, the low 4 bits of every channel of RGB are discarded. After the
test, discarding the low 4 bits doesn’t lower  the picture quality

Below is the test data of this two ways:

A Screen capture with 1440*900, the raw data is 3.7MB.

Reserving high 5 bits +Default Palette+ZLIB..................The encode size
is 680KB

Reserving high 4 bits +Default Palette+ZLIB..................The encode size
is 350KB

After discussion with Joshua, I change one method in his code and add two
new methods to compatible the two ways of handling RGB color.

*1.Change the method:** **pixel_color15. *


static inline unsigned pixel_color15(const uint8_t * src, int mask)


return ((src[0] & mask) >> 3) | ((src[1] & mask) << 2) | ((src[2] & mask) <<


Add a parameter ‘mask’ to the  pixel_color15

*2. Add two new methods.*

static int update_palette_index_size(Palette * palette)

 for(int i =0; i<32768;i++)
    palette->index[i] = 0x80;

 for (int index = 0; index < 128; index++)

  uint8_t c_r = palette->colors[index]>>16;
  uint8_t c_g = palette->colors[index]>>8 & 0xff;
  uint8_t c_b = palette->colors[index] & 0xff;
  unsigned palette_color_15 = ((c_b & 0xf0) >> 3) | ((c_g & 0xf0) << 2) |
((c_r & 0xf0) << 7);
     unsigned short bgri = (unsigned short)palette_color_15;

     palette->index[bgri] = index;

 return 0;

 static int write_pixel_15_7_size(Palette * palette, uint8_t * dest, const
uint8_t * src, int dist)
 unsigned short c15_4bits = pixel_color15(src, mask);
 if (palette->index[c15_4bits]!=0x80)
  dest[0] = (uint8_t) palette->index[c15_4bits];
  return 1;
  dest[0] = 0x80 | (uint8_t) (c15_4bits >> 8);
  dest[1] = c15_4bits & 0xff;
  return 2;

Whiling focus on screen capture image size, the update_palette_index_size
and write_pixel_15_7_size will be replace the update_palette_index and
write_pixel_15_7 in your code. In the write_pixel_15_7_size, the 'dist'
parameter is used as 'mask'. So, in the flashsv2_encode_frame, the dist
should be set to 0xF0.

Whiling focus on screen capture image quality, the update_palette_index and
write_pixel_15_7 should be chosen and passes the “0xF1” for the ‘mask’
parameter of method  pixel_color15.

For the detail code, Please see the attchment.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: encode_svc2.cpp
Type: text/x-c++src
Size: 34855 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110321/03f1e42b/attachment-0001.bin>

More information about the ffmpeg-devel mailing list