static void write_header(FFV1Context *f){
    uint8_t state[CONTEXT_SIZE];
    int i;
    RangeCoder * const c= &f->c;

    memset(state, 128, sizeof(state));

    put_symbol(c, state, f->version, 0);
    put_symbol(c, state, f->avctx->coder_type, 0);
    put_symbol(c, state, f->colorspace, 0); //YUV cs type
    if(f->version>0)
        put_symbol(c, state, f->avctx->bits_per_raw_sample, 0);
    put_rac(c, state, 1); //chroma planes
        put_symbol(c, state, f->chroma_h_shift, 0);
        put_symbol(c, state, f->chroma_v_shift, 0);
    put_rac(c, state, 0); //no transparency plane

    for(i=0; i<5; i++)
        write_quant_table(c, f->quant_table[i]);
}