else if(mov->tracks[i].enc->codec_type == CODEC_TYPE_AUDIO) { long trackDuration = 0;  if(mov->tracks[i].enc->codec_id == CODEC_ID_AMR_NB) { int j; for (j=0; j<mov->tracks[i].samples; j++) { int cl = j / MOV_INDEX_CLUSTER_SIZE; int id = j % MOV_INDEX_CLUSTER_SIZE; trackDuration += mov->tracks[i].cluster[cl][id].entries; } mov->tracks[i].sampleDelta = 160; mov->tracks[i].frameCount = mov->tracks[i].samples; mov->tracks[i].trackDuration = mov->tracks[i].samples * mov->tracks[i].sampleDelta; mov->tracks[i].timescale = 8000; } else { int j; for (j=0; j<=mov->tracks[i].entry; j++) { int cl = j / MOV_INDEX_CLUSTER_SIZE; int id = j % MOV_INDEX_CLUSTER_SIZE; trackDuration += mov->tracks[i].cluster[cl][id].len; } mov->tracks[i].frameCount = trackDuration; mov->tracks[i].timescale = mov->tracks[i].enc->sample_rate; mov->tracks[i].sampleDelta = 1; mov->tracks[i].trackDuration = trackDuration; }
else { mov->tracks[i].timescale = mov->tracks[i].enc->sample_rate; mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_size;
static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov){    int pos, i;    pos = url_ftell(pb);    put_be32(pb, 0); /* size placeholder*/    put_tag(pb, "moov");    mov->timescale = globalTimescale;    for (i=0; i<MAX_STREAMS; i++) {        if(mov->tracks[i].entry > 0) {            if(mov->tracks[i].enc->codec_type == CODEC_TYPE_VIDEO) {                mov->tracks[i].timescale = globalTimescale;                mov->tracks[i].sampleDelta = mov->tracks[i].enc->frame_rate_base;                mov->tracks[i].frameCount = mov->tracks[i].samples;                mov->tracks[i].trackDuration = (int64_t)((int64_t)mov->tracks[i].entry*                    (int64_t)globalTimescale*(int64_t)mov->tracks[i].enc->frame_rate_base)/(int64_t)mov->tracks[i].enc->frame_rate;            }            else if(mov->tracks[i].enc->codec_type == CODEC_TYPE_AUDIO) {                long trackDuration = 0;                /* If AMR, track timescale = 8000, AMR_WB = 16000 */                if(mov->tracks[i].enc->codec_id == CODEC_ID_AMR_NB) {                    int j;                    for (j=0; j<mov->tracks[i].samples; j++) {                        int cl = j / MOV_INDEX_CLUSTER_SIZE;                        int id = j % MOV_INDEX_CLUSTER_SIZE;                        trackDuration += mov->tracks[i].cluster[cl][id].entries;                    }                    mov->tracks[i].sampleDelta = 160;  // Bytes per chunk                    mov->tracks[i].frameCount = mov->tracks[i].samples;                    mov->tracks[i].trackDuration =                         mov->tracks[i].samples * mov->tracks[i].sampleDelta; //trackDuration                    mov->tracks[i].timescale = 8000;                }                else {                    int j;                    for (j=0; j<=mov->tracks[i].entry; j++) {                        int cl = j / MOV_INDEX_CLUSTER_SIZE;                        int id = j % MOV_INDEX_CLUSTER_SIZE;                        trackDuration += mov->tracks[i].cluster[cl][id].len;                    }                    mov->tracks[i].frameCount = trackDuration;                    mov->tracks[i].timescale = mov->tracks[i].enc->sample_rate;                    mov->tracks[i].sampleDelta = 1;                    mov->tracks[i].trackDuration = trackDuration;                }            }            mov->tracks[i].time = mov->time;            mov->tracks[i].trackID = i+1;        }    }    mov_write_mvhd_tag(pb, mov);    //mov_write_iods_tag(pb, mov);    for (i=0; i<MAX_STREAMS; i++) {        if(mov->tracks[i].entry > 0) {            mov_write_trak_tag(pb, &(mov->tracks[i]));        }    }    return updateSize(pb, pos);}