summaryrefslogtreecommitdiffstats
path: root/libmpcodecs
diff options
context:
space:
mode:
authorgpoirier <gpoirier@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-09-02 21:54:17 +0000
committergpoirier <gpoirier@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-09-02 21:54:17 +0000
commitb2e88f2b3295e0a0a9650b80e54c56b8653b9d52 (patch)
tree8061991d66f5297334ac688171f96038196289b5 /libmpcodecs
parentf3c89204fcc5d4e4e2e5953ba27971b0c57ce697 (diff)
downloadmpv-b2e88f2b3295e0a0a9650b80e54c56b8653b9d52.tar.bz2
mpv-b2e88f2b3295e0a0a9650b80e54c56b8653b9d52.tar.xz
custom quantization matrix for x264, original patch by Robert Swain < robert POUM swain AH gmail POUM com>
Lots of nits and improvement by the MPlayer team Original thread: Date: Jul 12, 2005 5:04 PM Subject: [MPlayer-dev-eng] [PATCH] CQMs in x264 git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@16367 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpcodecs')
-rw-r--r--libmpcodecs/ve_x264.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/libmpcodecs/ve_x264.c b/libmpcodecs/ve_x264.c
index c79bea46ba..2dd263d9ea 100644
--- a/libmpcodecs/ve_x264.c
+++ b/libmpcodecs/ve_x264.c
@@ -106,6 +106,13 @@ static int psnr = 0;
static int log_level = 2;
static int turbo = 0;
static int visualize = 0;
+static char *cqm = NULL;
+static char *cqm4iy = NULL;
+static char *cqm4ic = NULL;
+static char *cqm4py = NULL;
+static char *cqm4pc = NULL;
+static char *cqm8iy = NULL;
+static char *cqm8py = NULL;
m_option_t x264encopts_conf[] = {
{"bitrate", &bitrate, CONF_TYPE_INT, CONF_RANGE, 0, 24000000, NULL},
@@ -155,6 +162,13 @@ m_option_t x264encopts_conf[] = {
{"qp_step", &qp_step, CONF_TYPE_INT, CONF_RANGE, 1, 50, NULL},
{"pass", &pass, CONF_TYPE_INT, CONF_RANGE, 1, 3, NULL},
{"rc_eq", &rc_eq, CONF_TYPE_STRING, 0, 0, 0, NULL},
+ {"cqm", &cqm, CONF_TYPE_STRING, 0, 0, 0, NULL},
+ {"cqm4iy", &cqm4iy, CONF_TYPE_STRING, 0, 0, 0, NULL},
+ {"cqm4ic", &cqm4ic, CONF_TYPE_STRING, 0, 0, 0, NULL},
+ {"cqm4py", &cqm4py, CONF_TYPE_STRING, 0, 0, 0, NULL},
+ {"cqm4pc", &cqm4pc, CONF_TYPE_STRING, 0, 0, 0, NULL},
+ {"cqm8iy", &cqm8iy, CONF_TYPE_STRING, 0, 0, 0, NULL},
+ {"cqm8py", &cqm8py, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"qcomp", &qcomp, CONF_TYPE_FLOAT, CONF_RANGE, 0, 1, NULL},
{"qblur", &qblur, CONF_TYPE_FLOAT, CONF_RANGE, 0, 99, NULL},
{"cplx_blur", &complexity_blur, CONF_TYPE_FLOAT, CONF_RANGE, 0, 999, NULL},
@@ -173,6 +187,23 @@ m_option_t x264encopts_conf[] = {
{NULL, NULL, 0, 0, 0, 0, NULL}
};
+static int parse_cqm(const char *str, uint8_t *cqm, int length,
+ h264_module_t *mod, char *matrix_name) {
+ int i;
+ if (!str) return 0;
+ for (i = 0; i < length; i++) {
+ long coef = strtol(str, &str, 0);
+ if (coef < 1 || coef > 255 || str[0] != ((i + 1 == length)?0:',')) {
+ mp_msg( MSGT_MENCODER, MSGL_ERR, "x264: Invalid entry in cqm%s at position %d.\n", matrix_name, i+1 );
+ return -1;
+ }
+ cqm[i] = coef;
+ str = &str[1];
+ }
+ mod->param.i_cqm_preset = X264_CQM_CUSTOM;
+ return 0;
+}
+
static int put_image(struct vf_instance_s *vf, mp_image_t *mpi);
static int encode_frame(struct vf_instance_s *vf, x264_picture_t *pic_in);
@@ -263,6 +294,38 @@ static int config(struct vf_instance_s* vf, int width, int height, int d_width,
mod->param.vui.i_sar_height = d_height*width;
mod->param.i_threads = threads;
+ if(cqm != NULL)
+ {
+ if( !strcmp(cqm, "flat") )
+ mod->param.i_cqm_preset = X264_CQM_FLAT;
+ else if( !strcmp(cqm, "jvt") )
+ mod->param.i_cqm_preset = X264_CQM_JVT;
+ else
+ {
+ FILE *cqm_test;
+ cqm_test = fopen( cqm, "rb" );
+ if( cqm_test )
+ {
+ mod->param.i_cqm_preset = X264_CQM_CUSTOM;
+ mod->param.psz_cqm_file = cqm;
+ fclose( cqm_test );
+ }
+ else
+ {
+ mp_msg( MSGT_MENCODER, MSGL_ERR, "x264: CQM file failed to open.\n" );
+ return 0;
+ }
+ }
+ }
+
+ if( (parse_cqm(cqm4iy, mod->param.cqm_4iy, 16, mod, "4iy") < 0) ||
+ (parse_cqm(cqm4ic, mod->param.cqm_4ic, 16, mod, "4ic") < 0) ||
+ (parse_cqm(cqm4py, mod->param.cqm_4py, 16, mod, "4py") < 0) ||
+ (parse_cqm(cqm4pc, mod->param.cqm_4pc, 16, mod, "4pc") < 0) ||
+ (parse_cqm(cqm8iy, mod->param.cqm_8iy, 64, mod, "8iy") < 0) ||
+ (parse_cqm(cqm8py, mod->param.cqm_8py, 64, mod, "8py") < 0) )
+ return 0;
+
switch(pass) {
case 0:
mod->param.rc.b_stat_write = 0;