Preserve video color range and handle capture worker failures
This commit is contained in:
1 parent
ce46677dfb
commit
50fad4ceff
3 files changed
+19
-9
No files matched your search
@@ -2,6 +2,7 @@
|
||||
#include "debug_config.h"
|
||||
#include <QPainter>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
extern "C" {
|
||||
#include "../../../src/stream/stream_media.h"
|
||||
#ifdef HAVE_FFMPEG
|
||||
@@ -172,11 +173,13 @@ bool StreamVideoEncoder::encode(const QImage& image, uint64_t pts, bool key, QLi
|
||||
{ QPainter painter(&canvas); painter.drawImage(QRect(QPoint((canvas.width() - fitted.width()) / 2,
|
||||
(canvas.height() - fitted.height()) / 2), fitted), image); }
|
||||
int result = av_frame_make_writable(m->frame);
|
||||
m->scale = sws_getCachedContext(m->scale, canvas.width(), canvas.height(), AV_PIX_FMT_BGRA,
|
||||
m->scale = sws_getCachedContext(m->scale, canvas.width(), canvas.height(), AV_PIX_FMT_RGB32,
|
||||
m->frame->width, m->frame->height, static_cast<AVPixelFormat>(m->frame->format), SWS_FAST_BILINEAR, nullptr, nullptr, nullptr);
|
||||
if (!m->scale) result = AVERROR(ENOMEM);
|
||||
if (result >= 0) {
|
||||
const uint8_t* input[] = {canvas.constBits()}; int stride[] = {canvas.bytesPerLine()};
|
||||
const int* coefficients = sws_getCoefficients(SWS_CS_ITU709);
|
||||
sws_setColorspaceDetails(m->scale, coefficients, 1, coefficients, 0, 0, 1 << 16, 1 << 16);
|
||||
const uint8_t* input[] = {canvas.constBits()}; int stride[] = {static_cast<int>(canvas.bytesPerLine())};
|
||||
result = sws_scale(m->scale, input, stride, 0, canvas.height(), m->frame->data, m->frame->linesize);
|
||||
}
|
||||
m->frame->pts = static_cast<int64_t>(pts); m->frame->pict_type = key ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_NONE;
|
||||
|
||||
Reference in new issue
Block a user