avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
videorescaler.h
Go to the documentation of this file.
1#pragma once
2
9
10#include <iostream>
11#include <memory>
12
13#include "ffmpeg.h"
14#include "frame.h"
15#include "avutils.h"
16#include "pixelformat.h"
17#include "averror.h"
18
19namespace av
20{
21
28{
32 SwsFlagFastBilinear = SWS_FAST_BILINEAR,
34 SwsFlagBilinear = SWS_BILINEAR,
36 SwsFlagBicubic = SWS_BICUBIC,
40 SwsFlagNeighbor = SWS_POINT,
42 SwsFlagArea = SWS_AREA,
44 SwsFlagBicublin = SWS_BICUBLIN,
46 SwsFlagGauss = SWS_GAUSS,
48 SwsFlagSinc = SWS_SINC,
50 SwsFlagLanczos = SWS_LANCZOS,
52 SwsFlagSpline = SWS_SPLINE,
54 SwsFlagPrintInfo = SWS_PRINT_INFO,
56 SwsFlagAccurateRnd = SWS_ACCURATE_RND,
58 SwsFlagFullChromaInt = SWS_FULL_CHR_H_INT,
60 SwsFlagFullChromaInp = SWS_FULL_CHR_H_INP,
62 SwsFlagBitexact = SWS_BITEXACT,
64 SwsFlagErrorDiffusion = SWS_ERROR_DIFFUSION,
65};
66
75class VideoRescaler : public FFWrapperPtr<SwsContext>, public noncopyable
76{
77public:
85
99 int32_t flags = SwsFlagAuto);
100
109 VideoRescaler(int m_dstWidth, int m_dstHeight, PixelFormat m_dstPixelFormat, int32_t flags = SwsFlagAuto);
110
123
125
142
148 int dstWidth() const { return m_dstWidth; }
154 int dstHeight() const { return m_dstHeight; }
160 PixelFormat dstPixelFormat() { return m_dstPixelFormat; }
161
167 int srcWidth() const { return m_srcWidth; }
173 int srcHeight() const { return m_srcHeight; }
179 PixelFormat srcPixelFormat() { return m_srcPixelFormat; }
180
186 int32_t flags() const { return m_flags; }
187
196 void rescale(VideoFrame &dst, const VideoFrame &src, OptionalErrorCode ec = throws());
205 VideoFrame rescale(const VideoFrame &src, OptionalErrorCode ec = throws());
206
212 bool isValid() const;
213
214private:
215 void swap(VideoRescaler &other) noexcept;
216
217 void getContext(int32_t flags = 0);
218
219 static
220 bool validate(int width, int height, PixelFormat pixelFormat);
221
222private:
223 int m_dstWidth = -1;
224 int m_dstHeight = -1;
225 PixelFormat m_dstPixelFormat = AV_PIX_FMT_NONE;
226
227 int m_srcWidth = -1;
228 int m_srcHeight = -1;
229 PixelFormat m_srcPixelFormat = AV_PIX_FMT_NONE;
230
231 int32_t m_flags = SwsFlagAuto;
232};
233
234} // ::av
235
Error codes, error categories and the OptionalErrorCode convention.
Common helpers: comparisons, value lookup, non-copyable base, string utilities.
Carries the caller's choice between exceptions and error codes.
Definition averror.h:96
The PixelFormat class is a simple wrapper for AVPixelFormat that allow to acces it it properties.
Definition pixelformat.h:41
One video frame.
Definition frame.h:578
VideoRescaler()
Create an uninitialised scaler.
VideoRescaler(VideoRescaler &&other)
Move the scaler.
PixelFormat dstPixelFormat()
Output pixel format.
Definition videorescaler.h:160
VideoFrame rescale(const VideoFrame &src, OptionalErrorCode ec=throws())
Scale into a newly allocated frame.
void rescale(VideoFrame &dst, const VideoFrame &src, OptionalErrorCode ec=throws())
Scale into an existing frame.
VideoRescaler & operator=(VideoRescaler &&rhs)
Move assignment.
int dstHeight() const
Output height.
Definition videorescaler.h:154
VideoRescaler & operator=(const VideoRescaler &rhs)
Copy assignment: replaces the configuration and the libswscale context.
VideoRescaler(const VideoRescaler &other)
Copy the scaler configuration.
int srcWidth() const
Input width.
Definition videorescaler.h:167
PixelFormat srcPixelFormat()
Input pixel format.
Definition videorescaler.h:179
VideoRescaler(int m_dstWidth, int m_dstHeight, PixelFormat m_dstPixelFormat, int32_t flags=SwsFlagAuto)
Create a scaler that keeps the input geometry and only converts formats.
int srcHeight() const
Input height.
Definition videorescaler.h:173
VideoRescaler(int dstWidth, int dstHeight, PixelFormat dstPixelFormat, int srcWidth, int srcHeight, PixelFormat srcPixelFormat, int32_t flags=SwsFlagAuto)
Create a scaler with explicit source and destination.
int32_t flags() const
Scaling options in use.
Definition videorescaler.h:186
int dstWidth() const
Output width.
Definition videorescaler.h:148
bool isValid() const
Whether the scaler has a libswscale context.
FFmpeg types re-exported for the public API and small value wrappers.
Video frames, audio samples and their common frame interface.
Root namespace of the library.
Definition audioresampler.h:19
SwsFlags
Scaling algorithms and options of libswscale.
Definition videorescaler.h:28
@ SwsFlagSinc
Sinc filter.
Definition videorescaler.h:48
@ SwsFlagAccurateRnd
Rounding mode that costs speed and gains accuracy.
Definition videorescaler.h:56
@ SwsFlagBitexact
Bit-exact output where the algorithm allows it.
Definition videorescaler.h:62
@ SwsFlagBicublin
Bicubic for luma, bilinear for chroma.
Definition videorescaler.h:44
@ SwsFlagErrorDiffusion
Error diffusion for palette conversion.
Definition videorescaler.h:64
@ SwsFlagLanczos
Lanczos filter, a good default for high quality.
Definition videorescaler.h:50
@ SwsFlagPrintInfo
Print the chosen filter configuration.
Definition videorescaler.h:54
@ SwsFlagFullChromaInp
Treat the input chroma as full resolution.
Definition videorescaler.h:60
@ SwsFlagAuto
Let libswscale pick the algorithm.
Definition videorescaler.h:30
@ SwsFlagArea
Averaging over the source area; good for downscaling.
Definition videorescaler.h:42
@ SwsFlagSpline
Spline filter.
Definition videorescaler.h:52
@ SwsFlagBicubic
Bicubic filtering.
Definition videorescaler.h:36
@ SwsFlagNeighbor
Nearest neighbour, the fastest and crudest option.
Definition videorescaler.h:40
@ SwsFlagFastBilinear
Bilinear filtering with reduced chroma interpolation.
Definition videorescaler.h:32
@ SwsFlagBilinear
Bilinear filtering.
Definition videorescaler.h:34
@ SwsFlagGauss
Gaussian filter.
Definition videorescaler.h:46
@ SwsFlagFullChromaInt
Full chroma interpolation by the scaler.
Definition videorescaler.h:58
@ SwsFlagExprerimental
Experimental filter, kept for compatibility.
Definition videorescaler.h:38
Pixel formats.