examples/filtering_audio: update to new API
In particular, fix crash.
This commit is contained in:
@@ -150,11 +150,10 @@ static int init_filters(const char *filters_descr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_samplesref(AVFilterBufferRef *samplesref)
|
static void print_frame(AVFrame *frame)
|
||||||
{
|
{
|
||||||
const AVFilterBufferRefAudioProps *props = samplesref->audio;
|
const int n = frame->nb_samples * av_get_channel_layout_nb_channels(av_frame_get_channel_layout(frame));
|
||||||
const int n = props->nb_samples * av_get_channel_layout_nb_channels(props->channel_layout);
|
const uint16_t *p = (uint16_t*)frame->data[0];
|
||||||
const uint16_t *p = (uint16_t*)samplesref->data[0];
|
|
||||||
const uint16_t *p_end = p + n;
|
const uint16_t *p_end = p + n;
|
||||||
|
|
||||||
while (p < p_end) {
|
while (p < p_end) {
|
||||||
@@ -169,10 +168,11 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
AVFrame *frame = avcodec_alloc_frame();
|
AVFrame *frame = av_frame_alloc();
|
||||||
|
AVFrame *filt_frame = av_frame_alloc();
|
||||||
int got_frame;
|
int got_frame;
|
||||||
|
|
||||||
if (!frame) {
|
if (!frame || !filt_frame) {
|
||||||
perror("Could not allocate frame");
|
perror("Could not allocate frame");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,6 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* read all packets */
|
/* read all packets */
|
||||||
while (1) {
|
while (1) {
|
||||||
AVFilterBufferRef *samplesref;
|
|
||||||
if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
|
if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -207,22 +206,20 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (got_frame) {
|
if (got_frame) {
|
||||||
/* push the audio data from decoded frame into the filtergraph */
|
/* push the audio data from decoded frame into the filtergraph */
|
||||||
if (av_buffersrc_add_frame(buffersrc_ctx, frame) < 0) {
|
if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) {
|
||||||
av_log(NULL, AV_LOG_ERROR, "Error while feeding the audio filtergraph\n");
|
av_log(NULL, AV_LOG_ERROR, "Error while feeding the audio filtergraph\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pull filtered audio from the filtergraph */
|
/* pull filtered audio from the filtergraph */
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = av_buffersink_get_buffer_ref(buffersink_ctx, &samplesref, 0);
|
ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
|
||||||
if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
|
if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
|
||||||
break;
|
break;
|
||||||
if(ret < 0)
|
if(ret < 0)
|
||||||
goto end;
|
goto end;
|
||||||
if (samplesref) {
|
print_frame(filt_frame);
|
||||||
print_samplesref(samplesref);
|
av_frame_unref(filt_frame);
|
||||||
avfilter_unref_bufferp(&samplesref);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,7 +230,8 @@ end:
|
|||||||
if (dec_ctx)
|
if (dec_ctx)
|
||||||
avcodec_close(dec_ctx);
|
avcodec_close(dec_ctx);
|
||||||
avformat_close_input(&fmt_ctx);
|
avformat_close_input(&fmt_ctx);
|
||||||
av_freep(&frame);
|
av_frame_free(&frame);
|
||||||
|
av_frame_free(&filt_frame);
|
||||||
|
|
||||||
if (ret < 0 && ret != AVERROR_EOF) {
|
if (ret < 0 && ret != AVERROR_EOF) {
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
Reference in New Issue
Block a user