Revision 2940b38e libavformat/ffmenc.c

View differences:

libavformat/ffmenc.c
92 92
{
93 93
    FFMContext *ffm = s->priv_data;
94 94
    AVStream *st;
95
    FFMStream *fst;
96 95
    ByteIOContext *pb = s->pb;
97 96
    AVCodecContext *codec;
98 97
    int bit_rate, i;
......
116 115
    /* list of streams */
117 116
    for(i=0;i<s->nb_streams;i++) {
118 117
        st = s->streams[i];
119
        fst = av_mallocz(sizeof(FFMStream));
120
        if (!fst)
121
            goto fail;
122 118
        av_set_pts_info(st, 64, 1, 1000000);
123
        st->priv_data = fst;
124 119

  
125 120
        codec = st->codec;
126 121
        /* generic info */
......
176 171
        default:
177 172
            return -1;
178 173
        }
179
        /* hack to have real time */
180
        if (ffm_nopts)
181
            fst->pts = 0;
182
        else
183
            fst->pts = av_gettime();
184 174
    }
185 175

  
176
    /* hack to have real time */
177
    if (ffm_nopts)
178
        ffm->start_time = 0;
179
    else
180
        ffm->start_time = av_gettime();
181

  
186 182
    /* flush until end of block reached */
187 183
    while ((url_ftell(pb) % ffm->packet_size) != 0)
188 184
        put_byte(pb, 0);
......
198 194
    ffm->first_packet = 1;
199 195

  
200 196
    return 0;
201
 fail:
202
    for(i=0;i<s->nb_streams;i++) {
203
        st = s->streams[i];
204
        av_freep(&st->priv_data);
205
    }
206
    return -1;
207 197
}
208 198

  
209 199
static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt)
210 200
{
201
    FFMContext *ffm = s->priv_data;
211 202
    AVStream *st = s->streams[pkt->stream_index];
212
    FFMStream *fst = st->priv_data;
213 203
    int64_t pts;
214 204
    uint8_t header[FRAME_HEADER_SIZE];
215 205

  
216
    pts = fst->pts;
206
    pts = ffm->start_time + pkt->pts;
217 207
    /* packet size & key_frame */
218 208
    header[0] = pkt->stream_index;
219 209
    header[1] = 0;
......
224 214
    ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1);
225 215
    ffm_write_data(s, pkt->data, pkt->size, pts, 0);
226 216

  
227
    fst->pts += pkt->duration;
228 217
    return 0;
229 218
}
230 219

  

Also available in: Unified diff