doc/examples/muxing: Exchange tmp_frame and frame
Reduces difference to 56f98e340fca894a76d1ddbe33118b8d8c4db34a Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
ad91bf854b
commit
c437765be7
@ -235,10 +235,10 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, A
|
|||||||
else
|
else
|
||||||
nb_samples = c->frame_size;
|
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);
|
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 */
|
/* create resampler context */
|
||||||
ost->swr_ctx = swr_alloc();
|
ost->swr_ctx = swr_alloc();
|
||||||
@ -266,15 +266,16 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, A
|
|||||||
* 'nb_channels' channels. */
|
* 'nb_channels' channels. */
|
||||||
static AVFrame *get_audio_frame(OutputStream *ost)
|
static AVFrame *get_audio_frame(OutputStream *ost)
|
||||||
{
|
{
|
||||||
|
AVFrame *frame = ost->tmp_frame;
|
||||||
int j, i, v;
|
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 */
|
/* check if we want to generate more frames */
|
||||||
if (av_compare_ts(ost->next_pts, ost->st->codec->time_base,
|
if (av_compare_ts(ost->next_pts, ost->st->codec->time_base,
|
||||||
STREAM_DURATION, (AVRational){ 1, 1 }) >= 0)
|
STREAM_DURATION, (AVRational){ 1, 1 }) >= 0)
|
||||||
return NULL;
|
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);
|
v = (int)(sin(ost->t) * 10000);
|
||||||
for (i = 0; i < ost->st->codec->channels; i++)
|
for (i = 0; i < ost->st->codec->channels; i++)
|
||||||
*q++ = v;
|
*q++ = v;
|
||||||
@ -282,10 +283,10 @@ static AVFrame *get_audio_frame(OutputStream *ost)
|
|||||||
ost->tincr += ost->tincr2;
|
ost->tincr += ost->tincr2;
|
||||||
}
|
}
|
||||||
|
|
||||||
ost->frame->pts = ost->next_pts;
|
frame->pts = ost->next_pts;
|
||||||
ost->next_pts += ost->frame->nb_samples;
|
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;
|
* internally;
|
||||||
* make sure we do not overwrite it here
|
* 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)
|
if (ret < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
/* convert to destination format */
|
/* convert to destination format */
|
||||||
ret = swr_convert(ost->swr_ctx,
|
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);
|
(const uint8_t **)frame->data, frame->nb_samples);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "Error while converting\n");
|
fprintf(stderr, "Error while converting\n");
|
||||||
exit(1);
|
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);
|
frame->pts = av_rescale_q(ost->samples_count, (AVRational){1, c->sample_rate}, c->time_base);
|
||||||
ost->samples_count += dst_nb_samples;
|
ost->samples_count += dst_nb_samples;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user