- if (av_read_frame(format_ctx.get(), &pkt) < 0) {
- break;
- }
- if (pkt.stream_index != stream_index) {
- continue;
+ if (av_read_frame(format_ctx.get(), &pkt) == 0) {
+ if (pkt.stream_index != stream_index) {
+ continue;
+ }
+ if (avcodec_send_packet(codec_ctx, &pkt) < 0) {
+ fprintf(stderr, "%s: Cannot send packet to codec.\n", pathname.c_str());
+ return nullptr;
+ }
+ } else {
+ eof = true; // Or error, but ignore that for the time being.