From 0f5ce831cc23c8f951b0022d9f5d686131e72e30 Mon Sep 17 00:00:00 2001 From: "G.J.R. Timmer" Date: Thu, 11 Jun 2026 04:51:52 -0400 Subject: [PATCH 1/2] fix: print diagnostic messages to stderr instead of stdout ffmpeg pipes video output to downstream processes via stdout. Diagnostic and error messages on stdout corrupt the pipe output. Change all std::cout to std::cerr for error/status messages in NVMPI_frameBuf, nvmpi_dec, and nvmpi_enc. Based on: https://github.com/Keylost/jetson-ffmpeg/pull/15 Co-Authored-By: Andrew Reiter Co-Authored-By: Claude Opus 4.6 --- src/NVMPI_frameBuf.cpp | 8 ++++---- src/nvmpi_dec.cpp | 4 ++-- src/nvmpi_enc.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/NVMPI_frameBuf.cpp b/src/NVMPI_frameBuf.cpp index ddef06e8..3edeb5b9 100644 --- a/src/NVMPI_frameBuf.cpp +++ b/src/NVMPI_frameBuf.cpp @@ -8,14 +8,14 @@ bool NVMPI_frameBuf::alloc(NvBufferCreateParams& input_params) ret = NvBufSurf::NvAllocate(&input_params, 1, &dst_dma_fd); if(ret<0) { - std::cout << "Failed to allocate buffer" << std::endl; + std::cerr << "Failed to allocate buffer" << std::endl; return false; } ret = NvBufSurfaceFromFd(dst_dma_fd, (void**)(&dst_dma_surface)); if(ret<0) { - std::cout << "Failed to get surface for buffer" << std::endl; + std::cerr << "Failed to get surface for buffer" << std::endl; NvBufferDestroy(dst_dma_fd); dst_dma_fd = -1; return false; @@ -24,7 +24,7 @@ bool NVMPI_frameBuf::alloc(NvBufferCreateParams& input_params) ret = NvBufferCreateEx(&dst_dma_fd, &input_params); if(ret<0) { - std::cout << "Failed to allocate buffer" << std::endl; + std::cerr << "Failed to allocate buffer" << std::endl; return false; } #endif @@ -40,7 +40,7 @@ bool NVMPI_frameBuf::destroy() ret = NvBufferDestroy(dst_dma_fd); if(ret<0) { - std::cout << "Failed to Destroy NvBuffer" << std::endl; + std::cerr << "Failed to Destroy NvBuffer" << std::endl; return false; } dst_dma_fd = -1; diff --git a/src/nvmpi_dec.cpp b/src/nvmpi_dec.cpp index a3b0366d..f0bbcc85 100644 --- a/src/nvmpi_dec.cpp +++ b/src/nvmpi_dec.cpp @@ -17,7 +17,7 @@ #define TEST_ERROR(condition, message, errorCode) \ if (condition) \ { \ - std::cout<< message; \ + std::cerr<< message; \ } using namespace std; @@ -650,7 +650,7 @@ int nvmpi_decoder_put_packet(nvmpictx* ctx,nvPacket* packet) ret = ctx->dec->output_plane.qBuffer(v4l2_buf, NULL); if (ret < 0) { - std::cout << "Error Qing buffer at output plane" << std::endl; + std::cerr << "Error Qing buffer at output plane" << std::endl; ctx->index--; return -2; } diff --git a/src/nvmpi_enc.cpp b/src/nvmpi_enc.cpp index 8300dbcb..b726a5b4 100644 --- a/src/nvmpi_enc.cpp +++ b/src/nvmpi_enc.cpp @@ -13,7 +13,7 @@ #define TEST_ERROR(condition, message, errorCode) \ if (condition) \ { \ - std::cout<< message; \ + std::cerr<< message; \ } #define OUTPLANE_MEMTYPE_MMAP 0 From 9582974d20099b76ba4d344481271e4bc9480189 Mon Sep 17 00:00:00 2001 From: "G.J.R. Timmer" Date: Thu, 11 Jun 2026 04:53:27 -0400 Subject: [PATCH 2/2] fix: redirect remaining stdout messages to stderr Additional stdout messages missed by the initial stderr fix: - nvmpi_dec: cout "Error DQing buffer" and printf "NvBufferMap failed" - nvmpi_enc: cout "Error while dequeing", printf EAGAIN warning, and cout "Error DQing buffer" All diagnostic output now goes to stderr to prevent corruption of piped video streams. Co-Authored-By: Claude Opus 4.6 --- src/nvmpi_dec.cpp | 4 ++-- src/nvmpi_enc.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/nvmpi_dec.cpp b/src/nvmpi_dec.cpp index f0bbcc85..b4a2b777 100644 --- a/src/nvmpi_dec.cpp +++ b/src/nvmpi_dec.cpp @@ -634,7 +634,7 @@ int nvmpi_decoder_put_packet(nvmpictx* ctx,nvPacket* packet) ret = ctx->dec->output_plane.dqBuffer(v4l2_buf, &nvBuffer, NULL, -1); if (ret < 0) { - cout << "Error DQing buffer at output plane" << std::endl; + cerr << "Error DQing buffer at output plane" << std::endl; return -1; } } @@ -686,7 +686,7 @@ int copyNvBufToFrame(nvmpictx* ctx, NVMPI_frameBuf *nvmpiBuf, nvFrame* frame) #endif if(ret != 0) { - printf("NvBufferMap failed \n"); + fprintf(stderr, "NvBufferMap failed \n"); return ret; } diff --git a/src/nvmpi_enc.cpp b/src/nvmpi_enc.cpp index b726a5b4..e11a7075 100644 --- a/src/nvmpi_enc.cpp +++ b/src/nvmpi_enc.cpp @@ -67,7 +67,7 @@ static bool encoder_capture_plane_dq_callback(struct v4l2_buffer *v4l2_buf, NvBu if (v4l2_buf == NULL) { - cout << "Error while dequeing buffer from output plane" << endl; + cerr << "Error while dequeing buffer from output plane" << endl; return false; } @@ -88,7 +88,7 @@ static bool encoder_capture_plane_dq_callback(struct v4l2_buffer *v4l2_buf, NvBu { //TODO wait for user to read buffer. make send_frame return AVERROR(EAGAIN) until avcodec_receive_packet() is called //TODO pass warning to avlog - printf("[libnvmpi][W]: EAGAIN. User must read output. nvmpi encoder packet memory pool is empty! Packet will be dropped. There may be artifacts in the output video.\n"); + fprintf(stderr, "[libnvmpi][W]: EAGAIN. User must read output. nvmpi encoder packet memory pool is empty! Packet will be dropped. There may be artifacts in the output video.\n"); } else { @@ -572,7 +572,7 @@ int nvmpi_encoder_put_frame(nvmpictx* ctx,nvFrame* frame) ret = ctx->enc->output_plane.dqBuffer(v4l2_buf, &nvBuffer, NULL, -1); if (ret < 0) { - cout << "Error DQing buffer at output plane" << std::endl; + cerr << "Error DQing buffer at output plane" << std::endl; return false; } }