X-Git-Url: https://git.piment-noir.org/?p=deb_x265.git;a=blobdiff_plain;f=source%2Fx265.cpp;h=ab7c93f31eae2a34031f776841f6c21ab330f915;hp=474cea92eacc462461a1bed4b00806bb75e23c01;hb=b53f7c52d8280ab63876efd6eb292c21430ac607;hpb=5c9b45285dd64723ad1dac380b98a7b1f3095674 diff --git a/source/x265.cpp b/source/x265.cpp index 474cea9..ab7c93f 100644 --- a/source/x265.cpp +++ b/source/x265.cpp @@ -37,7 +37,6 @@ /* Visual Leak Detector */ #include #endif -#include "PPA/ppa.h" #include #include @@ -155,6 +154,11 @@ static const struct option long_options[] = { "aq-strength", required_argument, NULL, 0 }, { "ipratio", required_argument, NULL, 0 }, { "pbratio", required_argument, NULL, 0 }, + { "qcomp", required_argument, NULL, 0 }, + { "qpstep", required_argument, NULL, 0 }, + { "ratetol", required_argument, NULL, 0 }, + { "cplxblur", required_argument, NULL, 0 }, + { "qblur", required_argument, NULL, 0 }, { "cbqpoffs", required_argument, NULL, 0 }, { "crqpoffs", required_argument, NULL, 0 }, { "rd", required_argument, NULL, 0 }, @@ -165,8 +169,10 @@ static const struct option long_options[] = { "no-lossless", no_argument, NULL, 0 }, { "no-signhide", no_argument, NULL, 0 }, { "signhide", no_argument, NULL, 0 }, - { "no-lft", no_argument, NULL, 0 }, - { "lft", no_argument, NULL, 0 }, + { "no-lft", no_argument, NULL, 0 }, /* DEPRECATED */ + { "lft", no_argument, NULL, 0 }, /* DEPRECATED */ + { "no-deblock", no_argument, NULL, 0 }, + { "deblock", required_argument, NULL, 0 }, { "no-sao", no_argument, NULL, 0 }, { "sao", no_argument, NULL, 0 }, { "no-sao-non-deblock", no_argument, NULL, 0 }, @@ -203,7 +209,8 @@ static const struct option long_options[] = { "lambda-file", required_argument, NULL, 0 }, { "b-intra", no_argument, NULL, 0 }, { "no-b-intra", no_argument, NULL, 0 }, - { "nr", required_argument, NULL, 0 }, + { "nr-intra", required_argument, NULL, 0 }, + { "nr-inter", required_argument, NULL, 0 }, { "stats", required_argument, NULL, 0 }, { "pass", required_argument, NULL, 0 }, { "slow-firstpass", no_argument, NULL, 0 }, @@ -268,8 +275,6 @@ struct CLIOptions void showHelp(x265_param *param); bool parse(int argc, char **argv, x265_param* param); bool parseQPFile(x265_picture &pic_org); - void readAnalysisFile(x265_picture* pic, x265_param*); - void writeAnalysisFile(x265_picture* pic, x265_param*); bool validateFanout(x265_param*); }; @@ -291,7 +296,7 @@ void CLIOptions::destroy() void CLIOptions::writeNALs(const x265_nal* nal, uint32_t nalcount) { - PPAScopeEvent(bitstream_write); + ProfileScopeEvent(bitstreamWrite); for (uint32_t i = 0; i < nalcount; i++) { bitstreamFile.write((const char*)nal->payload, nal->sizeBytes); @@ -335,11 +340,14 @@ void CLIOptions::printVersion(x265_param *param) void CLIOptions::showHelp(x265_param *param) { + int level = param->logLevel; x265_param_default(param); printVersion(param); -#define H0 printf #define OPT(value) (value ? "enabled" : "disabled") +#define H0 printf +#define H1 if (level >= X265_LOG_DEBUG) printf + H0("\nSyntax: x265 [options] infile [-o] outfile\n"); H0(" infile can be YUV or Y4M\n"); H0(" outfile is raw HEVC bitstream\n"); @@ -351,18 +359,18 @@ void CLIOptions::showHelp(x265_param *param) H0(" --log-level Logging level: none error warning info debug full. Default %s\n", logLevelNames[param->logLevel + 1]); H0(" --no-progress Disable CLI progress reports\n"); H0(" --[no-]cu-stats Enable logging stats about distribution of cu across all modes. Default %s\n",OPT(param->bLogCuStats)); - H0(" --csv Comma separated log file, log level >= 3 frame log, else one line per run\n"); + H1(" --csv Comma separated log file, log level >= 3 frame log, else one line per run\n"); H0("\nInput Options:\n"); H0(" --input Raw YUV or Y4M input file name. `-` for stdin\n"); - H0(" --y4m Force parsing of input stream as YUV4MPEG2 regardless of file extension\n"); + H1(" --y4m Force parsing of input stream as YUV4MPEG2 regardless of file extension\n"); H0(" --fps Source frame rate (float or num/denom), auto-detected if Y4M\n"); H0(" --input-res WxH Source picture size [w x h], auto-detected if Y4M\n"); - H0(" --input-depth Bit-depth of input file. Default 8\n"); - H0(" --input-csp Source color space: i420, i444 or i422, auto-detected if Y4M. Default: i420\n"); + H1(" --input-depth Bit-depth of input file. Default 8\n"); + H1(" --input-csp Source color space: i420, i444 or i422, auto-detected if Y4M. Default: i420\n"); H0("-f/--frames Maximum number of frames to encode. Default all\n"); H0(" --seek First frame to encode\n"); - H0(" --[no-]interlace Indicate input pictures are interlace fields in temporal order. Default progressive\n"); - H0(" --dither Enable dither if downscaling to 8 bit pixels. Default disabled\n"); + H1(" --[no-]interlace Indicate input pictures are interlace fields in temporal order. Default progressive\n"); + H1(" --dither Enable dither if downscaling to 8 bit pixels. Default disabled\n"); H0("\nQuality reporting metrics:\n"); H0(" --[no-]ssim Enable reporting SSIM metric scores. Default %s\n", OPT(param->bEnableSsim)); H0(" --[no-]psnr Enable reporting PSNR metric scores. Default %s\n", OPT(param->bEnablePsnr)); @@ -381,33 +389,34 @@ void CLIOptions::showHelp(x265_param *param) H0("-p/--preset Trade off performance for compression efficiency. Default medium\n"); H0(" ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, or placebo\n"); H0("-t/--tune Tune the settings for a particular type of source or situation:\n"); - H0(" psnr, ssim, zerolatency, or fastdecode\n"); + H0(" psnr, ssim, grain, zerolatency, fastdecode or cbr\n"); H0("\nQuad-Tree size and depth:\n"); - H0("-s/--ctu <64|32|16> Maximum CU size (default: 64x64). Default %d\n", param->maxCUSize); + H0("-s/--ctu <64|32|16> Maximum CU size (WxH). Default %d\n", param->maxCUSize); H0(" --tu-intra-depth Max TU recursive depth for intra CUs. Default %d\n", param->tuQTMaxIntraDepth); H0(" --tu-inter-depth Max TU recursive depth for inter CUs. Default %d\n", param->tuQTMaxInterDepth); - H0(" --[no-]rect Enable rectangular motion partitions Nx2N and 2NxN. Default %s\n", OPT(param->bEnableRectInter)); - H0(" --[no-]amp Enable asymmetric motion partitions, requires --rect. Default %s\n", OPT(param->bEnableAMP)); H0("\nAnalysis:\n"); H0(" --rd <0..6> Level of RD in mode decision 0:least....6:full RDO. Default %d\n", param->rdLevel); - H0(" --psy-rd <0..2.0> Strength of psycho-visual rate distortion optimization, 0 to disable. Default %f\n", param->psyRd); - H0(" --psy-rdoq <0..50.0> Strength of psycho-visual optimization in quantization, 0 to disable. Default %f\n", param->psyRdoq); - H0(" --nr An integer value in range of 100 to 1000, which denotes strength of noise reduction. Default disabled\n"); - H0(" --[no-]tskip-fast Enable fast intra transform skipping. Default %s\n", OPT(param->bEnableTSkipFast)); + H0(" --psy-rd <0..2.0> Strength of psycho-visual rate distortion optimization, 0 to disable. Default %.1f\n", param->psyRd); + H0(" --psy-rdoq <0..50.0> Strength of psycho-visual optimization in quantization, 0 to disable. Default %.1f\n", param->psyRdoq); H0(" --[no-]early-skip Enable early SKIP detection. Default %s\n", OPT(param->bEnableEarlySkip)); - H0(" --[no-]fast-cbf Enable early outs based on whether residual is coded. Default %s\n", OPT(param->bEnableCbfFastMode)); + H1(" --[no-]fast-cbf Enable early outs based on whether residual is coded. Default %s\n", OPT(param->bEnableCbfFastMode)); + H1(" --[no-]tskip-fast Enable fast intra transform skipping. Default %s\n", OPT(param->bEnableTSkipFast)); + H1(" --nr-intra An integer value in range of 0 to 2000, which denotes strength of noise reduction in intra CUs. Default 0\n"); + H1(" --nr-inter An integer value in range of 0 to 2000, which denotes strength of noise reduction in inter CUs. Default 0\n"); H0("\nCoding tools:\n"); H0("-w/--[no-]weightp Enable weighted prediction in P slices. Default %s\n", OPT(param->bEnableWeightedPred)); H0(" --[no-]weightb Enable weighted prediction in B slices. Default %s\n", OPT(param->bEnableWeightedBiPred)); H0(" --[no-]cu-lossless Consider lossless mode in CU RDO decisions. Default %s\n", OPT(param->bCULossless)); H0(" --[no-]signhide Hide sign bit of one coeff per TU (rdo). Default %s\n", OPT(param->bEnableSignHiding)); - H0(" --[no-]tskip Enable intra 4x4 transform skipping. Default %s\n", OPT(param->bEnableTransformSkip)); + H1(" --[no-]tskip Enable intra 4x4 transform skipping. Default %s\n", OPT(param->bEnableTransformSkip)); H0("\nTemporal / motion search options:\n"); H0(" --me Motion search method dia hex umh star full. Default %d\n", param->searchMethod); H0("-m/--subme Amount of subpel refinement to perform (0:least .. 7:most). Default %d \n", param->subpelRefine); H0(" --merange Motion search range. Default %d\n", param->searchRange); H0(" --max-merge <1..5> Maximum number of merge candidates. Default %d\n", param->maxNumMergeCand); - H0(" --[no-]temporal-mvp Enable temporal MV predictors. Default %s\n", OPT(param->bEnableTemporalMvp)); + H0(" --[no-]rect Enable rectangular motion partitions Nx2N and 2NxN. Default %s\n", OPT(param->bEnableRectInter)); + H0(" --[no-]amp Enable asymmetric motion partitions, requires --rect. Default %s\n", OPT(param->bEnableAMP)); + H1(" --[no-]temporal-mvp Enable temporal MV predictors. Default %s\n", OPT(param->bEnableTemporalMvp)); H0("\nSpatial / intra options:\n"); H0(" --[no-]strong-intra-smoothing Enable strong intra smoothing for 32x32 blocks. Default %s\n", OPT(param->bEnableStrongIntraSmoothing)); H0(" --[no-]constrained-intra Constrained intra prediction (use only intra coded reference pixels) Default %s\n", OPT(param->bEnableConstrainedIntra)); @@ -422,57 +431,59 @@ void CLIOptions::showHelp(x265_param *param) H0(" --scenecut How aggressively to insert extra I-frames. Default %d\n", param->scenecutThreshold); H0(" --rc-lookahead Number of frames for frame-type lookahead (determines encoder latency) Default %d\n", param->lookaheadDepth); H0(" --bframes Maximum number of consecutive b-frames (now it only enables B GOP structure) Default %d\n", param->bframes); - H0(" --bframe-bias Bias towards B frame decisions. Default %d\n", param->bFrameBias); + H1(" --bframe-bias Bias towards B frame decisions. Default %d\n", param->bFrameBias); H0(" --b-adapt <0..2> 0 - none, 1 - fast, 2 - full (trellis) adaptive B frame scheduling. Default %d\n", param->bFrameAdaptive); H0(" --[no-]b-pyramid Use B-frames as references. Default %s\n", OPT(param->bBPyramid)); H0(" --ref max number of L0 references to be allowed (1 .. 16) Default %d\n", param->maxNumReferences); - H0(" --qpfile Force frametypes and QPs for some or all frames\n"); - H0(" Format of each line: framenumber frametype QP\n"); - H0(" QP is optional (none lets x265 choose). Frametypes: I,i,P,B,b.\n"); - H0(" QPs are restricted by qpmin/qpmax.\n"); - H0("\nRate control, Quantization:\n"); + H1(" --qpfile Force frametypes and QPs for some or all frames\n"); + H1(" Format of each line: framenumber frametype QP\n"); + H1(" QP is optional (none lets x265 choose). Frametypes: I,i,P,B,b.\n"); + H1(" QPs are restricted by qpmin/qpmax.\n"); + H0("\nRate control, Adaptive Quantization:\n"); H0(" --bitrate Target bitrate (kbps) for ABR (implied). Default %d\n", param->rc.bitrate); - H0("-q/--qp QP for P slices in CQP mode (implied). --ipratio and --pbration determine other slice QPs\n"); - H0(" --crf Quality-based VBR (0-51). Default %f\n", param->rc.rfConstant); - H0(" --[no-]lossless Enable lossless: bypass transform, quant and loop filters globally. Default %s\n", OPT(param->bLossless)); - H0(" --crf-max With CRF+VBV, limit RF to this value. Default %f\n", param->rc.rfConstantMax); - H0(" May cause VBV underflows!\n"); - H0(" --crf-min With CRF+VBV, limit RF to this value. Default %f\n", param->rc.rfConstantMin); - H0(" this specifies a minimum rate factor value for encode!\n"); + H1("-q/--qp QP for P slices in CQP mode (implied). --ipratio and --pbration determine other slice QPs\n"); + H0(" --crf Quality-based VBR (0-51). Default %.1f\n", param->rc.rfConstant); + H1(" --[no-]lossless Enable lossless: bypass transform, quant and loop filters globally. Default %s\n", OPT(param->bLossless)); + H1(" --crf-max With CRF+VBV, limit RF to this value. Default %f\n", param->rc.rfConstantMax); + H1(" May cause VBV underflows!\n"); + H1(" --crf-min With CRF+VBV, limit RF to this value. Default %f\n", param->rc.rfConstantMin); + H1(" this specifies a minimum rate factor value for encode!\n"); H0(" --vbv-maxrate Max local bitrate (kbit/s). Default %d\n", param->rc.vbvMaxBitrate); H0(" --vbv-bufsize Set size of the VBV buffer (kbit). Default %d\n", param->rc.vbvBufferSize); - H0(" --vbv-init Initial VBV buffer occupancy (fraction of bufsize or in kbits). Default %f\n", param->rc.vbvBufferInit); - H0(" --aq-mode Mode for Adaptive Quantization - 0:none 1:uniform AQ 2:auto variance. Default %d\n", param->rc.aqMode); - H0(" --aq-strength Reduces blocking and blurring in flat and textured areas.(0 to 3.0). Default %f\n", param->rc.aqStrength); - H0(" --[no-]cutree Enable cutree for Adaptive Quantization. Default %s\n", OPT(param->rc.cuTree)); - H0(" --ipratio QP factor between I and P. Default %f\n", param->rc.ipFactor); - H0(" --pbratio QP factor between P and B. Default %f\n", param->rc.pbFactor); - H0(" --cbqpoffs Chroma Cb QP Offset. Default %d\n", param->cbQpOffset); - H0(" --crqpoffs Chroma Cr QP Offset. Default %d\n", param->crQpOffset); - H0(" --stats Filename for stats file in multipass pass rate control. Default x265_2pass.log\n"); + H0(" --vbv-init Initial VBV buffer occupancy (fraction of bufsize or in kbits). Default %.2f\n", param->rc.vbvBufferInit); H0(" --pass Multi pass rate control.\n" " - 1 : First pass, creates stats file\n" " - 2 : Last pass, does not overwrite stats file\n" " - 3 : Nth pass, overwrites stats file\n"); + H0(" --stats Filename for stats file in multipass pass rate control. Default x265_2pass.log\n"); H0(" --[no-]slow-firstpass Enable a slow first pass in a multipass rate control mode. Default %s\n", OPT(param->rc.bEnableSlowFirstPass)); H0(" --analysis-mode save - Dump analysis info into file, load - Load analysis buffers from the file. Default %d\n", param->analysisMode); H0(" --analysis-file Specify file name used for either dumping or reading analysis data.\n"); - H0(" --scaling-list Specify a file containing HM style quant scaling lists or 'default' or 'off'. Default: off\n"); - H0(" --lambda-file Specify a file containing replacement values for the lambda tables\n"); - H0(" MAX_MAX_QP+1 floats for lambda table, then again for lambda2 table\n"); - H0(" Blank lines and lines starting with hash(#) are ignored\n"); - H0(" Comma is considered to be white-space\n"); + H0(" --aq-mode Mode for Adaptive Quantization - 0:none 1:uniform AQ 2:auto variance. Default %d\n", param->rc.aqMode); + H0(" --aq-strength Reduces blocking and blurring in flat and textured areas (0 to 3.0). Default %.2f\n", param->rc.aqStrength); + H0(" --[no-]cutree Enable cutree for Adaptive Quantization. Default %s\n", OPT(param->rc.cuTree)); + H1(" --ipratio QP factor between I and P. Default %.2f\n", param->rc.ipFactor); + H1(" --pbratio QP factor between P and B. Default %.2f\n", param->rc.pbFactor); + H1(" --qcomp Weight given to predicted complexity. Default %.2f\n", param->rc.qCompress); + H1(" --ratetol Degree of rate fluctuation that can be tolerated. Default %.2f\n", param->rc.rateTolerance); + H1(" --cbqpoffs Chroma Cb QP Offset. Default %d\n", param->cbQpOffset); + H1(" --crqpoffs Chroma Cr QP Offset. Default %d\n", param->crQpOffset); + H1(" --scaling-list Specify a file containing HM style quant scaling lists or 'default' or 'off'. Default: off\n"); + H1(" --lambda-file Specify a file containing replacement values for the lambda tables\n"); + H1(" MAX_MAX_QP+1 floats for lambda table, then again for lambda2 table\n"); + H1(" Blank lines and lines starting with hash(#) are ignored\n"); + H1(" Comma is considered to be white-space\n"); H0("\nLoop filters (deblock and SAO):\n"); - H0(" --[no-]lft Enable Deblocking Loop Filter. Default %s\n", OPT(param->bEnableLoopFilter)); + H0(" --[no-]deblock Enable Deblocking Loop Filter, optionally specify tC:Beta offsets Default %s\n", OPT(param->bEnableLoopFilter)); H0(" --[no-]sao Enable Sample Adaptive Offset. Default %s\n", OPT(param->bEnableSAO)); - H0(" --[no-]sao-non-deblock Use non-deblocked pixels, else right/bottom boundary areas skipped. Default %s\n", OPT(param->bSaoNonDeblocked)); + H1(" --[no-]sao-non-deblock Use non-deblocked pixels, else right/bottom boundary areas skipped. Default %s\n", OPT(param->bSaoNonDeblocked)); H0("\nVUI options:\n"); H0(" --sar Sample Aspect Ratio, the ratio of width to height of an individual pixel.\n"); H0(" Choose from 0=undef, 1=1:1(\"square\"), 2=12:11, 3=10:11, 4=16:11,\n"); H0(" 5=40:33, 6=24:11, 7=20:11, 8=32:11, 9=80:33, 10=18:11, 11=15:11,\n"); H0(" 12=64:33, 13=160:99, 14=4:3, 15=3:2, 16=2:1 or custom ratio of . Default %d\n", param->vui.aspectRatioIdc); - H0(" --crop-rect Add 'left,top,right,bottom' to the bitstream-level cropping rectangle\n"); - H0(" --overscan Specify whether it is appropriate for decoder to show cropped region: undef, show or crop. Default undef\n"); + H1(" --crop-rect Add 'left,top,right,bottom' to the bitstream-level cropping rectangle\n"); + H1(" --overscan Specify whether it is appropriate for decoder to show cropped region: undef, show or crop. Default undef\n"); H0(" --videoformat Specify video format from undef, component, pal, ntsc, secam, mac. Default undef\n"); H0(" --range Specify black level and range of luma and chroma signals as full or limited Default limited\n"); H0(" --colorprim Specify color primaries from undef, bt709, bt470m, bt470bg, smpte170m,\n"); @@ -480,21 +491,25 @@ void CLIOptions::showHelp(x265_param *param) H0(" --transfer Specify transfer characteristics from undef, bt709, bt470m, bt470bg, smpte170m,\n"); H0(" smpte240m, linear, log100, log316, iec61966-2-4, bt1361e, iec61966-2-1,\n"); H0(" bt2020-10, bt2020-12. Default undef\n"); - H0(" --colormatrix Specify color matrix setting from undef, bt709, fcc, bt470bg, smpte170m,\n"); - H0(" smpte240m, GBR, YCgCo, bt2020nc, bt2020c. Default undef\n"); - H0(" --chromaloc Specify chroma sample location (0 to 5). Default of %d\n", param->vui.chromaSampleLocTypeTopField); + H1(" --colormatrix Specify color matrix setting from undef, bt709, fcc, bt470bg, smpte170m,\n"); + H1(" smpte240m, GBR, YCgCo, bt2020nc, bt2020c. Default undef\n"); + H1(" --chromaloc Specify chroma sample location (0 to 5). Default of %d\n", param->vui.chromaSampleLocTypeTopField); H0("\nBitstream options:\n"); H0(" --[no-]info Emit SEI identifying encoder and parameters. Default %s\n", OPT(param->bEmitInfoSEI)); H0(" --[no-]aud Emit access unit delimiters at the start of each access unit. Default %s\n", OPT(param->bEnableAccessUnitDelimiters)); - H0(" --[no-]hrd Enable HRD parameters signalling. Default %s\n", OPT(param->bEmitHRDSEI)); + H0(" --[no-]hrd Enable HRD parameters signaling. Default %s\n", OPT(param->bEmitHRDSEI)); H0(" --[no-]repeat-headers Emit SPS and PPS headers at each keyframe. Default %s\n", OPT(param->bRepeatHeaders)); - H0(" --hash Decoded Picture Hash SEI 0: disabled, 1: MD5, 2: CRC, 3: Checksum. Default %d\n", param->decodedPictureHashSEI); - H0("\nReconstructed video options (debugging):\n"); - H0("-r/--recon Reconstructed raw image YUV or Y4M output file name\n"); - H0(" --recon-depth Bit-depth of reconstructed raw image file. Defaults to input bit depth, or 8 if Y4M\n"); + H1(" --hash Decoded Picture Hash SEI 0: disabled, 1: MD5, 2: CRC, 3: Checksum. Default %d\n", param->decodedPictureHashSEI); + H1("\nReconstructed video options (debugging):\n"); + H1("-r/--recon Reconstructed raw image YUV or Y4M output file name\n"); + H1(" --recon-depth Bit-depth of reconstructed raw image file. Defaults to input bit depth, or 8 if Y4M\n"); #undef OPT #undef H0 - printf("\n\nFull documentation may be found at http://x265.readthedocs.org/en/default/cli.html\n"); +#undef H1 + + if (level < X265_LOG_DEBUG) + printf("\nUse --log-level full --help for a full listing\n"); + printf("\n\nComplete documentation may be found at http://x265.readthedocs.org/en/default/cli.html\n"); exit(0); } @@ -510,7 +525,6 @@ bool CLIOptions::parse(int argc, char **argv, x265_param* param) const char *preset = NULL; const char *tune = NULL; const char *profile = NULL; - const char *analysisfn = "x265_analysis.dat"; if (argc <= 1) { @@ -603,7 +617,6 @@ bool CLIOptions::parse(int argc, char **argv, x265_param* param) OPT("profile") profile = optarg; /* handled last */ OPT("preset") /* handled above */; OPT("tune") /* handled above */; - OPT("analysis-file") analysisfn = optarg; OPT("qpfile") { this->qpfile = fopen(optarg, "rb"); @@ -751,163 +764,9 @@ bool CLIOptions::parse(int argc, char **argv, x265_param* param) x265_log(NULL, X265_LOG_ERROR, "failed to open bitstream file <%s> for writing\n", bitstreamfn); return true; } - - if (param->analysisMode) - { - const char *mode = param->analysisMode == X265_ANALYSIS_SAVE ? "wb" : "rb"; - this->analysisFile = fopen(analysisfn, mode); - if (!this->analysisFile) - { - x265_log(NULL, X265_LOG_ERROR, "failed to open analysis file %s\n", analysisfn); - return true; - } - } - return false; } -bool CLIOptions::validateFanout(x265_param *param) -{ -#define CMP_OPT_FANOUT(opt, param_val)\ - {\ - bErr = 0;\ - p = strstr(paramBuf, opt "=");\ - char* q = strstr(paramBuf, "no-"opt);\ - if (p && sscanf(p, opt "=%d" , &i) && param_val != i)\ - bErr = 1;\ - else if (!param_val && !q)\ - bErr = 1;\ - else if (param_val && (q || !strstr(paramBuf, opt)))\ - bErr = 1;\ - if (bErr)\ - {\ - x265_log(param, X265_LOG_ERROR, "different " opt " setting than given in analysis file (%d vs %d)\n", param_val, i);\ - X265_FREE(paramBuf);\ - return false;\ - }\ - } - - char *p = NULL, *paramBuf; - int i, j; - uint32_t k , l; - bool bErr = false; - - paramBuf = X265_MALLOC(char, MAXPARAMSIZE); - if (!paramBuf) - return false; - - fread(paramBuf, 1, MAXPARAMSIZE, this->analysisFile); - - /* check whether fanout options are compatible */ - if (strncmp(paramBuf, "#options:", 9)) - { - x265_log(param, X265_LOG_ERROR, "options list in analysis file is not valid\n"); - X265_FREE(paramBuf); - return false; - } - - char* buf = strchr(paramBuf, '\n'); - if (!buf) - { - x265_log(param, X265_LOG_ERROR, "Malformed analysis file\n"); - X265_FREE(paramBuf); - return false; - } - *buf = '\0'; - fseek(this->analysisFile, (int)strlen(paramBuf) + 1, SEEK_SET); - - if (sscanf(paramBuf, "#options: %dx%d", &i, &j) != 2) - { - x265_log(param, X265_LOG_ERROR, "Resolution specified in analysis file is not valid\n"); - X265_FREE(paramBuf); - return false; - } - if ((p = strstr(paramBuf, " fps=")) == 0 || sscanf(p, " fps=%u/%u", &k, &l) != 2) - { - x265_log(param, X265_LOG_ERROR, "fps specified in analysis file is not valid\n"); - X265_FREE(paramBuf); - return false; - } - if (k != param->fpsNum || l != param->fpsDenom) - { - x265_log(param, X265_LOG_ERROR, "fps mismatch than given in analysis file (%u/%u vs %u/%u)\n", - param->fpsNum, param->fpsDenom, k, l); - X265_FREE(paramBuf); - return false; - } - - CMP_OPT_FANOUT("bitdepth", param->internalBitDepth); - CMP_OPT_FANOUT("weightp", param->bEnableWeightedPred); - CMP_OPT_FANOUT("bframes", param->bframes); - CMP_OPT_FANOUT("b-pyramid", param->bBPyramid); - CMP_OPT_FANOUT("b-adapt", param->bFrameAdaptive); - CMP_OPT_FANOUT("open-gop", param->bOpenGOP); - CMP_OPT_FANOUT("keyint", param->keyframeMax); - CMP_OPT_FANOUT("min-keyint", param->keyframeMin); - CMP_OPT_FANOUT("scenecut", param->scenecutThreshold); - CMP_OPT_FANOUT("ctu", (int)param->maxCUSize); - CMP_OPT_FANOUT("ref", param->maxNumReferences); - CMP_OPT_FANOUT("rc-lookahead", param->lookaheadDepth); - -#undef CMP_OPT_FANOUT - - X265_FREE(paramBuf); - return true; -} - -void CLIOptions::readAnalysisFile(x265_picture* pic, x265_param* p) -{ - int poc, width, height; - uint32_t numPart, numCU; - fread(&width, sizeof(int), 1, this->analysisFile); - fread(&height, sizeof(int), 1, this->analysisFile); - fread(&poc, sizeof(int), 1, this->analysisFile); - fread(&pic->sliceType, sizeof(int), 1, this->analysisFile); - fread(&numCU, sizeof(int), 1, this->analysisFile); - fread(&numPart, sizeof(int), 1, this->analysisFile); - - if (poc != pic->poc || width != p->sourceWidth || height != p->sourceHeight) - { - x265_log(NULL, X265_LOG_WARNING, "Error in reading intra-inter data.\n"); - x265_free_analysis_data(pic); - return; - } - - fread(pic->analysisData.intraData->depth, - sizeof(uint8_t), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile); - fread(pic->analysisData.intraData->modes, - sizeof(uint8_t), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile); - fread(pic->analysisData.intraData->partSizes, - sizeof(char), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile); - fread(pic->analysisData.intraData->poc, - sizeof(int), pic->analysisData.numCUsInFrame, this->analysisFile); - fread(pic->analysisData.intraData->cuAddr, - sizeof(uint32_t), pic->analysisData.numCUsInFrame, this->analysisFile); - fread(pic->analysisData.interData, sizeof(x265_inter_data), pic->analysisData.numCUsInFrame * 85, this->analysisFile); -} - -void CLIOptions::writeAnalysisFile(x265_picture* pic, x265_param *p) -{ - uint64_t seekTo = pic->poc * this->analysisRecordSize + this->analysisHeaderSize; - fseeko(this->analysisFile, seekTo, SEEK_SET); - fwrite(&p->sourceWidth, sizeof(int), 1, this->analysisFile); - fwrite(&p->sourceHeight, sizeof(int), 1, this->analysisFile); - fwrite(&pic->poc, sizeof(int), 1, this->analysisFile); - fwrite(&pic->sliceType, sizeof(int), 1, this->analysisFile); - fwrite(&pic->analysisData.numCUsInFrame, sizeof(int), 1, this->analysisFile); - fwrite(&pic->analysisData.numPartitions, sizeof(int), 1, this->analysisFile); - - fwrite(pic->analysisData.intraData->depth, - sizeof(uint8_t), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile); - fwrite(pic->analysisData.intraData->modes, - sizeof(uint8_t), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile); - fwrite(pic->analysisData.intraData->partSizes, - sizeof(char), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile); - fwrite(pic->analysisData.intraData->poc, sizeof(int), pic->analysisData.numCUsInFrame, this->analysisFile); - fwrite(pic->analysisData.intraData->cuAddr, sizeof(uint32_t), pic->analysisData.numCUsInFrame, this->analysisFile); - fwrite(pic->analysisData.interData, sizeof(x265_inter_data), pic->analysisData.numCUsInFrame * 85, this->analysisFile); -} - bool CLIOptions::parseQPFile(x265_picture &pic_org) { int32_t num = -1, qp, ret; @@ -948,7 +807,7 @@ int main(int argc, char **argv) // This uses Microsoft's proprietary WCHAR type, but this only builds on Windows to start with VLDSetReportOptions(VLD_OPT_REPORT_TO_DEBUGGER | VLD_OPT_REPORT_TO_FILE, L"x265_leaks.txt"); #endif - PPA_INIT(); + PROFILE_INIT(); x265_param *param = x265_param_alloc(); CLIOptions cliopt; @@ -979,7 +838,8 @@ int main(int argc, char **argv) x265_picture pic_orig, pic_out; x265_picture *pic_in = &pic_orig; - x265_picture *pic_recon = cliopt.recon ? &pic_out : NULL; + /* Allocate recon picture if analysisMode is enabled */ + x265_picture *pic_recon = (cliopt.recon || !!param->analysisMode) ? &pic_out : NULL; uint32_t inFrameCount = 0; uint32_t outFrameCount = 0; x265_nal *p_nal; @@ -1000,35 +860,12 @@ int main(int argc, char **argv) x265_picture_init(param, pic_in); - if (param->analysisMode && !pic_recon) - { - x265_log(NULL, X265_LOG_ERROR, "Must specify recon with analysis-mode option.\n"); - goto fail; - } if (param->analysisMode) { - if (param->analysisMode == X265_ANALYSIS_SAVE) + if (param->bDistributeModeAnalysis || param->bDistributeMotionEstimation) { - char *p = x265_param2string(param); - if (!p) - { - x265_log(NULL, X265_LOG_ERROR, "analysis: buffer allocation failure, aborting"); - goto fail; - } - uint32_t numCU = pic_in->analysisData.numCUsInFrame; - uint32_t numPart = pic_in->analysisData.numPartitions; - - cliopt.analysisRecordSize = ((sizeof(int) * 4 + sizeof(uint32_t) * 2) + sizeof(x265_inter_data) * numCU * 85 + - sizeof(uint8_t) * 2 * numPart * numCU + sizeof(char) * numPart * numCU + sizeof(int) * numCU + sizeof(uint32_t) * numCU); - - fprintf(cliopt.analysisFile, "#options: %s\n", p); - cliopt.analysisHeaderSize = ftell(cliopt.analysisFile); - X265_FREE(p); - } - else - { - if (!cliopt.validateFanout(param)) - goto fail; + x265_log(NULL, X265_LOG_ERROR, "Analysis load/save options incompatible with pmode/pme"); + goto fail; } } @@ -1069,13 +906,6 @@ int main(int argc, char **argv) ditherImage(*pic_in, param->sourceWidth, param->sourceHeight, errorBuf, X265_DEPTH); pic_in->bitDepth = X265_DEPTH; } - if (param->analysisMode) - { - x265_alloc_analysis_data(pic_in); - - if (param->analysisMode == X265_ANALYSIS_LOAD) - cliopt.readAnalysisFile(pic_in, param); - } } int numEncoded = x265_encoder_encode(encoder, &p_nal, &nal, pic_in, pic_recon); @@ -1085,15 +915,9 @@ int main(int argc, char **argv) break; } outFrameCount += numEncoded; - if (numEncoded && pic_recon) - { - cliopt.recon->writePicture(pic_out); - if (param->analysisMode == X265_ANALYSIS_SAVE) - cliopt.writeAnalysisFile(pic_recon, param); - if (param->analysisMode) - x265_free_analysis_data(pic_recon); - } + if (numEncoded && pic_recon && cliopt.recon) + cliopt.recon->writePicture(pic_out); if (nal) cliopt.writeNALs(p_nal, nal); @@ -1106,15 +930,8 @@ int main(int argc, char **argv) { uint32_t numEncoded = x265_encoder_encode(encoder, &p_nal, &nal, NULL, pic_recon); outFrameCount += numEncoded; - if (numEncoded && pic_recon) - { + if (numEncoded && pic_recon && cliopt.recon) cliopt.recon->writePicture(pic_out); - if (param->analysisMode == X265_ANALYSIS_SAVE) - cliopt.writeAnalysisFile(pic_recon, param); - if (param->analysisMode) - x265_free_analysis_data(pic_recon); - } - if (nal) cliopt.writeNALs(p_nal, nal);