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) continue;



        if(mov->tracks[i].enc->codec_type == CODEC_TYPE_VIDEO) {

            mov->tracks[i].timescale = mov->tracks[i].enc->frame_rate;

            mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_rate_base;

        }

        else if(mov->tracks[i].enc->codec_type == CODEC_TYPE_AUDIO) {

            /* If AMR, track timescale = 8000, AMR_WB = 16000 */

            if(mov->tracks[i].enc->codec_id == CODEC_ID_AMR_NB) {

                mov->tracks[i].sampleDuration = 160;  // Bytes per chunk

                mov->tracks[i].timescale = 8000;

            }

            else {

                mov->tracks[i].timescale = mov->tracks[i].enc->sample_rate;

                mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_size;

            }

        }



        mov->tracks[i].trackDuration = 

            mov->tracks[i].sampleCount * mov->tracks[i].sampleDuration;

        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);

}

static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov)

{

    int pos, i;

    pos = url_ftell(pb);

    put_be32(pb, 0); 

    put_tag(pb, "moov");

    mov->timescale = globalTimescale;



    for (i=0; i<MAX_STREAMS; i++) {

        if(mov->tracks[i].entry <= 0) continue;



        if(mov->tracks[i].enc->codec_type == CODEC_TYPE_VIDEO) {

            mov->tracks[i].timescale = mov->tracks[i].enc->frame_rate;

            mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_rate_base;

        }

        else if(mov->tracks[i].enc->codec_type == CODEC_TYPE_AUDIO) {

            

            if(mov->tracks[i].enc->codec_id == CODEC_ID_AMR_NB) {

                mov->tracks[i].sampleDuration = 160;  

                mov->tracks[i].timescale = 8000;

            }

            else {

                mov->tracks[i].timescale = mov->tracks[i].enc->sample_rate;

                mov->tracks[i].sampleDuration = mov->tracks[i].enc->frame_size;

            }

        }



        mov->tracks[i].trackDuration = 

            mov->tracks[i].sampleCount * mov->tracks[i].sampleDuration;

        mov->tracks[i].time = mov->time;

        mov->tracks[i].trackID = i+1;

    }



    mov_write_mvhd_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);

}

static int FUNC_0(ByteIOContext *VAR_0, MOVContext *VAR_1)

{

    int VAR_2, VAR_3;

    VAR_2 = url_ftell(VAR_0);

    put_be32(VAR_0, 0); 

    put_tag(VAR_0, "moov");

    VAR_1->timescale = globalTimescale;



    for (VAR_3=0; VAR_3<MAX_STREAMS; VAR_3++) {

        if(VAR_1->tracks[VAR_3].entry <= 0) continue;



        if(VAR_1->tracks[VAR_3].enc->codec_type == CODEC_TYPE_VIDEO) {

            VAR_1->tracks[VAR_3].timescale = VAR_1->tracks[VAR_3].enc->frame_rate;

            VAR_1->tracks[VAR_3].sampleDuration = VAR_1->tracks[VAR_3].enc->frame_rate_base;

        }

        else if(VAR_1->tracks[VAR_3].enc->codec_type == CODEC_TYPE_AUDIO) {

            

            if(VAR_1->tracks[VAR_3].enc->codec_id == CODEC_ID_AMR_NB) {

                VAR_1->tracks[VAR_3].sampleDuration = 160;  

                VAR_1->tracks[VAR_3].timescale = 8000;

            }

            else {

                VAR_1->tracks[VAR_3].timescale = VAR_1->tracks[VAR_3].enc->sample_rate;

                VAR_1->tracks[VAR_3].sampleDuration = VAR_1->tracks[VAR_3].enc->frame_size;

            }

        }



        VAR_1->tracks[VAR_3].trackDuration = 

            VAR_1->tracks[VAR_3].sampleCount * VAR_1->tracks[VAR_3].sampleDuration;

        VAR_1->tracks[VAR_3].time = VAR_1->time;

        VAR_1->tracks[VAR_3].trackID = VAR_3+1;

    }



    mov_write_mvhd_tag(VAR_0, VAR_1);

    

    for (VAR_3=0; VAR_3<MAX_STREAMS; VAR_3++) {

        if(VAR_1->tracks[VAR_3].entry > 0) {

            mov_write_trak_tag(VAR_0, &(VAR_1->tracks[VAR_3]));

        }

    }



    return updateSize(VAR_0, VAR_2);

}

static int FUNC_0(ByteIOContext *VAR_0, MOVContext *VAR_1)
{ int VAR_2, VAR_3; VAR_2 = url_ftell(VAR_0); put_be32(VAR_0, 0); put_tag(VAR_0, "moov"); VAR_1->timescale = globalTimescale; for (VAR_3=0; VAR_3<MAX_STREAMS; VAR_3++) { if(VAR_1->tracks[VAR_3].entry <= 0) continue; if(VAR_1->tracks[VAR_3].enc->codec_type == CODEC_TYPE_VIDEO) { VAR_1->tracks[VAR_3].timescale = VAR_1->tracks[VAR_3].enc->frame_rate; VAR_1->tracks[VAR_3].sampleDuration = VAR_1->tracks[VAR_3].enc->frame_rate_base; } else if(VAR_1->tracks[VAR_3].enc->codec_type == CODEC_TYPE_AUDIO) { if(VAR_1->tracks[VAR_3].enc->codec_id == CODEC_ID_AMR_NB) { VAR_1->tracks[VAR_3].sampleDuration = 160; VAR_1->tracks[VAR_3].timescale = 8000; } else { VAR_1->tracks[VAR_3].timescale = VAR_1->tracks[VAR_3].enc->sample_rate; VAR_1->tracks[VAR_3].sampleDuration = VAR_1->tracks[VAR_3].enc->frame_size; } } VAR_1->tracks[VAR_3].trackDuration =
VAR_1->tracks[VAR_3].sampleCount * VAR_1->tracks[VAR_3].sampleDuration; VAR_1->tracks[VAR_3].time = VAR_1->time; VAR_1->tracks[VAR_3].trackID = VAR_3+1; } mov_write_mvhd_tag(VAR_0, VAR_1); for (VAR_3=0; VAR_3<MAX_STREAMS; VAR_3++) { if(VAR_1->tracks[VAR_3].entry > 0) { mov_write_trak_tag(VAR_0, &(VAR_1->tracks[VAR_3])); } } return updateSize(VAR_0, VAR_2); }