- /* if we get an encoded packet, feed it straight to the decoder */
- if (got_output) {
- result = avcodec_decode_audio4(dec_ctx, out_frame, &got_output, &enc_pkt);
+ while (result >= 0) {
+ result = avcodec_receive_packet(enc_ctx, &enc_pkt);
+ if (result == AVERROR(EAGAIN))
+ break;
+ else if (result < 0 && result != AVERROR_EOF) {
+ av_log(NULL, AV_LOG_ERROR, "Error encoding audio frame\n");
+ return result;
+ }
+
+ /* if we get an encoded packet, feed it straight to the decoder */
+ result = avcodec_send_packet(dec_ctx, &enc_pkt);
+ av_packet_unref(&enc_pkt);