int n = fwrite(ps->stream_buf, 1, ps->buf_level, ps->fp);
n = fwrite(ps->stream_buf, 1, ps->buf_level, ps->fp);
static int mux_flush_packs(PackStream *ps){  BitPack *bp      = &ps->bit_pack;  uint8_t *start   = ps->stream_buf + 4;  uint8_t *end     = ps->stream_buf + ps->buf_level;  double  scr_step = ps->pack_size * ps->pict_duration / ps->buf_level;  int64_t timestamp;    while (start < end)  {    //-- transfer SCR to timestamp --     timestamp = (int64_t)(ps->scr * 27000 / 300.0 + 0.5);         //-- update SCR (System Clock Reference) = total 48bits = 6 bytes --    put_init_bp(bp, start);     put_bits(bp,  2, 0x1);    put_bits(bp,  3, (uint32_t)((timestamp >> 30) & 0x07));    put_bits(bp,  1, 1);    put_bits(bp, 15, (uint32_t)((timestamp >> 15) & 0x7fff));    put_bits(bp,  1, 1);    put_bits(bp, 15, (uint32_t)((timestamp) & 0x7fff));    put_bits(bp,  1, 1);    put_bits(bp,  9, 0);    // set remainder of SCR (because of simplicity to 0)     put_bits(bp,  1, 1);    // marker     //-- next SCR in next pack --    ps->scr += scr_step;    start   += ps->pack_size;  }    int n = fwrite(ps->stream_buf, 1, ps->buf_level, ps->fp);  //-- start in front of buffer again --    ps->pack_start = ps->stream_buf;  ps->buf_level  = 0;  ps->frame_no++;    return 0;}