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

◆ rebuild_scaler_from_frame()

bool MayaFlux::IO::VideoStreamContext::rebuild_scaler_from_frame ( const AVFrame *  frame,
uint32_t  target_width = 0,
uint32_t  target_height = 0,
int  target_format = -1 
)

Rebuild the SwsContext using the pixel format resolved from a live decoded frame.

dshow and similar capture devices on Windows leave pix_fmt as AV_PIX_FMT_NONE until the first decoded frame arrives. Call this once from the camera's frame-receive loop on the very first valid AVFrame to finalise the scaler before calling sws_scale.

Parameters
frameThe first successfully decoded AVFrame.
target_widthDesired output width (0 = keep frame width).
target_heightDesired output height (0 = keep frame height).
target_formatDesired AVPixelFormat (negative = AV_PIX_FMT_RGBA).
Returns
True if the scaler was (re)initialised successfully.

Definition at line 347 of file VideoStreamContext.cpp.

350{
351 if (!frame || frame->width <= 0 || frame->height <= 0
352 || frame->format == AV_PIX_FMT_NONE) {
353 m_last_error = "rebuild_scaler_from_frame: invalid frame";
354 return false;
355 }
356
357 if (codec_context && codec_context->pix_fmt == AV_PIX_FMT_NONE)
358 codec_context->pix_fmt = static_cast<AVPixelFormat>(frame->format);
359
360 if (width == 0 || height == 0) {
361 width = static_cast<uint32_t>(frame->width);
362 height = static_cast<uint32_t>(frame->height);
363 }
364 src_pixel_format = codec_context ? codec_context->pix_fmt : frame->format;
365
366 if (sws_context) {
367 sws_freeContext(sws_context);
368 sws_context = nullptr;
369 }
370
371 const uint32_t use_w = tw > 0 ? tw : (target_width > 0 ? target_width : width);
372 const uint32_t use_h = th > 0 ? th : (target_height > 0 ? target_height : height);
373 const int use_f = tf >= 0 ? tf : (target_format >= 0 ? target_format : -1);
374
375 return setup_scaler(use_w, use_h, use_f);
376}
uint32_t target_width
Requested output width (0 = source).
uint32_t target_height
Requested output height (0 = source).
bool setup_scaler(uint32_t target_width, uint32_t target_height, int target_format)
Allocate and initialise the SwsContext for pixel format conversion.
uint32_t height
Source height in pixels.
uint32_t width
Source width in pixels.
int src_pixel_format
Source AVPixelFormat.
SwsContext * sws_context
Owned; freed in destructor.
AVCodecContext * codec_context
Owned; freed in destructor.
int target_format
Requested AVPixelFormat (negative = RGBA).

References codec_context, height, m_last_error, setup_scaler(), src_pixel_format, sws_context, target_format, target_height, target_width, and width.

+ Here is the call graph for this function: