33 #define PCR_TIME_BASE 27000000
83 #define MPEGTS_FLAG_REEMIT_PAT_PMT 0x01
84 #define MPEGTS_FLAG_AAC_LATM 0x02
90 #define DEFAULT_PES_HEADER_FREQ 16
91 #define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
94 {
"mpegts_transport_stream_id",
"Set transport_stream_id field.",
96 {
"mpegts_original_network_id",
"Set original_network_id field.",
98 {
"mpegts_service_id",
"Set service_id field.",
100 {
"mpegts_pmt_start_pid",
"Set the first pid of the PMT.",
102 {
"mpegts_start_pid",
"Set the first pid.",
104 {
"mpegts_m2ts_mode",
"Enable m2ts mode.",
108 {
"pes_payload_size",
"Minimum PES packet payload in bytes",
112 {
"resend_headers",
"Reemit PAT/PMT before writing the next packet",
115 {
"latm",
"Use LATM packetization for AAC",
119 {
"resend_headers",
"Reemit PAT/PMT before writing the next packet",
121 {
"mpegts_copyts",
"dont offset dts/pts",
138 const unsigned char *buf_ptr;
140 int first,
b, len1, left;
143 buf[len - 4] = (crc >> 24) & 0xff;
144 buf[len - 3] = (crc >> 16) & 0xff;
145 buf[len - 2] = (crc >> 8) & 0xff;
146 buf[len - 1] = (crc) & 0xff;
151 first = (buf == buf_ptr);
159 s->
cc = (s->
cc + 1) & 0xf;
166 memcpy(q, buf_ptr, len1);
171 memset(q, 0xff, left);
190 int version,
int sec_num,
int last_sec_num,
194 unsigned int tot_len;
198 tot_len = 3 + 5 + len + 4;
205 put16(&q, flags | (len + 5 + 4));
207 *q++ = 0xc1 | (version << 1);
219 #define DEFAULT_PROVIDER_NAME "FFmpeg"
220 #define DEFAULT_SERVICE_NAME "Service01"
223 #define SDT_RETRANS_TIME 500
224 #define PAT_RETRANS_TIME 100
225 #define PCR_RETRANS_TIME 20
261 uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr;
262 int val, stream_type, i;
267 program_info_length_ptr = q;
272 val = 0xf000 | (q - program_info_length_ptr - 2);
273 program_info_length_ptr[0] = val >> 8;
274 program_info_length_ptr[1] = val;
335 char *next = lang->
value;
342 for (p = lang->
value; next && *len_ptr < 255 / 4 * 4; p = next + 1) {
343 next = strchr(p,
',');
344 if (strlen(p) != 3 && (!next || next != p + 3))
369 const char *language;
370 language = lang && strlen(lang->
value)==3 ? lang->
value :
"eng";
398 val = 0xf000 | (q - desc_length_ptr - 2);
399 desc_length_ptr[0] = val >> 8;
400 desc_length_ptr[1] = val;
427 uint8_t data[1012], *q, *desc_list_len_ptr, *desc_len_ptr;
428 int i, running_status, free_ca_mode, val;
437 desc_list_len_ptr = q;
449 desc_len_ptr[0] = q - desc_len_ptr - 1;
452 val = (running_status << 13) | (free_ca_mode << 12) |
453 (q - desc_list_len_ptr - 2);
454 desc_list_len_ptr[0] = val >> 8;
455 desc_list_len_ptr[1] = val;
491 uint32_t tp_extra_header = pcr % 0x3fffffff;
492 tp_extra_header =
AV_RB32(&tp_extra_header);
494 sizeof(tp_extra_header));
513 const char *service_name;
536 service->
pmt.
cc = 15;
572 }
else if (st->
id < 0x1FFF) {
584 for (j = 0; j < i; j++)
585 if (pids[j] == ts_st->
pid) {
590 pids[i] = ts_st->
pid;
676 "sdt every %d, pat/pmt every %d pkts\n",
731 int64_t pcr_low = pcr % 300, pcr_high = pcr / 300;
733 *buf++ = pcr_high >> 25;
734 *buf++ = pcr_high >> 17;
735 *buf++ = pcr_high >> 9;
736 *buf++ = pcr_high >> 1;
737 *buf++ = pcr_high << 7 | pcr_low >> 8 | 0x7e;
769 *q++ = ts_st->
pid >> 8;
771 *q++ = 0x20 | ts_st->
cc;
789 val = fourbits << 4 | (((pts >> 30) & 0x07) << 1) | 1;
791 val = (((pts >> 15) & 0x7fff) << 1) | 1;
794 val = (((pts) & 0x7fff) << 1) | 1;
805 if ((pkt[3] & 0x20) == 0) {
827 return pkt + 5 + pkt[4];
838 const uint8_t *payload,
int payload_size,
839 int64_t pts, int64_t dts,
int key)
845 int val, is_start,
len, header_len, write_pcr, private_code,
flags;
846 int afc_len, stuffing_len;
852 while (payload_size > 0) {
868 (dts -
get_pcr(ts, s->
pb)/300) > delay) {
880 val = (ts_st->
pid >> 8);
885 ts_st->
cc = (ts_st->
cc + 1) & 0xf;
886 *q++ = 0x10 | ts_st->
cc;
901 pcr = (dts - delay)*300;
908 int pes_extension = 0;
968 len = payload_size + header_len + 3;
969 if (private_code != 0)
1011 if (private_code != 0)
1012 *q++ = private_code;
1016 header_len = q - buf;
1019 if (len > payload_size)
1022 if (stuffing_len > 0) {
1024 if (buf[3] & 0x20) {
1026 afc_len = buf[4] + 1;
1027 memmove(buf + 4 + afc_len + stuffing_len,
1029 header_len - (4 + afc_len));
1030 buf[4] += stuffing_len;
1031 memset(buf + 4 + afc_len, 0xff, stuffing_len);
1034 memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4);
1036 buf[4] = stuffing_len - 1;
1037 if (stuffing_len >= 2) {
1039 memset(buf + 6, 0xff, stuffing_len - 2);
1045 payload_size -=
len;
1062 int64_t dts = pkt->
dts, pts = pkt->
pts;
1065 av_log(s,
AV_LOG_WARNING,
"resend_headers option is deprecated, use -mpegts_flags resend_headers\n");
1091 uint32_t
state = -1;
1095 "no startcode found, use the h264_mp4toannexb bitstream filter (-bsf h264_mp4toannexb)\n");
1101 av_dlog(s,
"nal %d\n", state & 0x1f);
1102 }
while (p < buf_end && (state & 0x1f) != 9 &&
1103 (state & 0x1f) != 5 && (state & 0x1f) != 1);
1105 if ((state & 0x1f) != 9) {
1109 memcpy(data+6, pkt->
data, pkt->
size);
1117 if (pkt->
size < 2) {
1127 "and extradata missing\n");
1255 .mime_type =
"video/x-mpegts",
1256 .extensions =
"ts,m2t,m2ts,mts",
1264 .priv_class = &mpegts_muxer_class,