[FFmpeg-cvslog] doc/examples/filtering_audio: fix chunked audio decoding

Stefano Sabatini git at videolan.org
Mon Dec 2 15:23:33 CET 2013


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Mon Dec  2 15:21:52 2013 +0100| [c490cd4c1ae36246e9ae510c252dce65a432c125] | committer: Stefano Sabatini

doc/examples/filtering_audio: fix chunked audio decoding

Support the case when multiple frames are contained in a single packet.
In particular, fix fate-samples/lossless-audio/luckynight-partial.shn
sample decoding.

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

 doc/examples/filtering_audio.c |   19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/doc/examples/filtering_audio.c b/doc/examples/filtering_audio.c
index 0be2654..5802d90 100644
--- a/doc/examples/filtering_audio.c
+++ b/doc/examples/filtering_audio.c
@@ -196,7 +196,7 @@ static void print_frame(const AVFrame *frame)
 int main(int argc, char **argv)
 {
     int ret;
-    AVPacket packet;
+    AVPacket packet0, packet;
     AVFrame *frame = av_frame_alloc();
     AVFrame *filt_frame = av_frame_alloc();
     int got_frame;
@@ -220,9 +220,13 @@ int main(int argc, char **argv)
         goto end;
 
     /* read all packets */
+    packet.data = NULL;
     while (1) {
-        if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
-            break;
+        if (!packet0.data) {
+            if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
+                break;
+            packet0 = packet;
+        }
 
         if (packet.stream_index == audio_stream_index) {
             avcodec_get_frame_defaults(frame);
@@ -232,6 +236,8 @@ int main(int argc, char **argv)
                 av_log(NULL, AV_LOG_ERROR, "Error decoding audio\n");
                 continue;
             }
+            packet.size -= ret;
+            packet.data += ret;
 
             if (got_frame) {
                 /* push the audio data from decoded frame into the filtergraph */
@@ -251,8 +257,13 @@ int main(int argc, char **argv)
                     av_frame_unref(filt_frame);
                 }
             }
+
+            if (packet.size <= 0)
+                av_free_packet(&packet0);
+        } else {
+            /* discard non-wanted packets */
+            av_free_packet(&packet0);
         }
-        av_free_packet(&packet);
     }
 end:
     avfilter_graph_free(&filter_graph);



More information about the ffmpeg-cvslog mailing list