34 #define PCR_TIME_BASE 27000000
84 #define MPEGTS_FLAG_REEMIT_PAT_PMT 0x01
85 #define MPEGTS_FLAG_AAC_LATM 0x02
91 #define DEFAULT_PES_HEADER_FREQ 16
92 #define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
95 {
"mpegts_transport_stream_id",
"Set transport_stream_id field.",
97 {
"mpegts_original_network_id",
"Set original_network_id field.",
99 {
"mpegts_service_id",
"Set service_id field.",
101 {
"mpegts_pmt_start_pid",
"Set the first pid of the PMT.",
103 {
"mpegts_start_pid",
"Set the first pid.",
105 {
"mpegts_m2ts_mode",
"Enable m2ts mode.",
109 {
"pes_payload_size",
"Minimum PES packet payload in bytes",
113 {
"resend_headers",
"Reemit PAT/PMT before writing the next packet",
116 {
"latm",
"Use LATM packetization for AAC",
120 {
"resend_headers",
"Reemit PAT/PMT before writing the next packet",
122 {
"mpegts_copyts",
"don't offset dts/pts",
139 const unsigned char *buf_ptr;
141 int first,
b, len1, left;
144 buf[len - 4] = (crc >> 24) & 0xff;
145 buf[len - 3] = (crc >> 16) & 0xff;
146 buf[len - 2] = (crc >> 8) & 0xff;
147 buf[len - 1] = (crc) & 0xff;
152 first = (buf == buf_ptr);
160 s->
cc = (s->
cc + 1) & 0xf;
167 memcpy(q, buf_ptr, len1);
172 memset(q, 0xff, left);
191 int version,
int sec_num,
int last_sec_num,
195 unsigned int tot_len;
199 tot_len = 3 + 5 + len + 4;
206 put16(&q, flags | (len + 5 + 4));
208 *q++ = 0xc1 | (version << 1);
220 #define DEFAULT_PROVIDER_NAME "FFmpeg"
221 #define DEFAULT_SERVICE_NAME "Service01"
224 #define SDT_RETRANS_TIME 500
225 #define PAT_RETRANS_TIME 100
226 #define PCR_RETRANS_TIME 20
262 uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr;
263 int val, stream_type, i;
268 program_info_length_ptr = q;
273 val = 0xf000 | (q - program_info_length_ptr - 2);
274 program_info_length_ptr[0] = val >> 8;
275 program_info_length_ptr[1] =
val;
339 char *next = lang->
value;
346 for (p = lang->
value; next && *len_ptr < 255 / 4 * 4; p = next + 1) {
347 next = strchr(p,
',');
348 if (strlen(p) != 3 && (!next || next != p + 3))
373 const char *language;
374 language = lang && strlen(lang->
value)==3 ? lang->
value :
"eng";
412 val = 0xf000 | (q - desc_length_ptr - 2);
413 desc_length_ptr[0] = val >> 8;
414 desc_length_ptr[1] =
val;
441 uint8_t data[1012], *q, *desc_list_len_ptr, *desc_len_ptr;
442 int i, running_status, free_ca_mode,
val;
451 desc_list_len_ptr = q;
463 desc_len_ptr[0] = q - desc_len_ptr - 1;
466 val = (running_status << 13) | (free_ca_mode << 12) |
467 (q - desc_list_len_ptr - 2);
468 desc_list_len_ptr[0] = val >> 8;
469 desc_list_len_ptr[1] =
val;
505 uint32_t tp_extra_header = pcr % 0x3fffffff;
506 tp_extra_header =
AV_RB32(&tp_extra_header);
508 sizeof(tp_extra_header));
527 const char *service_name;
550 service->
pmt.
cc = 15;
586 }
else if (st->
id < 0x1FFF) {
598 for (j = 0; j < i; j++)
599 if (pids[j] == ts_st->
pid) {
604 pids[i] = ts_st->
pid;
690 "sdt every %d, pat/pmt every %d pkts\n",
745 int64_t pcr_low = pcr % 300, pcr_high = pcr / 300;
747 *buf++ = pcr_high >> 25;
748 *buf++ = pcr_high >> 17;
749 *buf++ = pcr_high >> 9;
750 *buf++ = pcr_high >> 1;
751 *buf++ = pcr_high << 7 | pcr_low >> 8 | 0x7e;
783 *q++ = ts_st->
pid >> 8;
785 *q++ = 0x20 | ts_st->
cc;
803 val = fourbits << 4 | (((pts >> 30) & 0x07) << 1) | 1;
805 val = (((pts >> 15) & 0x7fff) << 1) | 1;
808 val = (((pts) & 0x7fff) << 1) | 1;
819 if ((pkt[3] & 0x20) == 0) {
841 return pkt + 5 + pkt[4];
852 const uint8_t *payload,
int payload_size,
853 int64_t pts, int64_t dts,
int key)
859 int val, is_start,
len, header_len, write_pcr, private_code,
flags;
860 int afc_len, stuffing_len;
866 while (payload_size > 0) {
882 (dts -
get_pcr(ts, s->
pb)/300) > delay) {
894 val = (ts_st->
pid >> 8);
899 ts_st->
cc = (ts_st->
cc + 1) & 0xf;
900 *q++ = 0x10 | ts_st->
cc;
915 pcr = (dts - delay)*300;
922 int pes_extension = 0;
982 len = payload_size + header_len + 3;
983 if (private_code != 0)
1025 if (private_code != 0)
1026 *q++ = private_code;
1030 header_len = q -
buf;
1033 if (len > payload_size)
1036 if (stuffing_len > 0) {
1038 if (buf[3] & 0x20) {
1040 afc_len = buf[4] + 1;
1041 memmove(buf + 4 + afc_len + stuffing_len,
1043 header_len - (4 + afc_len));
1044 buf[4] += stuffing_len;
1045 memset(buf + 4 + afc_len, 0xff, stuffing_len);
1048 memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4);
1050 buf[4] = stuffing_len - 1;
1051 if (stuffing_len >= 2) {
1053 memset(buf + 6, 0xff, stuffing_len - 2);
1059 payload_size -=
len;
1076 int64_t dts = pkt->
dts, pts = pkt->
pts;
1079 av_log(s,
AV_LOG_WARNING,
"resend_headers option is deprecated, use -mpegts_flags resend_headers\n");
1105 uint32_t
state = -1;
1110 "no startcode found, use the h264_mp4toannexb bitstream filter (-bsf h264_mp4toannexb)\n");
1118 av_dlog(s,
"nal %d\n", state & 0x1f);
1119 }
while (p < buf_end && (state & 0x1f) != 9 &&
1120 (state & 0x1f) != 5 && (state & 0x1f) != 1);
1122 if ((state & 0x1f) != 9) {
1126 memcpy(data+6, pkt->
data, pkt->
size);
1134 if (pkt->
size < 2) {
1144 "and extradata missing\n");
1272 .mime_type =
"video/x-mpegts",
1273 .extensions =
"ts,m2t,m2ts,mts",
1281 .priv_class = &mpegts_muxer_class,