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);
150 double comp_mse[4], mse = 0;
178 set_meta(metadata,
"lavfi.psnr.mse.", s->
comps[j], comp_mse[c]);
181 set_meta(metadata,
"lavfi.psnr.mse_avg", 0, mse);
186 fprintf(s->
stats_file,
"psnr_log_version:2 fields:n");
238 "stats_add_max was specified but stats_version < 2.\n" );
264 #define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
265 #define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
266 #define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
345 outlink->
w = mainlink->
w;
346 outlink->
h = mainlink->
h;
413 .preinit = psnr_framesync_preinit,
419 .priv_class = &psnr_class,
static int activate(AVFilterContext *ctx)
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
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
#define AV_PIX_FMT_GBRP10
static uint64_t sse_line_8bit(const uint8_t *main_line, const uint8_t *ref_line, int outw)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
#define AV_PIX_FMT_GRAY10
const char * name
Pad name.
AVFilterContext * parent
Parent filter context.
#define AV_PIX_FMT_GRAY12
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
FRAMESYNC_DEFINE_CLASS(psnr, PSNRContext, fs)
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])
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
static double psnr(double d)
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...
AVDictionary * metadata
metadata.
A filter pad used for either input or output.
A link between two filters.
#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.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
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
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
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
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[]
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
AVFilterLink ** outputs
array of pointers to output links
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
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 depth
Number of bits in the component.
static int do_psnr(FFFrameSync *fs)
AVPixelFormat
Pixel format.
#define AV_CEIL_RSHIFT(a, b)