From b8ed82afb9f42735e837efd521665a447c91cddc Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 8 Jan 2025 17:22:37 -0500 Subject: [PATCH] Need to receive as many packets as possible after sending frame. Can't just do 1/1 --- src/zm_videostore.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index 4a42a3dfc..c2562bf58 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -1208,14 +1208,6 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr zm_packet) } // end if hwaccel #endif - //zm_packet->out_frame->coded_picture_number = frame_count; - //zm_packet->out_frame->display_picture_number = frame_count; - //zm_packet->out_frame->sample_aspect_ratio = (AVRational){ 0, 1 }; - // Do this to allow the encoder to choose whether to use I/P/B frame - //zm_packet->out_frame->pict_type = AV_PICTURE_TYPE_NONE; - //zm_packet->out_frame->key_frame = zm_packet->keyframe; - //frame->pkt_duration = 0; - if (video_first_pts == AV_NOPTS_VALUE) { video_first_pts = static_cast(std::chrono::duration_cast(zm_packet->timestamp.time_since_epoch()).count()); Debug(2, "No video_first_pts, set to (%" PRId64 ") secs(%.2f)", @@ -1242,13 +1234,20 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr zm_packet) //int ret = zm_send_frame_receive_packet(video_out_ctx, frame, *opkt); int ret = avcodec_send_frame(video_out_ctx, frame); - if (ret <= 0) { - if (ret < 0) { - Error("Could not send frame (error '%s')", av_make_error_string(ret).c_str()); - } + if (ret < 0) { + Error("Could not send frame (error '%s')", av_make_error_string(ret).c_str()); return ret; } - while (0 == avcodec_receive_packet(video_out_ctx, opkt.get())) { + while (true) { + ret = avcodec_receive_packet(video_out_ctx, opkt.get()); + if (ret < 0) { + if (ret != AVERROR(EAGAIN)) { + Error("Could not receive packet (error %d = %s)", ret, av_make_error_string(ret).c_str()); + } else { + Debug(1, "Could not receive packet (error %d = %s)", ret, av_make_error_string(ret).c_str()); + } + return ret; + } pkt_guard.acquire(opkt); ZM_DUMP_PACKET(opkt, "packet returned by codec"); @@ -1306,7 +1305,6 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr zm_packet) write_packet(opkt.get(), video_out_stream); } // end if codec matches - return 1; } // end int VideoStore::writeVideoFramePacket( AVPacket *ipkt )