From d1ce43a3e8fe18e29a334b1a2fda82215f86f2b9 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sun, 27 Jul 2014 01:35:10 +0200 Subject: [PATCH] doc/examples/muxing: mark correct frame as writeable Bug found from comparing 56f98e340fca894a76d1ddbe33118b8d8c4db34a to HEAD Signed-off-by: Michael Niedermayer --- doc/examples/muxing.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c index 2d97fde387..4216a563a7 100644 --- a/doc/examples/muxing.c +++ b/doc/examples/muxing.c @@ -266,7 +266,7 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, A * 'nb_channels' channels. */ static AVFrame *get_audio_frame(OutputStream *ost) { - int j, i, v, ret; + int j, i, v; int16_t *q = (int16_t*)ost->frame->data[0]; /* check if we want to generate more frames */ @@ -274,14 +274,6 @@ static AVFrame *get_audio_frame(OutputStream *ost) STREAM_DURATION, (AVRational){ 1, 1 }) >= 0) return NULL; - /* when we pass a frame to the encoder, it may keep a reference to it - * internally; - * make sure we do not overwrite it here - */ - ret = av_frame_make_writable(ost->frame); - if (ret < 0) - exit(1); - for (j = 0; j < ost->frame->nb_samples; j++) { v = (int)(sin(ost->t) * 10000); for (i = 0; i < ost->st->codec->channels; i++) @@ -321,6 +313,14 @@ static int write_audio_frame(AVFormatContext *oc, OutputStream *ost) c->sample_rate, c->sample_rate, AV_ROUND_UP); av_assert0(dst_nb_samples == frame->nb_samples); + /* when we pass a frame to the encoder, it may keep a reference to it + * internally; + * make sure we do not overwrite it here + */ + ret = av_frame_make_writable(ost->tmp_frame); + if (ret < 0) + exit(1); + /* convert to destination format */ ret = swr_convert(ost->swr_ctx, ost->tmp_frame->data, dst_nb_samples,