Revision d794d388

View differences:

libavformat/wav.c
25 25
typedef struct {
26 26
    offset_t data;
27 27
    offset_t data_end;
28
    int64_t minpts;
29
    int64_t maxpts;
30
    int last_duration;
28 31
} WAVContext;
29 32

  
30 33
#ifdef CONFIG_MUXERS
......
32 35
{
33 36
    WAVContext *wav = s->priv_data;
34 37
    ByteIOContext *pb = &s->pb;
35
    offset_t fmt;
38
    offset_t fmt, fact;
36 39

  
37 40
    put_tag(pb, "RIFF");
38 41
    put_le32(pb, 0); /* file length */
......
46 49
    }
47 50
    end_tag(pb, fmt);
48 51

  
52
    if(s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */
53
       && !url_is_streamed(&s->pb)) {
54
        fact = start_tag(pb, "fact");
55
        put_le32(pb, 0);
56
        end_tag(pb, fact);
57
    }
58

  
49 59
    av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
60
    wav->maxpts = wav->last_duration = 0;
61
    wav->minpts = INT64_MAX;
50 62

  
51 63
    /* data header */
52 64
    wav->data = start_tag(pb, "data");
......
59 71
static int wav_write_packet(AVFormatContext *s, AVPacket *pkt)
60 72
{
61 73
    ByteIOContext *pb = &s->pb;
74
    WAVContext *wav = s->priv_data;
62 75
    put_buffer(pb, pkt->data, pkt->size);
76
    if(pkt->pts != AV_NOPTS_VALUE) {
77
        wav->minpts = FFMIN(wav->minpts, pkt->pts);
78
        wav->maxpts = FFMAX(wav->maxpts, pkt->pts);
79
        wav->last_duration = pkt->duration;
80
    } else
81
        av_log(s, AV_LOG_ERROR, "wav_write_packet: NOPTS\n");
63 82
    return 0;
64 83
}
65 84

  
......
79 98
        url_fseek(pb, file_size, SEEK_SET);
80 99

  
81 100
        put_flush_packet(pb);
101

  
102
        if(s->streams[0]->codec->codec_tag != 0x01) {
103
            /* Update num_samps in fact chunk */
104
            int number_of_samples;
105
            number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration,
106
                                           s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num,
107
                                           s->streams[0]->time_base.den);
108
            url_fseek(pb, wav->data-12, SEEK_SET);
109
            put_le32(pb, number_of_samples);
110
            url_fseek(pb, file_size, SEEK_SET);
111
            put_flush_packet(pb);
112
        }
82 113
    }
83 114
    return 0;
84 115
}

Also available in: Unified diff