Check frame format before sws_getCachedContext.

This commit is contained in:
John Preston 2019-02-27 16:13:43 +04:00
parent e631d98230
commit a8aa66d191
1 changed files with 5 additions and 2 deletions

View File

@ -137,6 +137,10 @@ SwsContextPointer MakeSwsContextPointer(
return std::move(*existing);
}
}
if (frame->format <= AV_PIX_FMT_NONE || frame->format >= AV_PIX_FMT_NB) {
LogError(qstr("frame->format"));
return SwsContextPointer();
}
const auto result = sws_getCachedContext(
existing ? existing->release() : nullptr,
@ -319,8 +323,7 @@ QImage ConvertFrame(
storage = CreateFrameStorage(resize);
}
const auto format = AV_PIX_FMT_BGRA;
const auto hasDesiredFormat = (frame->format == format)
|| ((frame->format == -1) && (stream.codec->pix_fmt == format));
const auto hasDesiredFormat = (frame->format == format);
if (frameSize == storage.size() && hasDesiredFormat) {
static_assert(sizeof(uint32) == kPixelBytesSize);
auto to = reinterpret_cast<uint32*>(storage.bits());