~ppsspp/ppsspp/ffmpeg

« back to all changes in this revision

Viewing changes to doc/examples/muxing.c

  • Committer: Henrik Rydgård
  • Date: 2014-01-03 10:44:32 UTC
  • Revision ID: git-v1:87c6c126784b1718bfa448ecf2e6a9fef781eb4e
Update our ffmpeg snapshot to a clone of the official repository.

This is because Maxim's at3plus support has been officially merged!

Show diffs side-by-side

added added

removed removed

Lines of Context:
157
157
        10000 : c->frame_size;
158
158
 
159
159
    ret = av_samples_alloc_array_and_samples(&src_samples_data, &src_samples_linesize, c->channels,
160
 
                                             src_nb_samples, c->sample_fmt, 0);
 
160
                                             src_nb_samples, AV_SAMPLE_FMT_S16, 0);
161
161
    if (ret < 0) {
162
162
        fprintf(stderr, "Could not allocate source samples\n");
163
163
        exit(1);
164
164
    }
165
165
 
 
166
    /* compute the number of converted samples: buffering is avoided
 
167
     * ensuring that the output buffer will contain at least all the
 
168
     * converted input samples */
 
169
    max_dst_nb_samples = src_nb_samples;
 
170
 
166
171
    /* create resampler context */
167
172
    if (c->sample_fmt != AV_SAMPLE_FMT_S16) {
168
173
        swr_ctx = swr_alloc();
184
189
            fprintf(stderr, "Failed to initialize the resampling context\n");
185
190
            exit(1);
186
191
        }
187
 
    }
188
192
 
189
 
    /* compute the number of converted samples: buffering is avoided
190
 
     * ensuring that the output buffer will contain at least all the
191
 
     * converted input samples */
192
 
    max_dst_nb_samples = src_nb_samples;
193
 
    ret = av_samples_alloc_array_and_samples(&dst_samples_data, &dst_samples_linesize, c->channels,
194
 
                                             max_dst_nb_samples, c->sample_fmt, 0);
195
 
    if (ret < 0) {
196
 
        fprintf(stderr, "Could not allocate destination samples\n");
197
 
        exit(1);
 
193
        ret = av_samples_alloc_array_and_samples(&dst_samples_data, &dst_samples_linesize, c->channels,
 
194
                                                 max_dst_nb_samples, c->sample_fmt, 0);
 
195
        if (ret < 0) {
 
196
            fprintf(stderr, "Could not allocate destination samples\n");
 
197
            exit(1);
 
198
        }
 
199
    } else {
 
200
        dst_samples_data = src_samples_data;
198
201
    }
199
202
    dst_samples_size = av_samples_get_buffer_size(NULL, c->channels, max_dst_nb_samples,
200
203
                                                  c->sample_fmt, 0);
221
224
{
222
225
    AVCodecContext *c;
223
226
    AVPacket pkt = { 0 }; // data and size must be 0;
224
 
    AVFrame *frame = avcodec_alloc_frame();
 
227
    AVFrame *frame = av_frame_alloc();
225
228
    int got_packet, ret, dst_nb_samples;
226
229
 
227
230
    av_init_packet(&pkt);
254
257
            exit(1);
255
258
        }
256
259
    } else {
257
 
        dst_samples_data[0] = src_samples_data[0];
258
260
        dst_nb_samples = src_nb_samples;
259
261
    }
260
262
 
269
271
    }
270
272
 
271
273
    if (!got_packet)
272
 
        return;
 
274
        goto freeframe;
273
275
 
274
276
    pkt.stream_index = st->index;
275
277
 
280
282
                av_err2str(ret));
281
283
        exit(1);
282
284
    }
283
 
    avcodec_free_frame(&frame);
 
285
freeframe:
 
286
    av_frame_free(&frame);
284
287
}
285
288
 
286
289
static void close_audio(AVFormatContext *oc, AVStream *st)
287
290
{
288
291
    avcodec_close(st->codec);
 
292
    if (dst_samples_data != src_samples_data) {
 
293
        av_free(dst_samples_data[0]);
 
294
        av_free(dst_samples_data);
 
295
    }
289
296
    av_free(src_samples_data[0]);
290
 
    av_free(dst_samples_data[0]);
 
297
    av_free(src_samples_data);
291
298
}
292
299
 
293
300
/**************************************************************/
310
317
    }
311
318
 
312
319
    /* allocate and init a re-usable frame */
313
 
    frame = avcodec_alloc_frame();
 
320
    frame = av_frame_alloc();
314
321
    if (!frame) {
315
322
        fprintf(stderr, "Could not allocate video frame\n");
316
323
        exit(1);