aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2013-03-13 22:08:33 +0100
committerStefano Sabatini <stefasab@gmail.com>2013-03-14 21:39:09 +0100
commit9076a6a943f7855756222181698aba78d3773d8f (patch)
tree72f23a7daa41f997db80de6238a5fc40607ff47f
parentf0da370a523d76fb5f48e58537f26a9d949e9c05 (diff)
downloadffmpeg-9076a6a943f7855756222181698aba78d3773d8f.tar.gz
examples/filtering_audio: update to new API
In particular, fix crash.
-rw-r--r--doc/examples/filtering_audio.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/doc/examples/filtering_audio.c b/doc/examples/filtering_audio.c
index ad69d32c64..01e692688a 100644
--- a/doc/examples/filtering_audio.c
+++ b/doc/examples/filtering_audio.c
@@ -150,11 +150,10 @@ static int init_filters(const char *filters_descr)
return 0;
}
-static void print_samplesref(AVFilterBufferRef *samplesref)
+static void print_frame(AVFrame *frame)
{
- const AVFilterBufferRefAudioProps *props = samplesref->audio;
- const int n = props->nb_samples * av_get_channel_layout_nb_channels(props->channel_layout);
- const uint16_t *p = (uint16_t*)samplesref->data[0];
+ const int n = frame->nb_samples * av_get_channel_layout_nb_channels(av_frame_get_channel_layout(frame));
+ const uint16_t *p = (uint16_t*)frame->data[0];
const uint16_t *p_end = p + n;
while (p < p_end) {
@@ -169,10 +168,11 @@ int main(int argc, char **argv)
{
int ret;
AVPacket packet;
- AVFrame *frame = avcodec_alloc_frame();
+ AVFrame *frame = av_frame_alloc();
+ AVFrame *filt_frame = av_frame_alloc();
int got_frame;
- if (!frame) {
+ if (!frame || !filt_frame) {
perror("Could not allocate frame");
exit(1);
}
@@ -192,7 +192,6 @@ int main(int argc, char **argv)
/* read all packets */
while (1) {
- AVFilterBufferRef *samplesref;
if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
break;
@@ -207,22 +206,20 @@ int main(int argc, char **argv)
if (got_frame) {
/* 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");
break;
}
/* pull filtered audio from the filtergraph */
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)
break;
if(ret < 0)
goto end;
- if (samplesref) {
- print_samplesref(samplesref);
- avfilter_unref_bufferp(&samplesref);
- }
+ print_frame(filt_frame);
+ av_frame_unref(filt_frame);
}
}
}
@@ -233,7 +230,8 @@ end:
if (dec_ctx)
avcodec_close(dec_ctx);
avformat_close_input(&fmt_ctx);
- av_freep(&frame);
+ av_frame_free(&frame);
+ av_frame_free(&filt_frame);
if (ret < 0 && ret != AVERROR_EOF) {
char buf[1024];