Go to the documentation of this file.
45 #define PCR_TIME_BASE 27000000
49 #define DVB_PRIVATE_NETWORK_START 0xff01
115 #define MPEGTS_FLAG_REEMIT_PAT_PMT 0x01
116 #define MPEGTS_FLAG_AAC_LATM 0x02
117 #define MPEGTS_FLAG_PAT_PMT_AT_FRAMES 0x04
118 #define MPEGTS_FLAG_SYSTEM_B 0x08
119 #define MPEGTS_FLAG_DISCONT 0x10
120 #define MPEGTS_FLAG_NIT 0x20
121 #define MPEGTS_FLAG_OMIT_RAI 0x40
138 #define DEFAULT_PES_HEADER_FREQ 16
139 #define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
143 #define SECTION_LENGTH 1020
150 const unsigned char *buf_ptr;
157 buf[
len - 4] = (crc >> 24) & 0xff;
158 buf[
len - 3] = (crc >> 16) & 0xff;
159 buf[
len - 2] = (crc >> 8) & 0xff;
160 buf[
len - 1] = crc & 0xff;
165 first = buf == buf_ptr;
173 s->cc =
s->cc + 1 & 0xf;
175 if (
s->discontinuity) {
179 s->discontinuity = 0;
186 memcpy(q, buf_ptr, len1);
193 s->write_packet(
s, packet);
210 int version,
int sec_num,
int last_sec_num,
211 uint8_t *buf,
int len)
213 uint8_t section[1024], *q;
214 unsigned int tot_len;
218 tot_len = 3 + 5 +
len + 4;
239 #define DEFAULT_PROVIDER_NAME "FFmpeg"
240 #define DEFAULT_SERVICE_NAME "Service"
243 #define SDT_RETRANS_TIME 500
244 #define PAT_RETRANS_TIME 100
245 #define PCR_RETRANS_TIME 20
246 #define NIT_RETRANS_TIME 500
293 static void putbuf(uint8_t **q_ptr,
const uint8_t *buf,
size_t len)
295 memcpy(*q_ptr, buf,
len);
302 uint8_t stream_identifier;
303 uint16_t data_component_id;
308 stream_identifier = 0x30;
309 data_component_id = 0x0008;
312 stream_identifier = 0x87;
313 data_component_id = 0x0012;
317 "Unset/unknown ARIB caption profile %d utilized!\n",
325 *q++ = stream_identifier;
330 put16(&q, data_component_id);
449 "Stream %d, codec %s, is muxed as a private data stream "
450 "and may not be recognized upon reading.\n", st->
index,
502 "Stream %d, codec %s, is muxed as a private data stream "
503 "and may not be recognized upon reading.\n", st->
index,
516 int val, stream_type,
i, err = 0;
521 program_info_length_ptr = q;
534 val = 0xf000 | (q - program_info_length_ptr - 2);
535 program_info_length_ptr[0] =
val >> 8;
536 program_info_length_ptr[1] =
val;
538 for (
i = 0;
i <
s->nb_streams;
i++) {
542 const char default_language[] =
"und";
543 const char *
language = lang && strlen(lang->
value) >= 3 ? lang->
value : default_language;
546 if (
s->nb_programs) {
550 for (k = 0; k <
program->nb_stream_indexes; k++)
551 if (
program->stream_index[k] ==
i) {
632 static const uint8_t coupled_stream_counts[9] = {
633 1, 0, 1, 1, 2, 2, 2, 3, 3
635 static const uint8_t channel_map_a[8][8] = {
642 {0, 4, 1, 2, 3, 5, 6},
643 {0, 6, 1, 2, 3, 4, 5, 7},
645 static const uint8_t channel_map_b[8][8] = {
652 {0, 1, 2, 3, 4, 5, 6},
653 {0, 1, 2, 3, 4, 5, 6, 7},
675 }
else if (ch <= 2) {
689 const char *
p, *next;
696 for (
p = next =
language; next && *len_ptr < 255 / 4 * 4;
p = next + 1) {
701 next = strchr(
p,
',');
702 if (strlen(
p) != 3 && (!next || next !=
p + 3))
728 int extradata_copied = 0;
734 if (
sizeof(
data) - (q -
data) < 8) {
748 extradata_copied += 5;
758 extradata_copied += 4;
767 *len_ptr = q - len_ptr - 1;
769 uint8_t *len_ptr =
NULL;
770 int extradata_copied = 0;
786 extradata_copied += 2;
798 *len_ptr = q - len_ptr - 1;
822 const char *
tag =
"ID3 ";
835 val = 0xf000 | (q - desc_length_ptr - 2);
836 desc_length_ptr[0] =
val >> 8;
837 desc_length_ptr[1] =
val;
842 "The PMT section cannot fit stream %d and all following streams.\n"
843 "Try reducing the number of languages in the audio streams "
844 "or the total number of streams.\n",
i);
856 int i, running_status, free_ca_mode,
val;
865 desc_list_len_ptr = q;
877 desc_len_ptr[0] = q - desc_len_ptr - 1;
880 val = (running_status << 13) | (free_ca_mode << 12) |
881 (q - desc_list_len_ptr - 2);
882 desc_list_len_ptr[0] =
val >> 8;
883 desc_list_len_ptr[1] =
val;
923 put16(&desc_len_ptr, 0xf000 | q - (desc_len_ptr + 2));
924 put16(&loop_len_ptr, 0xf000 | q - (loop_len_ptr + 2));
939 str_len = strlen(str);
940 if (str[0] && (
unsigned)str[0] >= 0x20) {
941 const uint8_t *q = str;
942 int has_multibyte = 0;
946 has_multibyte |= (
code > 127);
951 buf[0] = str_len + 1;
953 memcpy(&buf[2], str, str_len);
962 memcpy(&buf[1], str, str_len);
977 uint32_t tp_extra_header = pcr % 0x3fffffff;
978 tp_extra_header =
AV_RB32(&tp_extra_header);
979 avio_write(
s->pb, (
unsigned char *) &tp_extra_header,
980 sizeof(tp_extra_header));
999 char default_service_name[32];
1000 const char *service_name;
1001 const char *provider_name;
1007 service_name = title ? title->
value : default_service_name;
1031 service->
pmt.
cc = 15;
1105 const char *provider_name;
1124 if (
s->nb_programs > 1) {
1130 if (
s->max_delay < 0)
1138 if (!
s->nb_programs) {
1143 for (
i = 0;
i <
s->nb_programs;
i++) {
1173 for (
i = 0;
i <
s->nb_streams;
i++) {
1224 ts_st->
pid = st->
id;
1226 if (ts_st->
pid >= 0x1FFF) {
1228 "Invalid stream id %d, must be less than 8191\n", st->
id);
1242 for (j = 0; j <
i; j++) {
1244 if (ts_st_prev->
pid == ts_st->
pid) {
1307 "sdt every %"PRId64
" ms, pat/pmt every %"PRId64
" ms",
1355 *buf++ = pcr_high >> 25;
1356 *buf++ = pcr_high >> 17;
1357 *buf++ = pcr_high >> 9;
1358 *buf++ = pcr_high >> 1;
1359 *buf++ = pcr_high << 7 | pcr_low >> 8 | 0x7e;
1390 *q++ = ts_st->
pid >> 8;
1392 *q++ = 0x20 | ts_st->
cc;
1413 val = fourbits << 4 | (((
pts >> 30) & 0x07) << 1) | 1;
1415 val = (((
pts >> 15) & 0x7fff) << 1) | 1;
1418 val = (((
pts) & 0x7fff) << 1) | 1;
1429 if ((
pkt[3] & 0x20) == 0) {
1492 const uint8_t *payload,
int payload_size,
1499 int val, is_start,
len, header_len, write_pcr,
flags;
1500 int afc_len, stuffing_len;
1521 while (payload_size > 0) {
1539 for (
int i = 0;
i <
s->nb_streams;
i++) {
1542 int st2_index =
i < st->
index ?
i : (
i + 1 ==
s->nb_streams ? st->
index :
i + 1);
1586 ts_st->
cc = ts_st->
cc + 1 & 0xf;
1587 *q++ = 0x10 | ts_st->
cc;
1595 !is_dvb_teletext ) {
1612 int pes_extension = 0;
1613 int pes_header_stuffing_bytes = 0;
1665 if (is_dvb_teletext) {
1666 pes_header_stuffing_bytes = 0x24 - header_len;
1669 len = payload_size + header_len + 3;
1671 if (is_dvb_subtitle) {
1716 if (is_dvb_subtitle) {
1723 if (is_dvb_teletext) {
1725 q += pes_header_stuffing_bytes;
1735 header_len = q - buf;
1738 if (
len > payload_size)
1741 if (stuffing_len > 0) {
1743 if (buf[3] & 0x20) {
1745 afc_len = buf[4] + 1;
1746 memmove(buf + 4 + afc_len + stuffing_len,
1748 header_len - (4 + afc_len));
1749 buf[4] += stuffing_len;
1753 memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4);
1755 buf[4] = stuffing_len - 1;
1756 if (stuffing_len >= 2) {
1763 if (is_dvb_subtitle && payload_size ==
len) {
1771 payload_size -=
len;
1782 "no startcode found, use the video bitstream filter '%s_mp4toannexb' to fix it "
1783 "('-bsf:v %s_mp4toannexb' option with ffmpeg)\n", codec, codec, codec);
1805 static const int durations[32] = {
1806 480, 960, 1920, 2880,
1807 480, 960, 1920, 2880,
1808 480, 960, 1920, 2880,
1816 int toc, frame_duration, nframes,
duration;
1823 frame_duration = durations[toc >> 3];
1841 duration = nframes * frame_duration;
1844 "Opus packet duration > 120 ms, invalid");
1852 const uint8_t *extra_data,
const int extra_size,
AVPacket *
pkt,
int *
size)
1859 memcpy(
data + sz,
aud, aud_size);
1860 memcpy(
data + sz + aud_size, extra_data, extra_size);
1866 #define H264_NAL_TYPE(state) (state & 0x1f)
1867 #define HEVC_NAL_TYPE(state) ((state & 0x7e) >> 1)
1868 #define VVC_NAL_TYPE(state) ((state >> 11) & 0x1f)
1873 const uint8_t *buf =
pkt->
data;
1880 int opus_samples = 0;
1881 size_t side_data_size;
1882 uint8_t *side_data =
NULL;
1889 stream_id = side_data[0];
1910 const uint8_t *
p = buf, *buf_end =
p +
size;
1911 const uint8_t *found_aud =
NULL, *found_aud_end =
NULL;
1913 uint32_t
state = -1;
1933 found_aud_end =
p + 1;
1934 if (found_aud < buf)
1936 if (buf_end < found_aud_end)
1937 found_aud_end = buf_end;
1939 }
while (
p < buf_end
1942 && (extradd > 0 || !found_aud));
1948 const uint8_t
aud[] = {
1956 }
else if (extradd != 0) {
1960 const int new_pkt_size =
pkt->
size + 1 + extradd;
1965 bytestream2_put_byte(&pb, 0x00);
1972 size = new_pkt_size;
1985 "and extradata missing\n");
2008 const uint8_t *
p = buf, *buf_end =
p +
size;
2009 uint32_t
state = -1;
2025 }
while (p < buf_end && nal_type != HEVC_NAL_AUD && nal_type >=
HEVC_NAL_VPS);
2030 const uint8_t
aud[] = {
2041 const uint8_t *
p = buf, *buf_end =
p +
size;
2042 uint32_t
state = -1;
2043 uint32_t nal_type = -1;
2059 }
while (p < buf_end && nal_type != VVC_AUD_NUT && nal_type >=
VVC_OPI_NUT);
2064 const uint8_t
aud[] = {
2082 size_t side_data_size;
2084 int ctrl_header_size;
2085 int trim_start = 0, trim_end = 0;
2093 if (side_data && side_data_size >= 10) {
2099 ctrl_header_size += 2;
2101 ctrl_header_size += 2;
2131 trim_end =
FFMIN(trim_end, opus_samples - trim_start);
2138 size = ctrl_header_size;
2148 uint8_t number_of_channels_flag;
2149 uint8_t service_type_flag;
2150 uint8_t full_service_flag = 1;
2153 dvb_ac3_desc =
av_mallocz(
sizeof(*dvb_ac3_desc));
2154 if (!dvb_ac3_desc) {
2162 number_of_channels_flag = 1;
2165 number_of_channels_flag = 0;
2169 number_of_channels_flag = 3;
2171 number_of_channels_flag = 2;
2178 number_of_channels_flag = 4;
2181 number_of_channels_flag = 7;
2185 if (service_type_flag == 1 || service_type_flag == 4 ||
2186 (service_type_flag == 7 && !number_of_channels_flag))
2187 full_service_flag = 0;
2191 ((service_type_flag & 0x7) << 3) |
2192 (number_of_channels_flag & 0x7);
2249 for (
i = 0;
i <
s->nb_streams;
i++) {
2263 while (packets++ < 32)
2292 for (
i = 0;
i <
s->nb_streams;
i++) {
2315 const struct Entry {
2317 const char *bsf_name;
2327 const struct Entry *e =
list +
i;
2338 #define OFFSET(x) offsetof(MpegTSWrite, x)
2339 #define ENC AV_OPT_FLAG_ENCODING_PARAM
2341 {
"mpegts_transport_stream_id",
"Set transport_stream_id field.",
2343 {
"mpegts_original_network_id",
"Set original_network_id field.",
2345 {
"mpegts_service_id",
"Set service_id field.",
2347 {
"mpegts_service_type",
"Set service_type field.",
2349 {
"digital_tv",
"Digital Television.",
2351 {
"digital_radio",
"Digital Radio.",
2353 {
"teletext",
"Teletext.",
2355 {
"advanced_codec_digital_radio",
"Advanced Codec Digital Radio.",
2357 {
"mpeg2_digital_hdtv",
"MPEG2 Digital HDTV.",
2359 {
"advanced_codec_digital_sdtv",
"Advanced Codec Digital SDTV.",
2361 {
"advanced_codec_digital_hdtv",
"Advanced Codec Digital HDTV.",
2363 {
"hevc_digital_hdtv",
"HEVC Digital Television Service.",
2365 {
"mpegts_pmt_start_pid",
"Set the first pid of the PMT.",
2367 {
"mpegts_start_pid",
"Set the first pid.",
2371 {
"pes_payload_size",
"Minimum PES packet payload in bytes",
2374 {
"resend_headers",
"Reemit PAT/PMT before writing the next packet",
2376 {
"latm",
"Use LATM packetization for AAC",
2378 {
"pat_pmt_at_frames",
"Reemit PAT and PMT at each video frame",
2380 {
"system_b",
"Conform to System B (DVB) instead of System A (ATSC)",
2382 {
"initial_discontinuity",
"Mark initial packets as discontinuous",
2384 {
"nit",
"Enable NIT transmission",
2386 {
"omit_rai",
"Disable writing of random access indicator",
2389 {
"tables_version",
"set PAT, PMT, SDT and NIT version",
OFFSET(tables_version),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 31,
ENC },
2390 {
"omit_video_pes_length",
"Omit the PES packet length for video packets",
2392 {
"pcr_period",
"PCR retransmission time in milliseconds",
2394 {
"pat_period",
"PAT/PMT retransmission time limit in seconds",
2396 {
"sdt_period",
"SDT retransmission time limit in seconds",
2398 {
"nit_period",
"NIT retransmission time limit in seconds",
2413 .p.mime_type =
"video/MP2T",
2414 .p.extensions =
"ts,m2t,m2ts,mts",
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
@ AV_ROUND_UP
Round toward +infinity.
#define DEFAULT_PROVIDER_NAME
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_PROFILE_KLVA_SYNC
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C program
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define MPEGTS_FLAG_AAC_LATM
#define SYSTEM_CLOCK_FREQUENCY_DIVISOR
enum AVMediaType codec_type
General type of the encoded data.
uint8_t provider_name[256]
static void section_write_packet(MpegTSSection *s, const uint8_t *packet)
static uint8_t * h26x_prefix_aud(const uint8_t *aud, const int aud_size, const uint8_t *extra_data, const int extra_size, AVPacket *pkt, int *size)
#define STREAM_TYPE_AUDIO_AAC
This struct describes the properties of an encoded stream.
static int check_h26x_startcode(AVFormatContext *s, const AVStream *st, const AVPacket *pkt, const char *codec)
#define STREAM_TYPE_VIDEO_VC1
#define STREAM_TYPE_PRIVATE_DATA
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
static void mpegts_write_flush(AVFormatContext *s)
#define STREAM_ID_EMM_STREAM
#define HEVC_NAL_TYPE(state)
#define STREAM_ID_PADDING_STREAM
int first_timestamp_checked
first pts/dts check needed
#define STREAM_ID_PROGRAM_STREAM_MAP
#define M2TS_AUDIO_START_PID
static void set_af_flag(uint8_t *pkt, int flag)
#define STREAM_TYPE_AUDIO_MPEG1
AVStream ** streams
A list of all streams in the file.
static void mpegts_deinit(AVFormatContext *s)
#define STREAM_TYPE_VIDEO_VVC
@ AV_CODEC_ID_DVB_TELETEXT
AVRational avg_frame_rate
Average framerate.
static int64_t get_pcr(const MpegTSWrite *ts)
static int mpegts_check_bitstream(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
#define DVB_EXTENSION_DESCRIPTOR
#define AV_LOG_VERBOSE
Detailed information.
#define MPEGTS_FLAG_PAT_PMT_AT_FRAMES
#define AV_PROFILE_ARIB_PROFILE_C
int nb_channels
Number of channels in this layout.
@ AV_CODEC_ID_HDMV_PGS_SUBTITLE
static int opus_get_packet_samples(AVFormatContext *s, AVPacket *pkt)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static int mpegts_write_end(AVFormatContext *s)
@ MPEGTS_SERVICE_TYPE_TELETEXT
#define ENHANCED_AC3_DESCRIPTOR
#define STREAM_TYPE_AUDIO_MPEG2
static void put_registration_descriptor(uint8_t **q_ptr, uint32_t tag)
#define NETWORK_NAME_DESCRIPTOR
static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
#define AV_PROFILE_ARIB_PROFILE_A
#define METADATA_DESCRIPTOR
#define REGISTRATION_DESCRIPTOR
static void mpegts_write_pes(AVFormatContext *s, AVStream *st, const uint8_t *payload, int payload_size, int64_t pts, int64_t dts, int key, int stream_id)
#define STREAM_TYPE_VIDEO_AVS2
#define STREAM_TYPE_VIDEO_AVS3
#define STREAM_ID_DSMCC_STREAM
static int get_m2ts_stream_type(AVFormatContext *s, AVStream *st)
#define STREAM_TYPE_ATSC_AUDIO_EAC3
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static int get_dvb_stream_type(AVFormatContext *s, AVStream *st)
static double val(void *priv, double ch)
void(* write_packet)(struct MpegTSSection *s, const uint8_t *packet)
#define DEFAULT_SERVICE_NAME
@ MPEGTS_SERVICE_TYPE_DIGITAL_RADIO
#define H264_NAL_TYPE(state)
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
uint8_t provider_name[256]
#define STREAM_ID_METADATA_STREAM
@ AV_CODEC_ID_DVB_SUBTITLE
#define GET_UTF8(val, GET_BYTE, ERROR)
Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
#define SUBTITLING_DESCRIPTOR
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define STREAM_TYPE_BLURAY_AUDIO_AC3
#define FF_ARRAY_ELEMS(a)
static void select_pcr_streams(AVFormatContext *s)
#define STREAM_ID_EXTENDED_STREAM_ID
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static int write_pcr_bits(uint8_t *buf, int64_t pcr)
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define STREAM_TYPE_VIDEO_MPEG4
#define MPEGTS_FLAG_SYSTEM_B
@ MPEGTS_SERVICE_TYPE_HEVC_DIGITAL_HDTV
#define TELETEXT_DESCRIPTOR
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
int av_match_ext(const char *filename, const char *extensions)
Return a positive value if the given filename has one of the given extensions, 0 otherwise.
#define STREAM_TYPE_BLURAY_AUDIO_TRUEHD
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const AVOption options[]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static AVFormatContext * ctx
#define STREAM_ID_TYPE_E_STREAM
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static int mpegts_init(AVFormatContext *s)
static void extend_af(uint8_t *pkt, int size)
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
uint8_t component_type_flag
av_warn_unused_result int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
@ AV_CODEC_ID_ARIB_CAPTION
static void retransmit_si_info(AVFormatContext *s, int force_pat, int force_sdt, int force_nit, int64_t pcr)
static void mpegts_insert_null_packet(AVFormatContext *s)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
#define STREAM_TYPE_ATSC_AUDIO_AC3
@ MPEGTS_SERVICE_TYPE_MPEG2_DIGITAL_HDTV
static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len)
#define STREAM_ID_PRIVATE_STREAM_1
const char * av_default_item_name(void *ptr)
Return the context name.
AVIOContext * pb
I/O context.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
#define M2TS_PGSSUB_START_PID
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
AVChannelLayout ch_layout
Audio only.
#define MPEGTS_FLAG_REEMIT_PAT_PMT
int sample_rate
Audio only.
int64_t nb_frames
number of frames in this stream if known or 0
AVCodecID
Identify the syntax and semantics of the bitstream.
int extradata_size
Size of the extradata content in bytes.
static void enable_pcr_generation_for_stream(AVFormatContext *s, AVStream *pcr_st)
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
@ MPEGTS_SERVICE_TYPE_DIGITAL_TV
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
#define FF_OFMT_FLAG_ALLOW_FLUSH
This flag indicates that the muxer stores data internally and supports flushing it.
#define SERVICE_LIST_DESCRIPTOR
#define STREAM_TYPE_VIDEO_HEVC
static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
#define VVC_NAL_TYPE(state)
static void mpegts_write_pat(AVFormatContext *s)
@ MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_HDTV
#define AV_NOPTS_VALUE
Undefined timestamp value.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
#define STREAM_ID_PRIVATE_STREAM_2
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
int profile
Codec-specific bitstream restrictions that the stream conforms to.
const FFOutputFormat ff_mpegts_muxer
static MpegTSService * mpegts_add_service(AVFormatContext *s, int sid, const AVDictionary *metadata, AVProgram *program)
#define STREAM_IDENTIFIER_DESCRIPTOR
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
#define FF_COMPLIANCE_NORMAL
#define STREAM_TYPE_VIDEO_MPEG2
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
MpegTSService ** services
static void write_packet(AVFormatContext *s, const uint8_t *packet)
int flags
A combination of AV_PKT_FLAG values.
#define STREAM_TYPE_AUDIO_AAC_LATM
#define DATA_COMPONENT_DESCRIPTOR
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
#define STREAM_TYPE_VIDEO_DIRAC
#define ISO_639_LANGUAGE_DESCRIPTOR
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
static void put16(uint8_t **q_ptr, int val)
static int mpegts_write_section1(MpegTSSection *s, int tid, int id, int version, int sec_num, int last_sec_num, uint8_t *buf, int len)
#define STREAM_TYPE_BLURAY_SUBTITLE_TEXT
#define AV_TIME_BASE
Internal time base represented as integer.
int avpriv_ac3_parse_header(AC3HeaderInfo **phdr, const uint8_t *buf, size_t size)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
static void putbuf(uint8_t **q_ptr, const uint8_t *buf, size_t len)
static void write_pts(uint8_t *q, int fourbits, int64_t pts)
@ AV_PKT_DATA_MPEGTS_STREAM_ID
MPEGTS stream ID as uint8_t, this is required to pass the stream ID information from the demuxer to t...
New fields can be added to the end with minor version bumps.
#define MPEGTS_FLAG_DISCONT
#define STREAM_TYPE_BLURAY_AUDIO_DTS_HD
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int opus_pending_trim_start
#define SERVICE_DESCRIPTOR
static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
Undefined Behavior In the C language
DVBAC3Descriptor * dvb_ac3_desc
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
#define STREAM_ID_VIDEO_STREAM_0
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
int id
Format-specific stream ID.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
const struct AVOutputFormat * oformat
The output container format.
void * av_malloc(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define STREAM_TYPE_BLURAY_AUDIO_EAC3
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
@ MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_RADIO
#define STREAM_TYPE_BLURAY_AUDIO_PCM_BLURAY
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
@ MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_SDTV
int index
stream index in AVFormatContext
#define STREAM_TYPE_VIDEO_H264
static void mpegts_write_sdt(AVFormatContext *s)
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
static void mpegts_write_nit(AVFormatContext *s)
@ AV_OPT_TYPE_INT
Underlying C type is int.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
#define STREAM_TYPE_VIDEO_CAVS
@ AV_PKT_DATA_SKIP_SAMPLES
Recommends skipping the specified number of samples.
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
static const AVClass mpegts_muxer_class
void av_log_once(void *avcl, int initial_level, int subsequent_level, int *state, const char *fmt,...)
const AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
#define STREAM_ID_AUDIO_STREAM_0
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
#define STREAM_TYPE_METADATA
#define STREAM_ID_ECM_STREAM
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define STREAM_ID_PROGRAM_STREAM_DIRECTORY
static int get_pes_stream_id(AVFormatContext *s, AVStream *st, int stream_id, int *async)
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
int omit_video_pes_length
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static uint8_t * get_ts_payload_start(uint8_t *pkt)
#define STREAM_TYPE_BLURAY_AUDIO_DTS
@ AV_CODEC_ID_HDMV_TEXT_SUBTITLE
static void mpegts_insert_pcr_only(AVFormatContext *s, AVStream *st)
#define MKTAG(a, b, c, d)
#define DVB_PRIVATE_NETWORK_START
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
#define DEFAULT_PES_PAYLOAD_SIZE
#define STREAM_TYPE_BLURAY_SUBTITLE_PGS
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
int initial_padding
Audio only.
#define MPEGTS_FLAG_OMIT_RAI
static int encode_str8(uint8_t *buf, const char *str)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
int mux_rate
set to 1 when VBR
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
int ff_check_h264_startcode(AVFormatContext *s, const AVStream *st, const AVPacket *pkt)
Check presence of H264 startcode.
static int put_arib_caption_descriptor(AVFormatContext *s, uint8_t **q_ptr, AVCodecParameters *codecpar)