60 #define OFFSET(x) offsetof(PSNRContext, x)
61 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
66 {
"stats_version",
"Set the format version for the stats file.",
OFFSET(stats_version),
AV_OPT_TYPE_INT, {.i64=1}, 1, 2,
FLAGS },
73 static inline unsigned pow_2(
unsigned base)
78 static inline double get_psnr(
double mse, uint64_t nb_frames,
int max)
80 return 10.0 * log10(
pow_2(max) / (mse / nb_frames));
88 for (j = 0; j < outw; j++)
89 m2 +=
pow_2(main_line[j] - ref_line[j]);
98 const uint16_t *main_line = (
const uint16_t *) _main_line;
99 const uint16_t *ref_line = (
const uint16_t *) _ref_line;
101 for (j = 0; j < outw; j++)
102 m2 +=
pow_2(main_line[j] - ref_line[j]);
109 const uint8_t *main_data[4],
const int main_linesizes[4],
110 const uint8_t *ref_data[4],
const int ref_linesizes[4],
111 int w,
int h,
double mse[4])
118 const uint8_t *main_line = main_data[
c];
119 const uint8_t *ref_line = ref_data[
c];
120 const int ref_linesize = ref_linesizes[
c];
121 const int main_linesize = main_linesizes[
c];
123 for (i = 0; i < outh; i++) {
125 ref_line += ref_linesize;
126 main_line += main_linesize;
128 mse[
c] = m / (double)(outw * outh);
135 snprintf(value,
sizeof(value),
"%0.2f", d);
138 snprintf(key2,
sizeof(key2),
"%s%c", key, comp);
149 double comp_mse[4], mse = 0;
170 set_meta(metadata,
"lavfi.psnr.mse.", s->
comps[j], comp_mse[c]);
173 set_meta(metadata,
"lavfi.psnr.mse_avg", 0, mse);
178 fprintf(s->
stats_file,
"psnr_log_version:2 fields:n");
230 "stats_add_max was specified but stats_version < 2.\n" );
256 #define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
257 #define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
258 #define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
334 outlink->
w = mainlink->
w;
335 outlink->
h = mainlink->
h;
415 .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)
#define AV_PIX_FMT_GRAY10
const char * name
Pad name.
#define AV_PIX_FMT_GRAY12
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
static unsigned pow_2(unsigned base)
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[]
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)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
#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)
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)