This file is indexed.

/usr/share/doc/libx265-doc/html/api.html is in libx265-doc 1.9-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Application Programming Interface &mdash; x265  documentation</title>
    
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="x265  documentation" href="index.html" />
    <link rel="next" title="Threading" href="threading.html" />
    <link rel="prev" title="Command Line Options" href="cli.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="threading.html" title="Threading"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="cli.html" title="Command Line Options"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">x265  documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="application-programming-interface">
<h1>Application Programming Interface<a class="headerlink" href="#application-programming-interface" title="Permalink to this headline"></a></h1>
<div class="section" id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h2>
<p>x265 is written primarily in C++ and x86 assembly language but the
public facing programming interface is C for the widest possible
portability.  This C interface is wholly defined within <code class="file docutils literal"><span class="pre">x265.h</span></code>
in the source/ folder of our source tree.  All of the functions and
variables and enumerations meant to be used by the end-user are present
in this header.</p>
<p>Where possible, x265 has tried to keep its public API as close as
possible to x264&#8217;s public API. So those familiar with using x264 through
its C interface will find x265 quite familiar.</p>
<p>This file is meant to be read in-order; the narrative follows linearly
through the various sections</p>
</div>
<div class="section" id="build-considerations">
<h2>Build Considerations<a class="headerlink" href="#build-considerations" title="Permalink to this headline"></a></h2>
<p>The choice of Main or Main10 profile encodes is made at compile time;
the internal pixel depth influences a great deal of variable sizes and
thus 8 and 10bit pixels are handled as different build options
(primarily to maintain the performance of the 8bit builds). libx265
exports a variable <strong>x265_max_bit_depth</strong> which indicates how the
library was compiled (it will contain a value of 8 or 10). Further,
<strong>x265_version_str</strong> is a pointer to a string indicating the version of
x265 which was compiled, and <strong>x265_build_info_str</strong> is a pointer to a
string identifying the compiler and build options.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><strong>x265_version_str</strong> is only updated when <strong>cmake</strong> runs. If you are
making binaries for others to use, it is recommended to run
<strong>cmake</strong> prior to <strong>make</strong> in your build scripts.</p>
</div>
<p>x265 will accept input pixels of any depth between 8 and 16 bits
regardless of the depth of its internal pixels (8 or 10).  It will shift
and mask input pixels as required to reach the internal depth. If
downshifting is being performed using our CLI application (to 8 bits),
the <a class="reference internal" href="cli.html#cmdoption--dither"><code class="xref std std-option docutils literal"><span class="pre">--dither</span></code></a> option may be enabled to reduce banding. This
feature is not available through the C interface.</p>
</div>
<div class="section" id="encoder">
<h2>Encoder<a class="headerlink" href="#encoder" title="Permalink to this headline"></a></h2>
<p>The primary object in x265 is the encoder object, and this is
represented in the public API as an opaque typedef <strong>x265_encoder</strong>.
Pointers of this type are passed to most encoder functions.</p>
<p>A single encoder generates a single output bitstream from a sequence of
raw input pictures.  Thus if you need multiple output bitstreams you
must allocate multiple encoders.  You may pass the same input pictures
to multiple encoders, the encode function does not modify the input
picture structures (the pictures are copied into the encoder as the
first step of encode).</p>
<p>Encoder allocation is a reentrant function, so multiple encoders may be
safely allocated in a single process. The encoder access functions are
not reentrant for a single encoder, so the recommended use case is to
allocate one client thread per encoder instance (one thread for all
encoder instances is possible, but some encoder access functions are
blocking and thus this would be less efficient).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">There is one caveat to having multiple encoders within a single
process. All of the encoders must use the same maximum CTU size
because many global variables are configured based on this size.
Encoder allocation will fail if a mis-matched CTU size is attempted.
If no encoders are open, <strong>x265_cleanup()</strong> can be called to reset
the configured CTU size so a new size can be used.</p>
</div>
<p>An encoder is allocated by calling <strong>x265_encoder_open()</strong>:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_encoder_open:
 *      create a new encoder handler, all parameters from x265_param are copied */
x265_encoder* x265_encoder_open(x265_param *);
</pre></div>
</div>
<p>The returned pointer is then passed to all of the functions pertaining
to this encode. A large amount of memory is allocated during this
function call, but the encoder will continue to allocate memory as the
first pictures are passed to the encoder; until its pool of picture
structures is large enough to handle all of the pictures it must keep
internally.  The pool size is determined by the lookahead depth, the
number of frame threads, and the maximum number of references.</p>
<p>As indicated in the comment, <strong>x265_param</strong> is copied internally so the user
may release their copy after allocating the encoder.  Changes made to
their copy of the param structure have no affect on the encoder after it
has been allocated.</p>
</div>
<div class="section" id="param">
<h2>Param<a class="headerlink" href="#param" title="Permalink to this headline"></a></h2>
<p>The <strong>x265_param</strong> structure describes everything the encoder needs to
know about the input pictures and the output bitstream and most
everything in between.</p>
<p>The recommended way to handle these param structures is to allocate them
from libx265 via:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_param_alloc:
 *  Allocates an x265_param instance. The returned param structure is not
 *  special in any way, but using this method together with x265_param_free()
 *  and x265_param_parse() to set values by name allows the application to treat
 *  x265_param as an opaque data struct for version safety */
x265_param *x265_param_alloc();
</pre></div>
</div>
<p>In this way, your application does not need to know the exact size of
the param structure (the build of x265 could potentially be a bit newer
than the copy of <code class="file docutils literal"><span class="pre">x265.h</span></code> that your application compiled against).</p>
<p>Next you perform the initial <em>rough cut</em> configuration of the encoder by
chosing a performance preset and optional tune factor
<strong>x265_preset_names</strong> and <strong>x265_tune_names</strong> respectively hold the
string names of the presets and tune factors (see <span class="xref std std-ref">presets</span> for more detail on presets and tune factors):</p>
<div class="highlight-python"><div class="highlight"><pre>/*      returns 0 on success, negative on failure (e.g. invalid preset/tune name). */
int x265_param_default_preset(x265_param *, const char *preset, const char *tune);
</pre></div>
</div>
<p>Now you may optionally specify a profile. <strong>x265_profile_names</strong>
contains the string names this function accepts:</p>
<div class="highlight-python"><div class="highlight"><pre>/*      (can be NULL, in which case the function will do nothing)
 *      returns 0 on success, negative on failure (e.g. invalid profile name). */
int x265_param_apply_profile(x265_param *, const char *profile);
</pre></div>
</div>
<p>Finally you configure any remaining options by name using repeated calls to:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_param_parse:
 *  set one parameter by name.
 *  returns 0 on success, or returns one of the following errors.
 *  note: BAD_VALUE occurs only if it can&#39;t even parse the value,
 *  numerical range is not checked until x265_encoder_open().
 *  value=NULL means &quot;true&quot; for boolean options, but is a BAD_VALUE for non-booleans. */
#define X265_PARAM_BAD_NAME  (-1)
#define X265_PARAM_BAD_VALUE (-2)
int x265_param_parse(x265_param *p, const char *name, const char *value);
</pre></div>
</div>
<p>See <a class="reference internal" href="cli.html#string-options-ref"><span>string options</span></a> for the list of options (and their
descriptions) which can be set by <strong>x265_param_parse()</strong>.</p>
<p>After the encoder has been created, you may release the param structure:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_param_free:
 *  Use x265_param_free() to release storage for an x265_param instance
 *  allocated by x265_param_alloc() */
void x265_param_free(x265_param *);
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Using these methods to allocate and release the param structures
helps future-proof your code in many ways, but the x265 API is
versioned in such a way that we prevent linkage against a build of
x265 that does not match the version of the header you are compiling
against (unless you use x265_api_query() to acquire the library&#8217;s
interfaces). This is function of the X265_BUILD macro.</p>
</div>
<p><strong>x265_encoder_parameters()</strong> may be used to get a copy of the param
structure from the encoder after it has been opened, in order to see the
changes made to the parameters for auto-detection and other reasons:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_encoder_parameters:
 *      copies the current internal set of parameters to the pointer provided
 *      by the caller.  useful when the calling application needs to know
 *      how x265_encoder_open has changed the parameters.
 *      note that the data accessible through pointers in the returned param struct
 *      (e.g. filenames) should not be modified by the calling application. */
void x265_encoder_parameters(x265_encoder *, x265_param *);
</pre></div>
</div>
<p><strong>x265_encoder_reconfig()</strong> may be used to reconfigure encoder parameters mid-encode:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_encoder_reconfig:
 *       used to modify encoder parameters.
 *      various parameters from x265_param are copied.
 *      this takes effect immediately, on whichever frame is encoded next;
 *      returns 0 on success, negative on parameter validation error.
 *
 *      not all parameters can be changed; see the actual function for a
 *      detailed breakdown.  since not all parameters can be changed, moving
 *      from preset to preset may not always fully copy all relevant parameters,
 *      but should still work usably in practice. however, more so than for
 *      other presets, many of the speed shortcuts used in ultrafast cannot be
 *      switched out of; using reconfig to switch between ultrafast and other
 *      presets is not recommended without a more fine-grained breakdown of
 *      parameters to take this into account. */
int x265_encoder_reconfig(x265_encoder *, x265_param *);
</pre></div>
</div>
</div>
<div class="section" id="pictures">
<h2>Pictures<a class="headerlink" href="#pictures" title="Permalink to this headline"></a></h2>
<p>Raw pictures are passed to the encoder via the <strong>x265_picture</strong> structure.
Just like the param structure we recommend you allocate this structure
from the encoder to avoid potential size mismatches:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_picture_alloc:
 *  Allocates an x265_picture instance. The returned picture structure is not
 *  special in any way, but using this method together with x265_picture_free()
 *  and x265_picture_init() allows some version safety. New picture fields will
 *  always be added to the end of x265_picture */
x265_picture *x265_picture_alloc();
</pre></div>
</div>
<p>Regardless of whether you allocate your picture structure this way or
whether you simply declare it on the stack, your next step is to
initialize the structure via:</p>
<div class="highlight-python"><div class="highlight"><pre>/***
 * Initialize an x265_picture structure to default values. It sets the pixel
 * depth and color space to the encoder&#39;s internal values and sets the slice
 * type to auto - so the lookahead will determine slice type.
 */
void x265_picture_init(x265_param *param, x265_picture *pic);
</pre></div>
</div>
<p>x265 does not perform any color space conversions, so the raw picture&#8217;s
color space (chroma sampling) must match the color space specified in
the param structure used to allocate the encoder. <strong>x265_picture_init</strong>
initializes this field to the internal color space and it is best to
leave it unmodified.</p>
<p>The picture bit depth is initialized to be the encoder&#8217;s internal bit
depth but this value should be changed to the actual depth of the pixels
being passed into the encoder.  If the picture bit depth is more than 8,
the encoder assumes two bytes are used to represent each sample
(little-endian shorts).</p>
<p>The user is responsible for setting the plane pointers and plane strides
(in units of bytes, not pixels). The presentation time stamp (<strong>pts</strong>)
is optional, depending on whether you need accurate decode time stamps
(<strong>dts</strong>) on output.</p>
<p>If you wish to override the lookahead or rate control for a given
picture you may specify a slicetype other than X265_TYPE_AUTO, or a
forceQP value other than 0.</p>
<p>x265 does not modify the picture structure provided as input, so you may
reuse a single <strong>x265_picture</strong> for all pictures passed to a single
encoder, or even all pictures passed to multiple encoders.</p>
<p>Structures allocated from the library should eventually be released:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_picture_free:
 *  Use x265_picture_free() to release storage for an x265_picture instance
 *  allocated by x265_picture_alloc() */
void x265_picture_free(x265_picture *);
</pre></div>
</div>
</div>
<div class="section" id="analysis-buffers">
<h2>Analysis Buffers<a class="headerlink" href="#analysis-buffers" title="Permalink to this headline"></a></h2>
<p>Analysis information can be saved and reused to between encodes of the
same video sequence (generally for multiple bitrate encodes).  The best
results are attained by saving the analysis information of the highest
bitrate encode and reuse it in lower bitrate encodes.</p>
<p>When saving or loading analysis data, buffers must be allocated for
every picture passed into the encoder using:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_alloc_analysis_data:
 *  Allocate memory to hold analysis meta data, returns 1 on success else 0 */
int x265_alloc_analysis_data(x265_picture*);
</pre></div>
</div>
<p>Note that this is very different from the typical semantics of
<strong>x265_picture</strong>, which can be reused many times. The analysis buffers must
be re-allocated for every input picture.</p>
<p>Analysis buffers passed to the encoder are owned by the encoder until
they pass the buffers back via an output <strong>x265_picture</strong>. The user is
responsible for releasing the buffers when they are finished with them
via:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_free_analysis_data:
 *  Use x265_free_analysis_data to release storage of members allocated by
 *  x265_alloc_analysis_data */
void x265_free_analysis_data(x265_picture*);
</pre></div>
</div>
</div>
<div class="section" id="encode-process">
<h2>Encode Process<a class="headerlink" href="#encode-process" title="Permalink to this headline"></a></h2>
<p>The output of the encoder is a series of NAL packets, which are always
returned concatenated in consecutive memory. HEVC streams have SPS and
PPS and VPS headers which describe how the following packets are to be
decoded. If you specified <a class="reference internal" href="cli.html#cmdoption--repeat-headers"><code class="xref std std-option docutils literal"><span class="pre">--repeat-headers</span></code></a> then those headers
will be output with every keyframe.  Otherwise you must explicitly query
those headers using:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_encoder_headers:
 *      return the SPS and PPS that will be used for the whole stream.
 *      *pi_nal is the number of NAL units outputted in pp_nal.
 *      returns negative on error, total byte size of payload data on success
 *      the payloads of all output NALs are guaranteed to be sequential in memory. */
int x265_encoder_headers(x265_encoder *, x265_nal **pp_nal, uint32_t *pi_nal);
</pre></div>
</div>
<p>Now we get to the main encode loop. Raw input pictures are passed to the
encoder in display order via:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_encoder_encode:
 *      encode one picture.
 *      *pi_nal is the number of NAL units outputted in pp_nal.
 *      returns negative on error, zero if no NAL units returned.
 *      the payloads of all output NALs are guaranteed to be sequential in memory. */
int x265_encoder_encode(x265_encoder *encoder, x265_nal **pp_nal, uint32_t *pi_nal, x265_picture *pic_in, x265_picture *pic_out);
</pre></div>
</div>
<p>These pictures are queued up until the lookahead is full, and then the
frame encoders in turn are filled, and then finally you begin receiving
a output NALs (corresponding to a single output picture) with each input
picture you pass into the encoder.</p>
<p>Once the pipeline is completely full, <strong>x265_encoder_encode()</strong> will
block until the next output picture is complete.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Optionally, if the pointer of a second <strong>x265_picture</strong> structure is
provided, the encoder will fill it with data pertaining to the
output picture corresponding to the output NALs, including the
recontructed image, POC and decode timestamp. These pictures will be
in encode (or decode) order. The encoder will also write corresponding
frame encode statistics into <strong>x265_frame_stats</strong>.</p>
</div>
<p>When the last of the raw input pictures has been sent to the encoder,
<strong>x265_encoder_encode()</strong> must still be called repeatedly with a
<em>pic_in</em> argument of 0, indicating a pipeline flush, until the function
returns a value less than or equal to 0 (indicating the output bitstream
is complete).</p>
<p>At any time during this process, the application may query running
statistics from the encoder:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_encoder_get_stats:
 *       returns encoder statistics */
void x265_encoder_get_stats(x265_encoder *encoder, x265_stats *, uint32_t statsSizeBytes);
</pre></div>
</div>
</div>
<div class="section" id="cleanup">
<h2>Cleanup<a class="headerlink" href="#cleanup" title="Permalink to this headline"></a></h2>
<p>Finally, the encoder must be closed in order to free all of its
resources. An encoder that has been flushed cannot be restarted and
reused. Once <strong>x265_encoder_close()</strong> has been called, the encoder
handle must be discarded:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_encoder_close:
 *      close an encoder handler */
void x265_encoder_close(x265_encoder *);
</pre></div>
</div>
<p>When the application has completed all encodes, it should call
<strong>x265_cleanup()</strong> to free process global, particularly if a memory-leak
detection tool is being used. <strong>x265_cleanup()</strong> also resets the saved
CTU size so it will be possible to create a new encoder with a different
CTU size:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_cleanup:
 *     release library static allocations, reset configured CTU size */
void x265_cleanup(void);
</pre></div>
</div>
</div>
<div class="section" id="multi-library-interface">
<h2>Multi-library Interface<a class="headerlink" href="#multi-library-interface" title="Permalink to this headline"></a></h2>
<p>If your application might want to make a runtime bit-depth selection, it
will need to use one of these bit-depth introspection interfaces which
returns an API structure containing the public function entry points and
constants.</p>
<p>Instead of directly using all of the <strong>x265_</strong> methods documented above,
you query an x265_api structure from your libx265 and then use the
function pointers of the same name (minus the <strong>x265_</strong> prefix) within
that structure.  For instance <strong>x265_param_default()</strong> becomes
<strong>api-&gt;param_default()</strong>.</p>
<div class="section" id="x265-api-get">
<h3>x265_api_get<a class="headerlink" href="#x265-api-get" title="Permalink to this headline"></a></h3>
<p>The first bit-depth instrospecton method is x265_api_get(). It designed
for applications that might statically link with libx265, or will at
least be tied to a particular SONAME or API version:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_api_get:
 *   Retrieve the programming interface for a linked x265 library.
 *   May return NULL if no library is available that supports the
 *   requested bit depth. If bitDepth is 0, the function is guarunteed
 *   to return a non-NULL x265_api pointer from the system default
 *   libx265 */
const x265_api* x265_api_get(int bitDepth);
</pre></div>
</div>
<p>Like <strong>x265_encoder_encode()</strong>, this function has the build number
automatically appended to the function name via macros. This ties your
application to a particular binary API version of libx265 (the one you
compile against). If you attempt to link with a libx265 with a different
API version number, the link will fail.</p>
<p>Obviously this has no meaningful effect on applications which statically
link to libx265.</p>
</div>
<div class="section" id="x265-api-query">
<h3>x265_api_query<a class="headerlink" href="#x265-api-query" title="Permalink to this headline"></a></h3>
<p>The second bit-depth introspection method is designed for applications
which need more flexibility in API versioning.  If you use
<strong>x265_api_query()</strong> and dynamically link to libx265 at runtime (using
dlopen() on POSIX or LoadLibrary() on Windows) your application is no
longer directly tied to the API version that it was compiled against:</p>
<div class="highlight-python"><div class="highlight"><pre>/* x265_api_query:
 *   Retrieve the programming interface for a linked x265 library, like
 *   x265_api_get(), except this function accepts X265_BUILD as the second
 *   argument rather than using the build number as part of the function name.
 *   Applications which dynamically link to libx265 can use this interface to
 *   query the library API and achieve a relative amount of version skew
 *   flexibility. The function may return NULL if the library determines that
 *   the apiVersion that your application was compiled against is not compatible
 *   with the library you have linked with.
 *
 *   api_major_version will be incremented any time non-backward compatible
 *   changes are made to any public structures or functions. If
 *   api_major_version does not match X265_MAJOR_VERSION from the x265.h your
 *   application compiled against, your application must not use the returned
 *   x265_api pointer.
 *
 *   Users of this API *must* also validate the sizes of any structures which
 *   are not treated as opaque in application code. For instance, if your
 *   application dereferences a x265_param pointer, then it must check that
 *   api-&gt;sizeof_param matches the sizeof(x265_param) that your application
 *   compiled with. */
const x265_api* x265_api_query(int bitDepth, int apiVersion, int* err);
</pre></div>
</div>
<p>A number of validations must be performed on the returned API structure
in order to determine if it is safe for use by your application. If you
do not perform these checks, your application is liable to crash:</p>
<div class="highlight-python"><div class="highlight"><pre>if (api-&gt;api_major_version != X265_MAJOR_VERSION) /* do not use */
if (api-&gt;sizeof_param != sizeof(x265_param))      /* do not use */
if (api-&gt;sizeof_picture != sizeof(x265_picture))  /* do not use */
if (api-&gt;sizeof_stats != sizeof(x265_stats))      /* do not use */
if (api-&gt;sizeof_zone != sizeof(x265_zone))        /* do not use */
etc.
</pre></div>
</div>
<p>Note that if your application does not directly allocate or dereference
one of these structures, if it treats the structure as opaque or does
not use it at all, then it can skip the size check for that structure.</p>
<p>In particular, if your application uses api-&gt;param_alloc(),
api-&gt;param_free(), api-&gt;param_parse(), etc and never directly accesses
any x265_param fields, then it can skip the check on the
sizeof(x265_parm) and thereby ignore changes to that structure (which
account for a large percentage of X265_BUILD bumps).</p>
</div>
<div class="section" id="build-implications">
<h3>Build Implications<a class="headerlink" href="#build-implications" title="Permalink to this headline"></a></h3>
<p>By default libx265 will place all of its internal C++ classes and
functions within an x265 namespace and export all of the C functions
documented in this file. Obviously this prevents 8bit and 10bit builds
of libx265 from being statically linked into a single binary, all of
those symbols would collide.</p>
<p>However, if you set the EXPORT_C_API cmake option to OFF then libx265
will use a bit-depth specific namespace and prefix for its assembly
functions (x265_8bit, x265_10bit or x265_12bit) and export no C
functions.</p>
<p>In this way you can build one or more libx265 libraries without any
exported C interface and link them into a libx265 build that does export
a C interface. The build which exported the C functions becomes the
<em>default</em> bit depth for the combined library, and the other bit depths
are available via the bit-depth introspection methods.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">When setting EXPORT_C_API cmake option to OFF, it is recommended to
also set ENABLE_SHARED and ENABLE_CLI to OFF to prevent build
problems.  We only need the static library from these builds.</p>
</div>
<p>If an application requests a bit-depth that is not supported by the
default library or any of the additionally linked libraries, the
introspection method will fall-back to an attempt to dynamically bind a
shared library with a name appropriate for the requested bit-depth:</p>
<div class="highlight-python"><div class="highlight"><pre>8-bit:  libx265_main
10-bit: libx265_main10
12-bit: libx265_main12
</pre></div>
</div>
<p>If the profile-named library is not found, it will then try to bind a
generic libx265 in the hopes that it is a multilib library with all bit
depths.</p>
</div>
<div class="section" id="packaging-and-distribution">
<h3>Packaging and Distribution<a class="headerlink" href="#packaging-and-distribution" title="Permalink to this headline"></a></h3>
<p>We recommend that packagers distribute a single combined shared/static
library build which includes all the bit depth libraries linked
together. See the multilib scripts in our <code class="file docutils literal"><span class="pre">build/</span></code> subdirectories
for examples of how to affect these combined library builds. It is the
packager&#8217;s discretion which bit-depth exports the public C functions and
thus becomes the default bit-depth for the combined library.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Windows packagers might want to build libx265 with WINXP_SUPPORT
enabled. This makes the resulting binaries functional on XP and
Vista. Without this flag, the minimum supported host O/S is Windows
7. Also note that binaries built with WINXP_SUPPORT will <em>not</em> have
NUMA support and they will have slightly less performance.</p>
<p class="last">STATIC_LINK_CRT is also recommended so end-users will not need to
install any additional MSVC C runtime libraries.</p>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Application Programming Interface</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a></li>
<li><a class="reference internal" href="#build-considerations">Build Considerations</a></li>
<li><a class="reference internal" href="#encoder">Encoder</a></li>
<li><a class="reference internal" href="#param">Param</a></li>
<li><a class="reference internal" href="#pictures">Pictures</a></li>
<li><a class="reference internal" href="#analysis-buffers">Analysis Buffers</a></li>
<li><a class="reference internal" href="#encode-process">Encode Process</a></li>
<li><a class="reference internal" href="#cleanup">Cleanup</a></li>
<li><a class="reference internal" href="#multi-library-interface">Multi-library Interface</a><ul>
<li><a class="reference internal" href="#x265-api-get">x265_api_get</a></li>
<li><a class="reference internal" href="#x265-api-query">x265_api_query</a></li>
<li><a class="reference internal" href="#build-implications">Build Implications</a></li>
<li><a class="reference internal" href="#packaging-and-distribution">Packaging and Distribution</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="cli.html"
                        title="previous chapter">Command Line Options</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="threading.html"
                        title="next chapter">Threading</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/api.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="threading.html" title="Threading"
             >next</a> |</li>
        <li class="right" >
          <a href="cli.html" title="Command Line Options"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">x265  documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &copy; Copyright 2014 MulticoreWare Inc.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
    </div>
  </body>
</html>