diff --git a/src/video/video.c b/src/video/video.c index 124af57b..4e42d510 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -103,8 +103,7 @@ static void video_av_log_cb(void* avcl, int level, const char* fmt, va_list vl) && (strstr(buf, "::SubmitInput() : format") || strstr(buf, "SubmitToEncoder() End: frame pts=") || strstr(buf, "::QueryOutput()") || strstr(buf, "QueryOutput() End: frame pts="))) return; DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "ffmpeg AMF encoder=%s: %s", encoder, buf); - } - else if (level <= AV_LOG_ERROR) DEBUG_ERROR(DEBUG_CATEGORY_VIDEO, "ffmpeg: %s", buf); + } else if (level <= AV_LOG_ERROR) DEBUG_ERROR(DEBUG_CATEGORY_VIDEO, "ffmpeg: %s", buf); else DEBUG_WARN(DEBUG_CATEGORY_VIDEO, "ffmpeg: %s", buf); } diff --git a/tools/chatgui/src/live_video_encoder.cpp b/tools/chatgui/src/live_video_encoder.cpp index a4d7fd08..7407537b 100644 --- a/tools/chatgui/src/live_video_encoder.cpp +++ b/tools/chatgui/src/live_video_encoder.cpp @@ -390,6 +390,22 @@ bool LiveVideoEncoder::encode(const QImage& image, uint64_t pts, bool key, QList int stride[4] = {static_cast(canvas.bytesPerLine()), 0, 0, 0}; result = sws_scale(m->scale, input, stride, 0, canvas.height(), m->frame->data, m->frame->linesize); } + if (result >= 0 && m->reportTimer.elapsed() >= 1000 && debug_should_output(DEBUG_LEVEL_TRACE, DEBUG_CATEGORY_DEBUG) + && (m->frame->format == AV_PIX_FMT_NV12 || m->frame->format == AV_PIX_FMT_YUV420P)) { + uint64_t edges = 0, samples = 0; + int minimum = 255, maximum = 0; + for (int y = 0; y + 1 < m->frame->height; y += 16) { + const uint8_t* row = m->frame->data[0] + y * m->frame->linesize[0]; + for (int x = 0; x + 1 < m->frame->width; x += 16) { + int value = row[x]; minimum = std::min(minimum, value); maximum = std::max(maximum, value); + edges += std::abs(value - row[x + 1]) + std::abs(value - row[x + m->frame->linesize[0]]); samples += 2; + } + } + DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, + "video encoder input name=%s pts=%llu source=%dx%d encoded=%dx%d pixel=%d luma_min=%d luma_max=%d edge_x1000=%llu", + qPrintable(m->name), (unsigned long long)pts, image.width(), image.height(), m->frame->width, m->frame->height, + m->frame->format, minimum, maximum, (unsigned long long)(samples ? edges * 1000 / samples : 0)); + } bool constrained = m->config.profile != LiveVideoProfile::Automatic; if (constrained && m->timestamps.size() >= 8) { m->error = "GPU encoder exceeded the bounded input pipeline"; diff --git a/tools/chatgui/tests/test_stream_publish.cpp b/tools/chatgui/tests/test_stream_publish.cpp index 29391273..b7f0aa2a 100644 --- a/tools/chatgui/tests/test_stream_publish.cpp +++ b/tools/chatgui/tests/test_stream_publish.cpp @@ -210,6 +210,9 @@ private slots: av_log(context, AV_LOG_DEBUG, "UTUN_AMF_LOG_TEST driver value=%d\n", 17); QCOMPARE(ffmpegDiagnosticMessages.size(), 1); QVERIFY(ffmpegDiagnosticMessages.front().contains("encoder=hevc_amf: UTUN_AMF_LOG_TEST driver value=17")); + av_log(context, AV_LOG_DEBUG, "UTUN_AMF_LOG_TEST Debug: AMFEncoderUVEHEVCImpl::QueryOutput()\n"); + av_log(context, AV_LOG_DEBUG, "UTUN_AMF_LOG_TEST Trace: SubmitToEncoder() End: frame pts=17\n"); + QCOMPARE(ffmpegDiagnosticMessages.size(), 1); codec.name = "libx264"; av_log(context, AV_LOG_DEBUG, "UTUN_AMF_LOG_TEST unrelated encoder\n"); av_log(nullptr, AV_LOG_DEBUG, "UTUN_AMF_LOG_TEST unrelated context\n"); @@ -220,6 +223,10 @@ private slots: av_log(nullptr, AV_LOG_ERROR, "UTUN_AMF_LOG_TEST normal error\n"); QCOMPARE(ffmpegDiagnosticMessages.size(), 2); QVERIFY(ffmpegDiagnosticMessages.back().contains("normal error")); + debug_set_category_level(DEBUG_CATEGORY_DEBUG, DEBUG_LEVEL_TRACE); + av_log(context, AV_LOG_DEBUG, "UTUN_AMF_LOG_TEST Warning: AMFEncoderUVEHEVCImpl::QueryOutput() failed\n"); + QCOMPARE(ffmpegDiagnosticMessages.size(), 3); + QVERIFY(ffmpegDiagnosticMessages.back().contains("Warning:")); #else QSKIP("FFmpeg unavailable"); #endif