aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-07-27 04:10:06 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-07-27 12:03:51 +0200
commitc437765be7628c9dacb64aa1c1c46c0c39df1ca9 (patch)
treec8fb8ba1065857fc6ae407e797ac20531cb78139
parentad91bf854b559f1afc42fc06f8a7dfbb75def5c8 (diff)
downloadffmpeg-c437765be7628c9dacb64aa1c1c46c0c39df1ca9.tar.gz
doc/examples/muxing: Exchange tmp_frame and frame
Reduces difference to 56f98e340fca894a76d1ddbe33118b8d8c4db34a Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--doc/examples/muxing.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c
index 4216a563a7..934698a1d7 100644
--- a/doc/examples/muxing.c
+++ b/doc/examples/muxing.c
@@ -235,10 +235,10 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, A
else
nb_samples = c->frame_size;
- ost->frame = alloc_audio_frame(AV_SAMPLE_FMT_S16, c->channel_layout,
+ ost->frame = alloc_audio_frame(c->sample_fmt, c->channel_layout,
+ c->sample_rate, nb_samples);
+ ost->tmp_frame = alloc_audio_frame(AV_SAMPLE_FMT_S16, c->channel_layout,
c->sample_rate, nb_samples);
- ost->tmp_frame = alloc_audio_frame(c->sample_fmt, c->channel_layout,
- c->sample_rate, ost->frame->nb_samples);
/* create resampler context */
ost->swr_ctx = swr_alloc();
@@ -266,15 +266,16 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, A
* 'nb_channels' channels. */
static AVFrame *get_audio_frame(OutputStream *ost)
{
+ AVFrame *frame = ost->tmp_frame;
int j, i, v;
- int16_t *q = (int16_t*)ost->frame->data[0];
+ int16_t *q = (int16_t*)frame->data[0];
/* check if we want to generate more frames */
if (av_compare_ts(ost->next_pts, ost->st->codec->time_base,
STREAM_DURATION, (AVRational){ 1, 1 }) >= 0)
return NULL;
- for (j = 0; j < ost->frame->nb_samples; j++) {
+ for (j = 0; j <frame->nb_samples; j++) {
v = (int)(sin(ost->t) * 10000);
for (i = 0; i < ost->st->codec->channels; i++)
*q++ = v;
@@ -282,10 +283,10 @@ static AVFrame *get_audio_frame(OutputStream *ost)
ost->tincr += ost->tincr2;
}
- ost->frame->pts = ost->next_pts;
- ost->next_pts += ost->frame->nb_samples;
+ frame->pts = ost->next_pts;
+ ost->next_pts += frame->nb_samples;
- return ost->frame;
+ return frame;
}
/*
@@ -317,19 +318,19 @@ static int write_audio_frame(AVFormatContext *oc, OutputStream *ost)
* internally;
* make sure we do not overwrite it here
*/
- ret = av_frame_make_writable(ost->tmp_frame);
+ ret = av_frame_make_writable(ost->frame);
if (ret < 0)
exit(1);
/* convert to destination format */
ret = swr_convert(ost->swr_ctx,
- ost->tmp_frame->data, dst_nb_samples,
+ ost->frame->data, dst_nb_samples,
(const uint8_t **)frame->data, frame->nb_samples);
if (ret < 0) {
fprintf(stderr, "Error while converting\n");
exit(1);
}
- frame = ost->tmp_frame;
+ frame = ost->frame;
frame->pts = av_rescale_q(ost->samples_count, (AVRational){1, c->sample_rate}, c->time_base);
ost->samples_count += dst_nb_samples;