[FFmpeg-cvslog] examples/filtering_audio: update to new API

Stefano Sabatini git at videolan.org
Thu Mar 14 21:40:05 CET 2013


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Wed Mar 13 22:08:33 2013 +0100| [9076a6a943f7855756222181698aba78d3773d8f] | committer: Stefano Sabatini

examples/filtering_audio: update to new API

In particular, fix crash.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9076a6a943f7855756222181698aba78d3773d8f
---

 doc/examples/filtering_audio.c |   26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/doc/examples/filtering_audio.c b/doc/examples/filtering_audio.c
index ad69d32..01e6926 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];



More information about the ffmpeg-cvslog mailing list