Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/bpgenc.c b/bpgenc.c
- index 1e98d88..c58cd63 100644
- --- a/bpgenc.c
- +++ b/bpgenc.c
- @@ -1777,6 +1777,9 @@ void help(int is_full)
- if (is_full) {
- printf("\nAdvanced options:\n"
- "-alphaq set quantizer parameter for the alpha channel (default = same as -q value)\n"
- + "-chroma set x265's qp offset for chroma planes (default = 0)\n"
- + "-deblocking set x265's tC:Beta offsets for deblock strength (-6 to 6, default = -1)\n"
- + "-psy set x265's psy values for rd@1x and rdoq@2x (0 to 2.0, default = 0.2)\n"
- "-hash include MD5 hash in HEVC bitstream\n"
- "-keepmetadata keep the metadata (from JPEG: EXIF, ICC profile, XMP, from PNG: ICC profile)\n"
- "-v show debug messages\n"
- @@ -1790,6 +1793,9 @@ struct option long_opts[] = {
- { "hash", no_argument },
- { "keepmetadata", no_argument },
- { "alphaq", required_argument },
- + { "chroma", required_argument },
- + { "deblocking", required_argument },
- + { "psy", required_argument },
- { "lossless", no_argument },
- { NULL },
- };
- @@ -1802,8 +1808,12 @@ int main(int argc, char **argv)
- uint8_t *out_buf, *alpha_buf, *extension_buf;
- int out_buf_len, alpha_buf_len, verbose;
- FILE *f;
- - int qp, c, option_index, sei_decoded_picture_hash, is_png, extension_buf_len;
- - int keep_metadata, cb_size, width, height, compress_level, alpha_qp;
- + double qp, alpha_qp;
- + int c, option_index, sei_decoded_picture_hash, is_png, extension_buf_len;
- + int keep_metadata, cb_size, width, height, compress_level;
- + int chroma_offset;
- + int deblocking;
- + double psy;
- int bit_depth, lossless_mode;
- BPGImageFormatEnum format;
- BPGColorSpaceEnum color_space;
- @@ -1812,12 +1822,15 @@ int main(int argc, char **argv)
- outfilename = DEFAULT_OUTFILENAME;
- qp = DEFAULT_QP;
- alpha_qp = -1;
- + chroma_offset = 0;
- sei_decoded_picture_hash = 0;
- format = BPG_FORMAT_420;
- color_space = BPG_CS_YCbCr;
- keep_metadata = 0;
- verbose = 0;
- compress_level = 7;
- + deblocking = -1;
- + psy = 0.2;
- bit_depth = DEFAULT_BIT_DEPTH;
- lossless_mode = 0;
- for(;;) {
- @@ -1825,6 +1838,17 @@ int main(int argc, char **argv)
- if (c == -1)
- break;
- switch(c) {
- + case 'h':
- + show_help:
- + help(1);
- + break;
- + case 'q':
- + qp = atof(optarg);
- + if (qp < 0 || qp > 51) {
- + fprintf(stderr, "qp/crf must be between 0.0 and 51.0\n");
- + exit(1);
- + }
- + break;
- case 0:
- switch(option_index) {
- case 0:
- @@ -1834,13 +1858,34 @@ int main(int argc, char **argv)
- keep_metadata = 1;
- break;
- case 2:
- - alpha_qp = atoi(optarg);
- + alpha_qp = atof(optarg);
- if (alpha_qp < 0 || alpha_qp > 51) {
- fprintf(stderr, "alpha_qp must be between 0 and 51\n");
- exit(1);
- }
- break;
- case 3:
- + chroma_offset = atoi(optarg);
- + if ((chroma_offset + qp) < 0 || (chroma_offset + qp) > 51) {
- + fprintf(stderr, "chroma qp after offset must be between 0 and 51\n");
- + exit(1);
- + }
- + break;
- + case 4:
- + deblocking = atoi(optarg);
- + if (deblocking < -6)
- + deblocking = -6;
- + else if (deblocking > 6)
- + deblocking = 6;
- + break;
- + case 5:
- + psy = atof(optarg);
- + if (psy < 0)
- + psy = 0.0;
- + else if (psy > 2)
- + psy = 2.0;
- + break;
- + case 6:
- lossless_mode = 1;
- color_space = BPG_CS_RGB;
- format = BPG_FORMAT_444;
- @@ -1850,17 +1895,6 @@ int main(int argc, char **argv)
- goto show_help;
- }
- break;
- - case 'h':
- - show_help:
- - help(1);
- - break;
- - case 'q':
- - qp = atoi(optarg);
- - if (qp < 0 || qp > 51) {
- - fprintf(stderr, "qp must be between 0 and 51\n");
- - exit(1);
- - }
- - break;
- case 'o':
- outfilename = optarg;
- break;
- @@ -2004,9 +2038,12 @@ int main(int argc, char **argv)
- memset(p, 0, sizeof(*p));
- p->qp = qp;
- + p->chroma_offset = chroma_offset;
- p->lossless = lossless_mode;
- p->sei_decoded_picture_hash = sei_decoded_picture_hash;
- p->compress_level = compress_level;
- + p->deblocking = deblocking;
- + p->psy = psy;
- p->verbose = verbose;
- out_buf_len = hevc_encode_picture2(&out_buf, img, p);
- if (out_buf_len < 0) {
- diff --git a/bpgenc.h b/bpgenc.h
- index 3aa671d..62d6864 100644
- --- a/bpgenc.h
- +++ b/bpgenc.h
- @@ -39,10 +39,13 @@ typedef struct {
- } Image;
- typedef struct {
- - int qp; /* quantizer 0-51 */
- + double qp; /* quantizer 0-51 */
- + int chroma_offset;
- int lossless; /* 0-1 lossless mode */
- int sei_decoded_picture_hash; /* 0=no hash, 1=MD5 hash */
- int compress_level; /* 1-9 */
- + int deblocking; /* -6 to 6 */
- + double psy; /* 0 to 2.0 */
- int verbose;
- } HEVCEncodeParams;
- diff --git a/jctvc_glue.cpp b/jctvc_glue.cpp
- index 6aa30b4..566122c 100644
- --- a/jctvc_glue.cpp
- +++ b/jctvc_glue.cpp
- @@ -95,6 +95,18 @@ int jctvc_encode_picture(uint8_t **pbuf, Image *img,
- snprintf(buf, sizeof(buf),"--QP=%d", params->qp);
- add_opt(&argc, argv, buf);
- +
- + snprintf(buf, sizeof(buf),"--CbQpOffset=%d", params->chroma_offset);
- + add_opt(&argc, argv, buf);
- +
- + snprintf(buf, sizeof(buf),"--CrQpOffset=%d", params->chroma_offset);
- + add_opt(&argc, argv, buf);
- +
- + snprintf(buf, sizeof(buf),"--LoopFilterBetaOffset_div2=%d", params->deblocking);
- + add_opt(&argc, argv, buf);
- +
- + snprintf(buf, sizeof(buf),"--LoopFilterTcOffset_div2=%d", params->deblocking);
- + add_opt(&argc, argv, buf);
- snprintf(buf, sizeof(buf),"--SEIDecodedPictureHash=%d",
- params->sei_decoded_picture_hash);
- diff --git a/x265_glue.c b/x265_glue.c
- index 9641368..915ccd7 100644
- --- a/x265_glue.c
- +++ b/x265_glue.c
- @@ -98,13 +98,22 @@ int x265_encode_picture(uint8_t **pbuf, Image *img,
- p->fpsDenom = 1;
- p->totalFrames = 1;
- - p->rc.rateControlMode = X265_RC_CQP;
- - /* XXX: why do we need this offset to match the JCTVC quality ? */
- - if (img->bit_depth == 10)
- - p->rc.qp = params->qp + 7;
- - else
- - p->rc.qp = params->qp + 1;
- -
- + p->rc.rateControlMode = X265_RC_CRF;
- + p->rc.rfConstant = params->qp;
- + p->cbQpOffset = params->chroma_offset;
- + p->crQpOffset = params->chroma_offset;
- + if (params->qp <= 12)
- + p->bCULossless = 1;
- +
- + p->psyRd = params->psy;
- + p->deblockingFilterBetaOffset = params->deblocking;
- + p->deblockingFilterTCOffset = params->deblocking;
- +
- + /* XXX: Should probably be user-controlled */
- + p->psyRdoq = params->psy * 2.0;
- + p->rc.aqMode = X265_AQ_VARIANCE;
- + p->rc.aqStrength = 1.1;
- +
- enc = x265_encoder_open(p);
- pic = x265_picture_alloc();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement