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

Michael Niedermayer michaelni at gmx.at
Thu Mar 24 00:17:47 CET 2011


On Mon, Mar 21, 2011 at 09:18:15AM +0800, Leon Ou wrote:
[...]
> +typedef struct FlashSV2Context {
> +    AVCodecContext *avctx;
> +    uint8_t *current_frame;
> +    uint8_t *key_frame;
> +    AVFrame frame;
> +    uint8_t *encbuffer;
> +    uint8_t *keybuffer;
> +    uint8_t *databuffer;
> +
> +    Block *frame_blocks;
> +    Block *key_blocks;
> +    int frame_size;
> +    int blocks_size;
> +
> +    int use15_7, dist, comp;
> +
> +    int rows, cols;
> +
> +    int last_key_frame;
> +
> +    int image_width, image_height;
> +    int block_width, block_height;
> +    uint8_t flags;
> +    uint8_t use_custom_palette;
> +    uint8_t palette_type;       ///< 0=>default, 1=>custom - changed when palette regenerated.
> +    Palette palette;
> +#ifndef FLASHSV2_DUMB
> +    double tot_blocks;          ///< blocks encoded since last keyframe
> +    double diff_blocks;         ///< blocks that were different since last keyframe
> +    double tot_lines;           ///< total scanlines in image since last keyframe
> +    double diff_lines;          ///< scanlines that were different since last keyframe
> +    double raw_size;            ///< size of raw frames since last keyframe
> +    double comp_size;           ///< size of compressed data since last keyframe
> +    double uncomp_size;         ///< size of uncompressed data since last keyframe
> +
> +    double total_bits;          ///< total bits written to stream so far
> +#endif

floating point should be avoided to avoid problems with regression
tests (rounding differeces)



> +} FlashSV2Context;
> +
> +static av_cold void cleanup(FlashSV2Context * s)
> +{
> +    if (s->encbuffer)
> +        av_free(s->encbuffer);
> +    if (s->keybuffer)
> +        av_free(s->keybuffer);
> +    if (s->databuffer)
> +        av_free(s->databuffer);
> +    if (s->current_frame)
> +        av_free(s->current_frame);
> +    if (s->key_frame)
> +        av_free(s->key_frame);
> +
> +    if (s->frame_blocks)
> +        av_free(s->frame_blocks);
> +    if (s->key_blocks)
> +        av_free(s->key_blocks);
> +}

the NULL checks are unneeded


[...]
> +
> +    if (block_size == 0)
> +        return buf_pos;
> +
> +    buf[buf_pos++] = b->flags;
> +

> +    if (b->flags & HAS_DIFF_BLOCKS) {
> +        buf[buf_pos++] = (uint8_t) (b->start);
> +        buf[buf_pos++] = (uint8_t) (b->len);

the casts are useless


[...]
> +static int pixel_color7_slow(Palette * palette, unsigned color)
> +{
> +    int i, min = 0x7fffffff;
> +    int minc = -1;
> +    for (i = 0; i < 128; i++) {
> +        int c1 = palette->colors[i];
> +        int diff = chroma_diff(c1, color);
> +        if (diff < min) {
> +            min = diff;
> +            minc = i;
> +        }
> +    }
> +    return minc;
> +}

this can be done faster with LUT


[...]
> +static int encode_all_blocks(FlashSV2Context * s, int keyframe)
> +{
> +    int row, col, res;
> +    uint8_t *data;
> +    Block *b, *prev;
> +    for (row = 0; row < s->rows; row++) {
> +        for (col = 0; col < s->cols; col++) {
> +            b = s->frame_blocks + (row * s->cols + col);
> +            prev = s->key_blocks + (row * s->cols + col);
> +            if (keyframe) {
> +                b->start = 0;
> +                b->len = b->height;
> +                b->flags = s->use15_7 ? COLORSPACE_15_7 : 0;

> +            } else if (!b->dirty) {
> +                b->start = 0;
> +                b->len = 0;
> +                b->data_size = 0;
> +                b->flags = s->use15_7 ? COLORSPACE_15_7 : 0;
> +                continue;
> +            } else {
> +                b->flags = s->use15_7 ? COLORSPACE_15_7 | HAS_DIFF_BLOCKS : HAS_DIFF_BLOCKS;
> +            }

The b->dirty decission here should be made based on minimizing
C*rate + distortion

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 3
"Rare item" - "Common item with rare defect or maybe just a lie"
"Professional" - "'Toy' made in china, not functional except as doorstop"
"Experts will know" - "The seller hopes you are not an expert"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110324/54f78ef8/attachment.asc>


More information about the ffmpeg-devel mailing list