[Libav-user] Demuxing audio streams and flushing

Manu N audionuma at gmail.com
Mon Sep 23 07:42:04 CEST 2013

I'm currently trying to use libavformat to demux audio from multimedia
I'm using the demuxing.c example (in ffmpeg-2.0.1/doc/examples/) as a
starting point.
I have a problem understanding the flushing part of this example.

As I only need to demux audio, I have commented out the whole video
decoding part like this :

    if (pkt.stream_index == video_stream_idx) {
//        /* decode video frame */
//        ret = avcodec_decode_video2(video_dec_ctx, frame, got_frame,
//        if (ret < 0) {
//            fprintf(stderr, "Error decoding video frame\n");
//            return ret;
//        }
//        if (*got_frame) {
//            printf("video_frame%s n:%d coded_n:%d pts:%s\n",
//                   cached ? "(cached)" : "",
//                   video_frame_count++, frame->coded_picture_number,
//                   av_ts2timestr(frame->pts, &video_dec_ctx->time_base));
//            /* copy decoded frame to destination buffer:
//             * this is required since rawvideo expects non aligned data */
//            av_image_copy(video_dst_data, video_dst_linesize,
//                          (const uint8_t **)(frame->data),
//                          video_dec_ctx->pix_fmt, video_dec_ctx->width,
//            /* write to rawvideo file */
//            fwrite(video_dst_data[0], 1, video_dst_bufsize,
//        }
    } else if (pkt.stream_index == audio_stream_idx) {

I can run succesfully on audio only files (.wav, .ac3, ...).
But when I run it on a video + audio file (stream #0 video, stream #1
audio), I go into a never ending loop at the flushing part of the code :

    do {
        decode_packet(&got_frame, 1);
    } while (got_frame);

What happens is that at this point, pkt.stream_index == 0, so
avcodec_decode_audio4() is never called in the decode_packet function, and
got_frame is never set to 0.

My question is : do audio streams need flushing at all or is it only for
video streams ? If flushing is needed for audio streams, how to handle it
properly, given the fact that my goal is to demux all audio streams in a
file ?

Thanks for your advices,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130923/5f948fd0/attachment.html>

More information about the Libav-user mailing list