Advertisement
Guest User

libbpg-0.9.1 glue mod

a guest
Dec 8th, 2014
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.50 KB | None | 0 0
  1. diff --git a/bpgenc.c b/bpgenc.c
  2. index 1e98d88..c58cd63 100644
  3. --- a/bpgenc.c
  4. +++ b/bpgenc.c
  5. @@ -1777,6 +1777,9 @@ void help(int is_full)
  6.      if (is_full) {
  7.          printf("\nAdvanced options:\n"
  8.             "-alphaq              set quantizer parameter for the alpha channel (default = same as -q value)\n"
  9. +           "-chroma              set x265's qp offset for chroma planes (default = 0)\n"
  10. +           "-deblocking          set x265's tC:Beta offsets for deblock strength (-6 to 6, default = -1)\n"
  11. +           "-psy                 set x265's psy values for rd@1x and rdoq@2x (0 to 2.0, default = 0.2)\n"
  12.             "-hash                include MD5 hash in HEVC bitstream\n"
  13.             "-keepmetadata        keep the metadata (from JPEG: EXIF, ICC profile, XMP, from PNG: ICC profile)\n"
  14.             "-v                   show debug messages\n"
  15. @@ -1790,6 +1793,9 @@ struct option long_opts[] = {
  16.      { "hash", no_argument },
  17.      { "keepmetadata", no_argument },
  18.      { "alphaq", required_argument },
  19. +    { "chroma", required_argument },
  20. +    { "deblocking", required_argument },
  21. +    { "psy", required_argument },
  22.      { "lossless", no_argument },
  23.      { NULL },
  24.  };
  25. @@ -1802,8 +1808,12 @@ int main(int argc, char **argv)
  26.      uint8_t *out_buf, *alpha_buf, *extension_buf;
  27.      int out_buf_len, alpha_buf_len, verbose;
  28.      FILE *f;
  29. -    int qp, c, option_index, sei_decoded_picture_hash, is_png, extension_buf_len;
  30. -    int keep_metadata, cb_size, width, height, compress_level, alpha_qp;
  31. +    double qp, alpha_qp;
  32. +    int c, option_index, sei_decoded_picture_hash, is_png, extension_buf_len;
  33. +    int keep_metadata, cb_size, width, height, compress_level;
  34. +    int chroma_offset;
  35. +    int deblocking;
  36. +    double psy;
  37.      int bit_depth, lossless_mode;
  38.      BPGImageFormatEnum format;
  39.      BPGColorSpaceEnum color_space;
  40. @@ -1812,12 +1822,15 @@ int main(int argc, char **argv)
  41.      outfilename = DEFAULT_OUTFILENAME;
  42.      qp = DEFAULT_QP;
  43.      alpha_qp = -1;
  44. +    chroma_offset = 0;
  45.      sei_decoded_picture_hash = 0;
  46.      format = BPG_FORMAT_420;
  47.      color_space = BPG_CS_YCbCr;
  48.      keep_metadata = 0;
  49.      verbose = 0;
  50.      compress_level = 7;
  51. +    deblocking = -1;
  52. +    psy = 0.2;
  53.      bit_depth = DEFAULT_BIT_DEPTH;
  54.      lossless_mode = 0;
  55.      for(;;) {
  56. @@ -1825,6 +1838,17 @@ int main(int argc, char **argv)
  57.          if (c == -1)
  58.              break;
  59.          switch(c) {
  60. +        case 'h':
  61. +        show_help:
  62. +            help(1);
  63. +            break;
  64. +        case 'q':
  65. +            qp = atof(optarg);
  66. +            if (qp < 0 || qp > 51) {
  67. +                fprintf(stderr, "qp/crf must be between 0.0 and 51.0\n");
  68. +                exit(1);
  69. +            }
  70. +            break;
  71.          case 0:
  72.              switch(option_index) {
  73.              case 0:
  74. @@ -1834,13 +1858,34 @@ int main(int argc, char **argv)
  75.                  keep_metadata = 1;
  76.                  break;
  77.              case 2:
  78. -                alpha_qp = atoi(optarg);
  79. +                alpha_qp = atof(optarg);
  80.                  if (alpha_qp < 0 || alpha_qp > 51) {
  81.                      fprintf(stderr, "alpha_qp must be between 0 and 51\n");
  82.                      exit(1);
  83.                  }
  84.                  break;
  85.              case 3:
  86. +                chroma_offset = atoi(optarg);
  87. +                if ((chroma_offset + qp) < 0 || (chroma_offset + qp) > 51) {
  88. +                    fprintf(stderr, "chroma qp after offset must be between 0 and 51\n");
  89. +                    exit(1);
  90. +                }
  91. +                break;
  92. +            case 4:
  93. +                deblocking = atoi(optarg);
  94. +                if (deblocking < -6)
  95. +                    deblocking = -6;
  96. +                else if (deblocking > 6)
  97. +                    deblocking = 6;
  98. +                break;
  99. +            case 5:
  100. +                psy = atof(optarg);
  101. +                if (psy < 0)
  102. +                    psy = 0.0;
  103. +                else if (psy > 2)
  104. +                    psy = 2.0;
  105. +                break;
  106. +            case 6:
  107.                  lossless_mode = 1;
  108.                  color_space = BPG_CS_RGB;
  109.                  format = BPG_FORMAT_444;
  110. @@ -1850,17 +1895,6 @@ int main(int argc, char **argv)
  111.                  goto show_help;
  112.              }
  113.              break;
  114. -        case 'h':
  115. -        show_help:
  116. -            help(1);
  117. -            break;
  118. -        case 'q':
  119. -            qp = atoi(optarg);
  120. -            if (qp < 0 || qp > 51) {
  121. -                fprintf(stderr, "qp must be between 0 and 51\n");
  122. -                exit(1);
  123. -            }
  124. -            break;
  125.          case 'o':
  126.              outfilename = optarg;
  127.              break;
  128. @@ -2004,9 +2038,12 @@ int main(int argc, char **argv)
  129.          
  130.      memset(p, 0, sizeof(*p));
  131.      p->qp = qp;
  132. +    p->chroma_offset = chroma_offset;
  133.      p->lossless = lossless_mode;
  134.      p->sei_decoded_picture_hash = sei_decoded_picture_hash;
  135.      p->compress_level = compress_level;
  136. +    p->deblocking = deblocking;
  137. +    p->psy = psy;
  138.      p->verbose = verbose;
  139.      out_buf_len = hevc_encode_picture2(&out_buf, img, p);
  140.      if (out_buf_len < 0) {
  141. diff --git a/bpgenc.h b/bpgenc.h
  142. index 3aa671d..62d6864 100644
  143. --- a/bpgenc.h
  144. +++ b/bpgenc.h
  145. @@ -39,10 +39,13 @@ typedef struct {
  146.  } Image;
  147.  
  148.  typedef struct {
  149. -    int qp; /* quantizer 0-51 */
  150. +    double qp; /* quantizer 0-51 */
  151. +    int chroma_offset;
  152.      int lossless; /* 0-1 lossless mode */
  153.      int sei_decoded_picture_hash; /* 0=no hash, 1=MD5 hash */
  154.      int compress_level; /* 1-9 */
  155. +    int deblocking; /* -6 to 6 */
  156. +    double psy; /* 0 to 2.0 */
  157.      int verbose;
  158.  } HEVCEncodeParams;
  159.  
  160. diff --git a/jctvc_glue.cpp b/jctvc_glue.cpp
  161. index 6aa30b4..566122c 100644
  162. --- a/jctvc_glue.cpp
  163. +++ b/jctvc_glue.cpp
  164. @@ -95,6 +95,18 @@ int jctvc_encode_picture(uint8_t **pbuf, Image *img,
  165.  
  166.      snprintf(buf, sizeof(buf),"--QP=%d", params->qp);
  167.      add_opt(&argc, argv, buf);
  168. +
  169. +    snprintf(buf, sizeof(buf),"--CbQpOffset=%d", params->chroma_offset);
  170. +    add_opt(&argc, argv, buf);
  171. +
  172. +    snprintf(buf, sizeof(buf),"--CrQpOffset=%d", params->chroma_offset);
  173. +    add_opt(&argc, argv, buf);
  174. +
  175. +    snprintf(buf, sizeof(buf),"--LoopFilterBetaOffset_div2=%d", params->deblocking);
  176. +    add_opt(&argc, argv, buf);
  177. +
  178. +    snprintf(buf, sizeof(buf),"--LoopFilterTcOffset_div2=%d", params->deblocking);
  179. +    add_opt(&argc, argv, buf);
  180.      
  181.      snprintf(buf, sizeof(buf),"--SEIDecodedPictureHash=%d",
  182.               params->sei_decoded_picture_hash);
  183. diff --git a/x265_glue.c b/x265_glue.c
  184. index 9641368..915ccd7 100644
  185. --- a/x265_glue.c
  186. +++ b/x265_glue.c
  187. @@ -98,13 +98,22 @@ int x265_encode_picture(uint8_t **pbuf, Image *img,
  188.      p->fpsDenom = 1;
  189.      p->totalFrames = 1;
  190.  
  191. -    p->rc.rateControlMode = X265_RC_CQP;
  192. -    /* XXX: why do we need this offset to match the JCTVC quality ? */
  193. -    if (img->bit_depth == 10)
  194. -        p->rc.qp = params->qp + 7;
  195. -    else
  196. -        p->rc.qp = params->qp + 1;
  197. -        
  198. +    p->rc.rateControlMode = X265_RC_CRF;
  199. +    p->rc.rfConstant = params->qp;
  200. +    p->cbQpOffset = params->chroma_offset;
  201. +    p->crQpOffset = params->chroma_offset;
  202. +    if (params->qp <= 12)
  203. +        p->bCULossless = 1;
  204. +
  205. +    p->psyRd = params->psy;
  206. +    p->deblockingFilterBetaOffset = params->deblocking;
  207. +    p->deblockingFilterTCOffset = params->deblocking;
  208. +
  209. +    /* XXX: Should probably be user-controlled */
  210. +    p->psyRdoq = params->psy * 2.0;
  211. +    p->rc.aqMode = X265_AQ_VARIANCE;
  212. +    p->rc.aqStrength = 1.1;
  213. +
  214.      enc = x265_encoder_open(p);
  215.  
  216.      pic = x265_picture_alloc();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement