57 #define OFFSET(x) offsetof(PSNRContext, x)
58 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
68 static inline unsigned pow2(
unsigned base)
73 static inline double get_psnr(
double mse, uint64_t nb_frames,
int max)
75 return 10.0 * log10(
pow2(max) / (mse / nb_frames));
83 for (j = 0; j < outw; j++)
84 m2 +=
pow2(main_line[j] - ref_line[j]);
93 const uint16_t *main_line = (
const uint16_t *) _main_line;
94 const uint16_t *ref_line = (
const uint16_t *) _ref_line;
96 for (j = 0; j < outw; j++)
97 m2 +=
pow2(main_line[j] - ref_line[j]);
104 const uint8_t *main_data[4],
const int main_linesizes[4],
105 const uint8_t *ref_data[4],
const int ref_linesizes[4],
106 int w,
int h,
double mse[4])
113 const uint8_t *main_line = main_data[
c];
114 const uint8_t *ref_line = ref_data[
c];
115 const int ref_linesize = ref_linesizes[
c];
116 const int main_linesize = main_linesizes[
c];
118 for (i = 0; i < outh; i++) {
120 ref_line += ref_linesize;
121 main_line += main_linesize;
123 mse[
c] = m / (double)(outw * outh);
130 snprintf(value,
sizeof(value),
"%0.2f", d);
133 snprintf(key2,
sizeof(key2),
"%s%c", key, comp);
144 double comp_mse[4], mse = 0;
165 set_meta(metadata,
"lavfi.psnr.mse.", s->
comps[j], comp_mse[c]);
168 set_meta(metadata,
"lavfi.psnr.mse_avg", 0, mse);
220 #define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
221 #define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
222 #define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
295 outlink->
w = mainlink->
w;
296 outlink->
h = mainlink->
h;
376 .priv_class = &psnr_class,
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
Main libavfilter public API header.
int h
agreed upon image height
static AVFrame * do_psnr(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
#define AV_PIX_FMT_GBRP10
static uint64_t sse_line_8bit(const uint8_t *main_line, const uint8_t *ref_line, int outw)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static int request_frame(AVFilterLink *outlink)
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
static double get_psnr(double mse, uint64_t nb_frames, int max)
static void compute_images_mse(PSNRContext *s, const uint8_t *main_data[4], const int main_linesizes[4], const uint8_t *ref_data[4], const int ref_linesizes[4], int w, int h, double mse[4])
static double psnr(double d)
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
A filter pad used for either input or output.
A link between two filters.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0, will be automatically copied from the first input of the source filter if it exists.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int config_input_ref(AVFilterLink *inlink)
void * priv
private data for use by the filter
FFDualInputContext dinput
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
static av_cold void uninit(AVFilterContext *ctx)
#define AV_PIX_FMT_GBRAP16
int w
agreed upon image width
uint8_t nb_components
The number of components each pixel has, (1-4)
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GRAY16
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static void set_meta(AVDictionary **metadata, const char *key, char comp, float d)
GLsizei GLboolean const GLfloat * value
static int config_output(AVFilterLink *outlink)
static av_cold int init(AVFilterContext *ctx)
AVFilterContext * src
source filter
AVFrame *(* process)(AVFilterContext *ctx, AVFrame *main, const AVFrame *second)
static const AVFilterPad outputs[]
static unsigned pow2(unsigned base)
uint64_t(* sse_line)(const uint8_t *buf, const uint8_t *ref, int w)
#define AV_PIX_FMT_GBRP14
int format
agreed upon media format
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
#define AV_LOG_INFO
Standard information.
static const AVFilterPad inputs[]
AVDictionary ** avpriv_frame_get_metadatap(AVFrame *frame)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
const char * name
Filter name.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_GBRP12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
static const AVFilterPad psnr_inputs[]
static int ref[MAX_W *MAX_W]
planar GBRA 4:4:4:4 32bpp
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
static const AVFilterPad psnr_outputs[]
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static const AVOption psnr_options[]
static int query_formats(AVFilterContext *ctx)
AVFilterContext * dst
dest filter
AVFILTER_DEFINE_CLASS(psnr)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
static uint64_t sse_line_16bit(const uint8_t *_main_line, const uint8_t *_ref_line, int outw)
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
void ff_psnr_init_x86(PSNRDSPContext *dsp, int bpp)
int main(int argc, char **argv)
int depth
Number of bits in the component.
AVPixelFormat
Pixel format.
#define AV_CEIL_RSHIFT(a, b)