Trace HEVC key frame quantization and reduce AMF log noise
This commit is contained in:
1 parent
78b147f806
commit
f7853f145c
2 files changed
+61
-10
No files matched your search
@@ -32,11 +32,13 @@ struct LiveVideoEncoder::Impl {
|
||||
#ifdef HAVE_FFMPEG
|
||||
AVCodecContext* codec = nullptr;
|
||||
AVBSFContext* filter = nullptr;
|
||||
AVBSFContext* headers = nullptr; // Только чтение заголовков KEY при debug=trace, исходный пакет не меняется.
|
||||
bool headersAttempted = false;
|
||||
AVFrame* frame = nullptr;
|
||||
AVBufferRef* device = nullptr;
|
||||
SwsContext* scale = nullptr;
|
||||
~Impl() {
|
||||
av_bsf_free(&filter); avcodec_free_context(&codec); av_frame_free(&frame);
|
||||
av_bsf_free(&headers); av_bsf_free(&filter); avcodec_free_context(&codec); av_frame_free(&frame);
|
||||
av_buffer_unref(&device); sws_freeContext(scale);
|
||||
}
|
||||
#endif
|
||||
@@ -423,6 +425,35 @@ bool LiveVideoEncoder::encode(const QImage& image, uint64_t pts, bool key, QList
|
||||
if (result >= 0) result = av_bsf_receive_packet(m->filter, packet);
|
||||
if (result < 0) break;
|
||||
}
|
||||
if (m->config.codec == STREAM_MEDIA_H265 && (packet->flags & AV_PKT_FLAG_KEY)
|
||||
&& debug_should_output(DEBUG_LEVEL_TRACE, DEBUG_CATEGORY_DEBUG)) {
|
||||
int diagnostic = 0;
|
||||
if (!m->headersAttempted) {
|
||||
m->headersAttempted = true;
|
||||
const auto* trace = av_bsf_get_by_name("trace_headers");
|
||||
diagnostic = trace ? av_bsf_alloc(trace, &m->headers) : AVERROR(ENOSYS);
|
||||
if (diagnostic >= 0) diagnostic = m->filter ? avcodec_parameters_copy(m->headers->par_in, m->filter->par_out)
|
||||
: avcodec_parameters_from_context(m->headers->par_in, m->codec);
|
||||
if (diagnostic >= 0) {
|
||||
m->headers->time_base_in = m->codec->time_base;
|
||||
diagnostic = av_bsf_init(m->headers);
|
||||
}
|
||||
if (diagnostic >= 0) DEBUG_INFO(DEBUG_CATEGORY_DEBUG,
|
||||
"HEVC KEY header diagnostics enabled name=%s; slice_QP=26+init_qp_minus26+slice_qp_delta",
|
||||
qPrintable(m->name));
|
||||
}
|
||||
if (m->headers && diagnostic >= 0) {
|
||||
AVPacket* copy = av_packet_clone(packet);
|
||||
diagnostic = copy ? av_bsf_send_packet(m->headers, copy) : AVERROR(ENOMEM);
|
||||
if (diagnostic >= 0) diagnostic = av_bsf_receive_packet(m->headers, copy);
|
||||
av_packet_free(©);
|
||||
}
|
||||
if (diagnostic < 0) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_VIDEO, "HEVC header diagnostics disabled name=%s pts=%lld error=%s",
|
||||
qPrintable(m->name), (long long)packet->pts, qPrintable(ffError(diagnostic)));
|
||||
av_bsf_free(&m->headers);
|
||||
}
|
||||
}
|
||||
LiveEncodedFrame encoded; encoded.key = (packet->flags & AV_PKT_FLAG_KEY) != 0;
|
||||
encoded.pts = packet->pts >= 0 ? static_cast<uint64_t>(packet->pts) : pts;
|
||||
if (constrained) {
|
||||
|
||||
Reference in new issue
Block a user