FFmpeg
Loading...
Searching...
No Matches
qpfile_parser.h File Reference

Shared parser for the per-frame QP-offset file format. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  FFQpFrame
 
struct  FFQpFile
 

Macros

#define QPFILE_DELTA_MIN   (-12)
 
#define QPFILE_DELTA_MAX   (12)
 
#define QPFILE_LUT_SIZE   (QPFILE_DELTA_MAX - QPFILE_DELTA_MIN + 1)
 

Functions

int ff_qpfile_load (void *log_ctx, const char *path, FFQpFile *out)
 Load a per-frame QP-offset file into out, logging errors to log_ctx.
 
int ff_qpfile_check_grid (void *log_ctx, const char *encoder, const FFQpFile *qf, int width, int height)
 Verify that the QP file grid matches the video macroblock dimensions.
 
void ff_qpfile_free (FFQpFile *qpf)
 Free all memory allocated inside an FFQpFile structure.
 
const FFQpFrame * ff_qpfile_frame_for_index (const FFQpFile *qf, unsigned frame_index)
 Look up the QP frame record matching or preceding the given frame index.
 
unsigned ff_qpfile_segment_values (const FFQpFrame *qf, int *seg_values, unsigned max_segments)
 Fill seg_values with the palette (see ff_qpfile_palette) of the frame's block offsets, returning its size, or 0 without offsets.
 
unsigned ff_qpfile_nearest_segment (int v, const int *seg_values, unsigned n_seg)
 Return the index of the segment value nearest v, the first one on a tie.
 
unsigned ff_qpfile_palette (const int8_t *vals, size_t n, int *seg_values, unsigned max_segments)
 Fill seg_values, ascending, with each distinct value of the n offsets in vals when there are at most max_segments (at least 2) of them, else with max_segments evenly spaced values over their range; return the count, 0 when n is 0.
 
void ff_qpfile_segment_lut (uint8_t *lut, const int *seg_values, unsigned n_seg)
 Fill lut[QPFILE_LUT_SIZE] with the nearest segment index of each offset from QPFILE_DELTA_MIN to QPFILE_DELTA_MAX.
 

Detailed Description

Shared parser for the per-frame QP-offset file format.

Consumed by libx264, libsvtav1, and libaom-av1 encoder adapters via the new -qpfile AVOption.

Keep the parser shared across encoder adapters so future encoder additions inherit the same format handling and validation rules.

The parsed block offsets are QP deltas for libx264, deltas on libaom's 0..63 quantizer scale for libaom-av1 (libaom converts each to a quantizer index delta, 12 becoming 48) and AV1 quantizer index deltas for libsvtav1.

Definition in file qpfile_parser.h.

Macro Definition Documentation

◆ QPFILE_DELTA_MIN

#define QPFILE_DELTA_MIN   (-12)

◆ QPFILE_DELTA_MAX

#define QPFILE_DELTA_MAX   (12)

◆ QPFILE_LUT_SIZE

#define QPFILE_LUT_SIZE   (QPFILE_DELTA_MAX - QPFILE_DELTA_MIN + 1)

Definition at line 41 of file qpfile_parser.h.

Referenced by ff_qpfile_palette(), and test_lut().

Function Documentation

◆ ff_qpfile_load()

int ff_qpfile_load ( void * log_ctx,
const char * path,
FFQpFile * out )

Load a per-frame QP-offset file into out, logging errors to log_ctx.

Definition at line 398 of file qpfile_parser.c.

Referenced by load_qpfile(), run_fixture_test(), and X264_init().

◆ ff_qpfile_check_grid()

int ff_qpfile_check_grid ( void * log_ctx,
const char * encoder,
const FFQpFile * qf,
int width,
int height )

Verify that the QP file grid matches the video macroblock dimensions.

Definition at line 437 of file qpfile_parser.c.

Referenced by check_header_only(), check_valid(), load_qpfile(), and X264_init().

◆ ff_qpfile_free()

void ff_qpfile_free ( FFQpFile * qpf)

Free all memory allocated inside an FFQpFile structure.

Definition at line 457 of file qpfile_parser.c.

Referenced by aom_free(), eb_enc_close(), ff_qpfile_load(), run_fixture_test(), and X264_close().

◆ ff_qpfile_frame_for_index()

const FFQpFrame * ff_qpfile_frame_for_index ( const FFQpFile * qf,
unsigned frame_index )

Look up the QP frame record matching or preceding the given frame index.

Definition at line 471 of file qpfile_parser.c.

Referenced by check_clearing(), check_valid(), and setup_qpfile().

◆ ff_qpfile_segment_values()

unsigned ff_qpfile_segment_values ( const FFQpFrame * qf,
int * seg_values,
unsigned max_segments )

Fill seg_values with the palette (see ff_qpfile_palette) of the frame's block offsets, returning its size, or 0 without offsets.

Definition at line 531 of file qpfile_parser.c.

Referenced by check_valid().

◆ ff_qpfile_nearest_segment()

unsigned ff_qpfile_nearest_segment ( int v,
const int * seg_values,
unsigned n_seg )

Return the index of the segment value nearest v, the first one on a tie.

Definition at line 542 of file qpfile_parser.c.

Referenced by ff_qpfile_segment_lut().

◆ ff_qpfile_palette()

unsigned ff_qpfile_palette ( const int8_t * vals,
size_t n,
int * seg_values,
unsigned max_segments )

Fill seg_values, ascending, with each distinct value of the n offsets in vals when there are at most max_segments (at least 2) of them, else with max_segments evenly spaced values over their range; return the count, 0 when n is 0.

Every value must lie in QPFILE_DELTA_MIN..QPFILE_DELTA_MAX.

Definition at line 506 of file qpfile_parser.c.

Referenced by ff_qpfile_segment_values(), and test_palette().

◆ ff_qpfile_segment_lut()

void ff_qpfile_segment_lut ( uint8_t * lut,
const int * seg_values,
unsigned n_seg )

Fill lut[QPFILE_LUT_SIZE] with the nearest segment index of each offset from QPFILE_DELTA_MIN to QPFILE_DELTA_MAX.

Definition at line 559 of file qpfile_parser.c.

Referenced by test_lut().