put_le16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / FRAME_RATE_BASE));
put_le16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base));
static int swf_write_header(AVFormatContext *s){    SWFContext *swf;    ByteIOContext *pb = &s->pb;    AVCodecContext *enc, *audio_enc, *video_enc;    PutBitContext p;    uint8_t buf1[256];    int i, width, height, rate;    swf = av_malloc(sizeof(SWFContext));    if (!swf)        return -1;    s->priv_data = swf;    video_enc = NULL;    audio_enc = NULL;    for(i=0;i<s->nb_streams;i++) {        enc = &s->streams[i]->codec;        if (enc->codec_type == CODEC_TYPE_AUDIO)            audio_enc = enc;        else            video_enc = enc;    }    if (!video_enc) {        /* currenty, cannot work correctly if audio only */        width = 320;        height = 200;        rate = 10 * FRAME_RATE_BASE;    } else {        width = video_enc->width;        height = video_enc->height;        rate = video_enc->frame_rate;    }    put_tag(pb, "FWS");    put_byte(pb, 4); /* version (should use 4 for mpeg audio support) */    put_le32(pb, DUMMY_FILE_SIZE); /* dummy size                                       (will be patched if not streamed) */     put_swf_rect(pb, 0, width, 0, height);    put_le16(pb, (rate * 256) / FRAME_RATE_BASE); /* frame rate */    swf->duration_pos = url_ftell(pb);    put_le16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / FRAME_RATE_BASE)); /* frame count */        /* define a shape with the jpeg inside */    put_swf_tag(s, TAG_DEFINESHAPE);    put_le16(pb, SHAPE_ID); /* ID of shape */    /* bounding rectangle */    put_swf_rect(pb, 0, width, 0, height);    /* style info */    put_byte(pb, 1); /* one fill style */    put_byte(pb, 0x41); /* clipped bitmap fill */    put_le16(pb, BITMAP_ID); /* bitmap ID */    /* position of the bitmap */    put_swf_matrix(pb, (int)(1.0 * (1 << FRAC_BITS)), 0,                    0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0);    put_byte(pb, 0); /* no line style */        /* shape drawing */    init_put_bits(&p, buf1, sizeof(buf1), NULL, NULL);    put_bits(&p, 4, 1); /* one fill bit */    put_bits(&p, 4, 0); /* zero line bit */        put_bits(&p, 1, 0); /* not an edge */    put_bits(&p, 5, FLAG_MOVETO | FLAG_SETFILL0);    put_bits(&p, 5, 1); /* nbits */    put_bits(&p, 1, 0); /* X */    put_bits(&p, 1, 0); /* Y */    put_bits(&p, 1, 1); /* set fill style 1 */        /* draw the rectangle ! */    put_swf_line_edge(&p, width, 0);    put_swf_line_edge(&p, 0, height);    put_swf_line_edge(&p, -width, 0);    put_swf_line_edge(&p, 0, -height);        /* end of shape */    put_bits(&p, 1, 0); /* not an edge */    put_bits(&p, 5, 0);    flush_put_bits(&p);    put_buffer(pb, buf1, pbBufPtr(&p) - p.buf);    put_swf_end_tag(s);        if (audio_enc) {        int v;        /* start sound */        v = 0;        switch(audio_enc->sample_rate) {        case 11025:            v |= 1 << 2;            break;        case 22050:            v |= 2 << 2;            break;        case 44100:            v |= 3 << 2;            break;        default:            /* not supported */            av_free(swf);            return -1;        }        if (audio_enc->channels == 2)            v |= 1;        v |= 0x20; /* mp3 compressed */        v |= 0x02; /* 16 bits */                put_swf_tag(s, TAG_STREAMHEAD);        put_byte(&s->pb, 0);        put_byte(&s->pb, v);        put_le16(&s->pb, (audio_enc->sample_rate * FRAME_RATE_BASE) / rate);  /* avg samples per frame */                        put_swf_end_tag(s);    }    put_flush_packet(&s->pb);    return 0;}