//----------------------------------------------------------------------------
//
// TSDuck - The MPEG Transport Stream Toolkit
// Copyright (c) 2005-2025, Thierry Lelegard
// BSD-2-Clause license, see LICENSE.txt file or https://tsduck.io/license
//
//----------------------------------------------------------------------------

<<<
=== tspacketize

[.cmd-header]
Packetize PSI/SI tables in a transport stream PID

This utility packetizes PSI/SI tables in a transport stream PID.

[.usage]
Usage

[source,shell]
----
$ tspacketize [options] [input-file[=rate] ...]
----

[.usage]
Parameters

[.opt]
_input-file[=rate]_

[.optdoc]
Binary, XML or JSON files containing one or more sections or tables.
By default, files with a name ending in `.bin`, `.xml` or `.json` are automatically recognized.
For other file names, explicitly specify `--binary` or `--xml` or `--json`.

[.optdoc]
If the file name is omitted, the standard input is used (binary by default, specify `--xml` or `--json` otherwise).

[.optdoc]
The reference source format is XML.
JSON files are first translated to XML using the "automated XML-to-JSON conversion" rules of TSDuck
(see xref:xml-json-conv[xrefstyle=short]) and then compiled to binary.

[.optdoc]
If different repetition rates are required for different files, a parameter can be `_filename=value_`
where `_value_` is the repetition rate in milliseconds for all sections in that file.
For repetition rates to be effective, the bitrate of the target PID must be specified, see option `--bitrate`.

[.optdoc]
If an input file name starts with `<?xml`, it is considered as _inline XML content_.
Similarly, if an input file name starts with `{` or `[`, it is considered as _inline JSON content_.
In these two cases, it is not possible to specify a specific repetition rate for this XML or JSON content.

[.usage]
Options

[.opt]
*--binary*

[.optdoc]
Specify that all input files are binary, regardless of their file name.

[.opt]
*-b* _value_ +
*--bitrate* _value_

[.optdoc]
Specifies the bitrate (in bits/second) of the target PID.

[.optdoc]
See xref:bitrates[xrefstyle=short] for more details on the representation of bitrates.

[.optdoc]
This information is used to schedule sections in the output list of packets when specific bitrates are specified for sections.
When no specific bitrate is specified for any input file, this option is ignored.

[.opt]
*-c* +
*--continuous*

[.optdoc]
Continuous packetization.
By default, generate one cycle of sections.

[.opt]
*-f* +
*--force-crc*

[.optdoc]
Force recomputation of CRC32 in long sections.
Ignore the CRC32 values in the input files.
By default, the CRC32 of every section is verified and sections with wrong CRC32 are rejected.

[.opt]
*-j* +
*--json*

[.optdoc]
Specify that all input files are JSON, regardless of their file name.

[.opt]
*-o* _file-name_ +
*--output* _file-name_

[.optdoc]
Output file name for TS packets. By default, use standard output.

[.opt]
*-p* _value_ +
*--pid* _value_

[.optdoc]
PID of the output TS packets.
This is a required parameter, there is no default value.

[.opt]
*-s* +
*--stuffing*

[.optdoc]
Insert stuffing at end of each section, up to the next TS packet boundary.
By default, sections are packed and start in the middle of a TS packet, after the previous section.
Note, however, that section headers are never scattered over a packet boundary.

[.opt]
*-x* +
*--xml*

[.optdoc]
Specify that all input files are XML, regardless of their file name.

include::{docdir}/opt/group-section-file.adoc[tags=!*]
include::{docdir}/opt/group-duck-context.adoc[tags=!*;charset]
include::{docdir}/opt/group-common-commands.adoc[tags=!*]
