MayaFlux 0.5.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 352 of file VideoStreamContext.cpp.

355{
356 if (!frame || frame->width <= 0 || frame->height <= 0
357 || frame->format == AV_PIX_FMT_NONE) {
358 m_last_error = "rebuild_scaler_from_frame: invalid frame";
359 return false;
360 }
361
362 if (codec_context && codec_context->pix_fmt == AV_PIX_FMT_NONE)
363 codec_context->pix_fmt = static_cast<AVPixelFormat>(frame->format);
364
365 if (width == 0 || height == 0) {
366 width = static_cast<uint32_t>(frame->width);
367 height = static_cast<uint32_t>(frame->height);
368 }
369 src_pixel_format = codec_context ? codec_context->pix_fmt : frame->format;
370
371 if (sws_context) {
372 sws_freeContext(sws_context);
373 sws_context = nullptr;
374 }
375
376 const uint32_t use_w = tw > 0 ? tw : (target_width > 0 ? target_width : width);
377 const uint32_t use_h = th > 0 ? th : (target_height > 0 ? target_height : height);
378 const int use_f = tf >= 0 ? tf : (target_format >= 0 ? target_format : -1);
379
380 return setup_scaler(use_w, use_h, use_f);
381}
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: