<div dir="ltr"><div><div><div><div><div><div><div><div><div><div>Hello,<br></div>I'm currently trying to use libavformat to demux audio from multimedia files.<br></div>I'm using the demuxing.c example (in ffmpeg-2.0.1/doc/examples/) as a starting point.<br>
</div>I have a problem understanding the flushing part of this example.<br><br></div>As I only need to demux audio, I have commented out the whole video decoding part like this :<br><br> if (pkt.stream_index == video_stream_idx) {<br>
// /* decode video frame */<br>// ret = avcodec_decode_video2(video_dec_ctx, frame, got_frame, &pkt);<br>// if (ret < 0) {<br>// fprintf(stderr, "Error decoding video frame\n");<br>
// return ret;<br>// }<br>//<br>// if (*got_frame) {<br>// printf("video_frame%s n:%d coded_n:%d pts:%s\n",<br>// cached ? "(cached)" : "",<br>
// video_frame_count++, frame->coded_picture_number,<br>// av_ts2timestr(frame->pts, &video_dec_ctx->time_base));<br>//<br>// /* copy decoded frame to destination buffer:<br>
// * this is required since rawvideo expects non aligned data */<br>// av_image_copy(video_dst_data, video_dst_linesize,<br>// (const uint8_t **)(frame->data), frame->linesize,<br>
// video_dec_ctx->pix_fmt, video_dec_ctx->width, video_dec_ctx->height);<br>//<br>// /* write to rawvideo file */<br>// fwrite(video_dst_data[0], 1, video_dst_bufsize, video_dst_file);<br>
// }<br> } else if (pkt.stream_index == audio_stream_idx) {<br><br><br></div>I can run succesfully on audio only files (.wav, .ac3, ...).<br></div>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 :<br>
<br> do {<br> decode_packet(&got_frame, 1);<br> } while (got_frame);<br><br></div>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.<br>
<br></div>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 ?<br>
<br></div>Thanks for your advices,<br></div>Manuel<br><br></div>