- int err = avcodec_receive_frame(audio_codec_ctx, audio_avframe.get());
- if (err == 0) {
- convert_audio(audio_avframe.get(), audio_frame, audio_format);
- } else if (err != AVERROR(EAGAIN)) {
- fprintf(stderr, "%s: Cannot receive frame from audio codec.\n", pathname.c_str());
- *error = true;
- return AVFrameWithDeleter(nullptr);
+ if (*audio_pts != -1) {
+ for ( ;; ) {
+ int err = avcodec_receive_frame(audio_codec_ctx, audio_avframe.get());
+ if (err == 0) {
+ convert_audio(audio_avframe.get(), audio_frame, audio_format);
+ } else if (err == AVERROR(EAGAIN)) {
+ break;
+ } else {
+ fprintf(stderr, "%s: Cannot receive frame from audio codec.\n", pathname.c_str());
+ *error = true;
+ return AVFrameWithDeleter(nullptr);
+ }
+ }