MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ setup_scaler()

bool MayaFlux::IO::VideoStreamContext::setup_scaler ( uint32_t  target_width,
uint32_t  target_height,
int  target_format 
)
private

Allocate and initialise the SwsContext for pixel format conversion.

Parameters
target_widthDesired output width (0 = source width).
target_heightDesired output height (0 = source height).
target_formatDesired AVPixelFormat (negative = AV_PIX_FMT_RGBA).
Returns
True on success.

Definition at line 294 of file VideoStreamContext.cpp.

297{
298 if (!codec_context)
299 return false;
300
301 if (codec_context->pix_fmt == AV_PIX_FMT_NONE) {
302 m_last_error = "setup_scaler: source pix_fmt is AV_PIX_FMT_NONE — "
303 "codec has not resolved its output format yet";
304 return false;
305 }
306
311 : static_cast<int>(AV_PIX_FMT_RGBA);
312
313 sws_context = sws_getContext(
314 static_cast<int>(width),
315 static_cast<int>(height),
316 codec_context->pix_fmt,
317 static_cast<int>(out_width),
318 static_cast<int>(out_height),
319 static_cast<AVPixelFormat>(out_pixel_format),
320 SWS_BILINEAR,
321 nullptr, nullptr, nullptr);
322
323 if (!sws_context) {
324 m_last_error = "sws_getContext failed";
325 return false;
326 }
327
328 const AVPixFmtDescriptor* desc = av_pix_fmt_desc_get(
329 static_cast<AVPixelFormat>(out_pixel_format));
330 if (!desc) {
331 m_last_error = "setup_scaler: no descriptor for target pixel format";
332 return false;
333 }
334
335 if (av_pix_fmt_count_planes(static_cast<AVPixelFormat>(out_pixel_format)) != 1) {
336 m_last_error = std::string("setup_scaler: target format ")
337 + (desc->name ? desc->name : "?")
338 + " is multi-planar; the read path writes a single packed plane";
339 return false;
340 }
341
342 out_bytes_per_pixel = static_cast<uint32_t>((av_get_bits_per_pixel(desc) + 7) / 8);
343
344 out_linesize = static_cast<int>(out_width * out_bytes_per_pixel);
345 int align_remainder = out_linesize % 32;
346 if (align_remainder != 0)
347 out_linesize += 32 - align_remainder;
348
349 return true;
350}
uint32_t target_width
Requested output width (0 = source).
uint32_t target_height
Requested output height (0 = source).
uint32_t out_height
Output height after scaling.
uint32_t height
Source height in pixels.
uint32_t width
Source width in pixels.
int out_pixel_format
Output AVPixelFormat.
int out_linesize
Output row stride in bytes.
SwsContext * sws_context
Owned; freed in destructor.
AVCodecContext * codec_context
Owned; freed in destructor.
int target_format
Requested AVPixelFormat (negative = RGBA).
uint32_t out_bytes_per_pixel
Bytes per pixel in output format.
uint32_t out_width
Output width after scaling.

References codec_context, height, m_last_error, out_bytes_per_pixel, out_height, out_linesize, out_pixel_format, out_width, sws_context, target_format, target_height, target_width, and width.

Referenced by open(), and rebuild_scaler_from_frame().

+ Here is the caller graph for this function: