34 #define PCR_TIME_BASE 27000000
84 #define MPEGTS_FLAG_REEMIT_PAT_PMT 0x01
85 #define MPEGTS_FLAG_AAC_LATM 0x02
92 #define DEFAULT_PES_HEADER_FREQ 16
93 #define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
96 {
"mpegts_transport_stream_id",
"Set transport_stream_id field.",
98 {
"mpegts_original_network_id",
"Set original_network_id field.",
100 {
"mpegts_service_id",
"Set service_id field.",
102 {
"mpegts_pmt_start_pid",
"Set the first pid of the PMT.",
104 {
"mpegts_start_pid",
"Set the first pid.",
106 {
"mpegts_m2ts_mode",
"Enable m2ts mode.",
110 {
"pes_payload_size",
"Minimum PES packet payload in bytes",
114 {
"resend_headers",
"Reemit PAT/PMT before writing the next packet",
117 {
"latm",
"Use LATM packetization for AAC",
121 {
"resend_headers",
"Reemit PAT/PMT before writing the next packet",
123 {
"mpegts_copyts",
"don't offset dts/pts",
125 {
"tables_version",
"set PAT, PMT and SDT version",
142 const unsigned char *buf_ptr;
144 int first,
b, len1, left;
147 buf[len - 4] = (crc >> 24) & 0xff;
148 buf[len - 3] = (crc >> 16) & 0xff;
149 buf[len - 2] = (crc >> 8) & 0xff;
150 buf[len - 1] = (crc) & 0xff;
155 first = (buf == buf_ptr);
163 s->
cc = (s->
cc + 1) & 0xf;
170 memcpy(q, buf_ptr, len1);
175 memset(q, 0xff, left);
194 int version,
int sec_num,
int last_sec_num,
198 unsigned int tot_len;
202 tot_len = 3 + 5 + len + 4;
209 put16(&q, flags | (len + 5 + 4));
211 *q++ = 0xc1 | (version << 1);
223 #define DEFAULT_PROVIDER_NAME "FFmpeg"
224 #define DEFAULT_SERVICE_NAME "Service01"
227 #define SDT_RETRANS_TIME 500
228 #define PAT_RETRANS_TIME 100
229 #define PCR_RETRANS_TIME 20
265 uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr;
266 int val, stream_type, i;
271 program_info_length_ptr = q;
276 val = 0xf000 | (q - program_info_length_ptr - 2);
277 program_info_length_ptr[0] = val >> 8;
278 program_info_length_ptr[1] =
val;
342 char *next = lang->
value;
349 for (p = lang->
value; next && *len_ptr < 255 / 4 * 4; p = next + 1) {
350 next = strchr(p,
',');
351 if (strlen(p) != 3 && (!next || next != p + 3))
376 const char *language;
377 language = lang && strlen(lang->
value)==3 ? lang->
value :
"eng";
415 val = 0xf000 | (q - desc_length_ptr - 2);
416 desc_length_ptr[0] = val >> 8;
417 desc_length_ptr[1] =
val;
444 uint8_t data[1012], *q, *desc_list_len_ptr, *desc_len_ptr;
445 int i, running_status, free_ca_mode,
val;
454 desc_list_len_ptr = q;
466 desc_len_ptr[0] = q - desc_len_ptr - 1;
469 val = (running_status << 13) | (free_ca_mode << 12) |
470 (q - desc_list_len_ptr - 2);
471 desc_list_len_ptr[0] = val >> 8;
472 desc_list_len_ptr[1] =
val;
508 uint32_t tp_extra_header = pcr % 0x3fffffff;
509 tp_extra_header =
AV_RB32(&tp_extra_header);
511 sizeof(tp_extra_header));
530 const char *service_name;
553 service->
pmt.
cc = 15;
589 }
else if (st->
id < 0x1FFF) {
601 for (j = 0; j < i; j++)
602 if (pids[j] == ts_st->
pid) {
607 pids[i] = ts_st->
pid;
693 "sdt every %d, pat/pmt every %d pkts\n",
748 int64_t pcr_low = pcr % 300, pcr_high = pcr / 300;
750 *buf++ = pcr_high >> 25;
751 *buf++ = pcr_high >> 17;
752 *buf++ = pcr_high >> 9;
753 *buf++ = pcr_high >> 1;
754 *buf++ = pcr_high << 7 | pcr_low >> 8 | 0x7e;
786 *q++ = ts_st->
pid >> 8;
788 *q++ = 0x20 | ts_st->
cc;
806 val = fourbits << 4 | (((pts >> 30) & 0x07) << 1) | 1;
808 val = (((pts >> 15) & 0x7fff) << 1) | 1;
811 val = (((pts) & 0x7fff) << 1) | 1;
822 if ((pkt[3] & 0x20) == 0) {
844 return pkt + 5 + pkt[4];
855 const uint8_t *payload,
int payload_size,
856 int64_t pts, int64_t dts,
int key)
862 int val, is_start,
len, header_len, write_pcr, private_code,
flags;
863 int afc_len, stuffing_len;
869 while (payload_size > 0) {
885 (dts -
get_pcr(ts, s->
pb)/300) > delay) {
897 val = (ts_st->
pid >> 8);
902 ts_st->
cc = (ts_st->
cc + 1) & 0xf;
903 *q++ = 0x10 | ts_st->
cc;
918 pcr = (dts - delay)*300;
925 int pes_extension = 0;
985 len = payload_size + header_len + 3;
986 if (private_code != 0)
1028 if (private_code != 0)
1029 *q++ = private_code;
1033 header_len = q -
buf;
1036 if (len > payload_size)
1039 if (stuffing_len > 0) {
1041 if (buf[3] & 0x20) {
1043 afc_len = buf[4] + 1;
1044 memmove(buf + 4 + afc_len + stuffing_len,
1046 header_len - (4 + afc_len));
1047 buf[4] += stuffing_len;
1048 memset(buf + 4 + afc_len, 0xff, stuffing_len);
1051 memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4);
1053 buf[4] = stuffing_len - 1;
1054 if (stuffing_len >= 2) {
1056 memset(buf + 6, 0xff, stuffing_len - 2);
1062 payload_size -=
len;
1079 int64_t dts = pkt->
dts, pts = pkt->
pts;
1082 av_log(s,
AV_LOG_WARNING,
"resend_headers option is deprecated, use -mpegts_flags resend_headers\n");
1108 uint32_t
state = -1;
1113 "no startcode found, use the h264_mp4toannexb bitstream filter (-bsf h264_mp4toannexb)\n");
1121 av_dlog(s,
"nal %d\n", state & 0x1f);
1122 }
while (p < buf_end && (state & 0x1f) != 9 &&
1123 (state & 0x1f) != 5 && (state & 0x1f) != 1);
1125 if ((state & 0x1f) != 9) {
1129 memcpy(data+6, pkt->
data, pkt->
size);
1137 if (pkt->
size < 2) {
1147 "and extradata missing\n");
1275 .mime_type =
"video/x-mpegts",
1276 .extensions =
"ts,m2t,m2ts,mts",
1284 .priv_class = &mpegts_muxer_class,