You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

675 lines
20KB

  1. /*
  2. * MPEG2 transport stream (aka DVB) mux
  3. * Copyright (c) 2003 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "avformat.h"
  20. #include "crc.h"
  21. #include "mpegts.h"
  22. /* write DVB SI sections */
  23. /*********************************************/
  24. /* mpegts section writer */
  25. typedef struct MpegTSSection {
  26. int pid;
  27. int cc;
  28. void (*write_packet)(struct MpegTSSection *s, const uint8_t *packet);
  29. void *opaque;
  30. } MpegTSSection;
  31. /* NOTE: 4 bytes must be left at the end for the crc32 */
  32. static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len)
  33. {
  34. unsigned int crc;
  35. unsigned char packet[TS_PACKET_SIZE];
  36. const unsigned char *buf_ptr;
  37. unsigned char *q;
  38. int first, b, len1, left;
  39. crc = bswap_32(av_crc(av_crc04C11DB7, -1, buf, len - 4));
  40. buf[len - 4] = (crc >> 24) & 0xff;
  41. buf[len - 3] = (crc >> 16) & 0xff;
  42. buf[len - 2] = (crc >> 8) & 0xff;
  43. buf[len - 1] = (crc) & 0xff;
  44. /* send each packet */
  45. buf_ptr = buf;
  46. while (len > 0) {
  47. first = (buf == buf_ptr);
  48. q = packet;
  49. *q++ = 0x47;
  50. b = (s->pid >> 8);
  51. if (first)
  52. b |= 0x40;
  53. *q++ = b;
  54. *q++ = s->pid;
  55. s->cc = (s->cc + 1) & 0xf;
  56. *q++ = 0x10 | s->cc;
  57. if (first)
  58. *q++ = 0; /* 0 offset */
  59. len1 = TS_PACKET_SIZE - (q - packet);
  60. if (len1 > len)
  61. len1 = len;
  62. memcpy(q, buf_ptr, len1);
  63. q += len1;
  64. /* add known padding data */
  65. left = TS_PACKET_SIZE - (q - packet);
  66. if (left > 0)
  67. memset(q, 0xff, left);
  68. s->write_packet(s, packet);
  69. buf_ptr += len1;
  70. len -= len1;
  71. }
  72. }
  73. static inline void put16(uint8_t **q_ptr, int val)
  74. {
  75. uint8_t *q;
  76. q = *q_ptr;
  77. *q++ = val >> 8;
  78. *q++ = val;
  79. *q_ptr = q;
  80. }
  81. static int mpegts_write_section1(MpegTSSection *s, int tid, int id,
  82. int version, int sec_num, int last_sec_num,
  83. uint8_t *buf, int len)
  84. {
  85. uint8_t section[1024], *q;
  86. unsigned int tot_len;
  87. tot_len = 3 + 5 + len + 4;
  88. /* check if not too big */
  89. if (tot_len > 1024)
  90. return -1;
  91. q = section;
  92. *q++ = tid;
  93. put16(&q, 0xb000 | (len + 5 + 4)); /* 5 byte header + 4 byte CRC */
  94. put16(&q, id);
  95. *q++ = 0xc1 | (version << 1); /* current_next_indicator = 1 */
  96. *q++ = sec_num;
  97. *q++ = last_sec_num;
  98. memcpy(q, buf, len);
  99. mpegts_write_section(s, section, tot_len);
  100. return 0;
  101. }
  102. /*********************************************/
  103. /* mpegts writer */
  104. #define DEFAULT_PMT_START_PID 0x1000
  105. #define DEFAULT_START_PID 0x0100
  106. #define DEFAULT_PROVIDER_NAME "FFmpeg"
  107. #define DEFAULT_SERVICE_NAME "Service01"
  108. /* default network id, transport stream and service identifiers */
  109. #define DEFAULT_ONID 0x0001
  110. #define DEFAULT_TSID 0x0001
  111. #define DEFAULT_SID 0x0001
  112. /* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */
  113. #define DEFAULT_PES_HEADER_FREQ 16
  114. #define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
  115. /* we retransmit the SI info at this rate */
  116. #define SDT_RETRANS_TIME 500
  117. #define PAT_RETRANS_TIME 100
  118. #define PCR_RETRANS_TIME 20
  119. typedef struct MpegTSWriteStream {
  120. struct MpegTSService *service;
  121. int pid; /* stream associated pid */
  122. int cc;
  123. int payload_index;
  124. int64_t payload_pts;
  125. uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE];
  126. } MpegTSWriteStream;
  127. typedef struct MpegTSService {
  128. MpegTSSection pmt; /* MPEG2 pmt table context */
  129. int sid; /* service ID */
  130. char *name;
  131. char *provider_name;
  132. int pcr_pid;
  133. int pcr_packet_count;
  134. int pcr_packet_freq;
  135. } MpegTSService;
  136. typedef struct MpegTSWrite {
  137. MpegTSSection pat; /* MPEG2 pat table */
  138. MpegTSSection sdt; /* MPEG2 sdt table context */
  139. MpegTSService **services;
  140. int sdt_packet_count;
  141. int sdt_packet_freq;
  142. int pat_packet_count;
  143. int pat_packet_freq;
  144. int nb_services;
  145. int onid;
  146. int tsid;
  147. } MpegTSWrite;
  148. static void mpegts_write_pat(AVFormatContext *s)
  149. {
  150. MpegTSWrite *ts = s->priv_data;
  151. MpegTSService *service;
  152. uint8_t data[1012], *q;
  153. int i;
  154. q = data;
  155. for(i = 0; i < ts->nb_services; i++) {
  156. service = ts->services[i];
  157. put16(&q, service->sid);
  158. put16(&q, 0xe000 | service->pmt.pid);
  159. }
  160. mpegts_write_section1(&ts->pat, PAT_TID, ts->tsid, 0, 0, 0,
  161. data, q - data);
  162. }
  163. static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
  164. {
  165. // MpegTSWrite *ts = s->priv_data;
  166. uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr;
  167. int val, stream_type, i;
  168. q = data;
  169. put16(&q, 0xe000 | service->pcr_pid);
  170. program_info_length_ptr = q;
  171. q += 2; /* patched after */
  172. /* put program info here */
  173. val = 0xf000 | (q - program_info_length_ptr - 2);
  174. program_info_length_ptr[0] = val >> 8;
  175. program_info_length_ptr[1] = val;
  176. for(i = 0; i < s->nb_streams; i++) {
  177. AVStream *st = s->streams[i];
  178. MpegTSWriteStream *ts_st = st->priv_data;
  179. switch(st->codec->codec_id) {
  180. case CODEC_ID_MPEG1VIDEO:
  181. case CODEC_ID_MPEG2VIDEO:
  182. stream_type = STREAM_TYPE_VIDEO_MPEG2;
  183. break;
  184. case CODEC_ID_MPEG4:
  185. stream_type = STREAM_TYPE_VIDEO_MPEG4;
  186. break;
  187. case CODEC_ID_H264:
  188. stream_type = STREAM_TYPE_VIDEO_H264;
  189. break;
  190. case CODEC_ID_MP2:
  191. case CODEC_ID_MP3:
  192. stream_type = STREAM_TYPE_AUDIO_MPEG1;
  193. break;
  194. case CODEC_ID_AAC:
  195. stream_type = STREAM_TYPE_AUDIO_AAC;
  196. break;
  197. case CODEC_ID_AC3:
  198. stream_type = STREAM_TYPE_AUDIO_AC3;
  199. break;
  200. default:
  201. stream_type = STREAM_TYPE_PRIVATE_DATA;
  202. break;
  203. }
  204. *q++ = stream_type;
  205. put16(&q, 0xe000 | ts_st->pid);
  206. desc_length_ptr = q;
  207. q += 2; /* patched after */
  208. /* write optional descriptors here */
  209. switch(st->codec->codec_type) {
  210. case CODEC_TYPE_AUDIO:
  211. if (strlen(st->language) == 3) {
  212. *q++ = 0x0a; /* ISO 639 language descriptor */
  213. *q++ = 4;
  214. *q++ = st->language[0];
  215. *q++ = st->language[1];
  216. *q++ = st->language[2];
  217. *q++ = 0; /* undefined type */
  218. }
  219. break;
  220. case CODEC_TYPE_SUBTITLE:
  221. {
  222. const char *language;
  223. language = st->language;
  224. if (strlen(language) != 3)
  225. language = "eng";
  226. *q++ = 0x59;
  227. *q++ = 8;
  228. *q++ = language[0];
  229. *q++ = language[1];
  230. *q++ = language[2];
  231. *q++ = 0x10; /* normal subtitles (0x20 = if hearing pb) */
  232. put16(&q, 1); /* page id */
  233. put16(&q, 1); /* ancillary page id */
  234. }
  235. break;
  236. }
  237. val = 0xf000 | (q - desc_length_ptr - 2);
  238. desc_length_ptr[0] = val >> 8;
  239. desc_length_ptr[1] = val;
  240. }
  241. mpegts_write_section1(&service->pmt, PMT_TID, service->sid, 0, 0, 0,
  242. data, q - data);
  243. }
  244. /* NOTE: str == NULL is accepted for an empty string */
  245. static void putstr8(uint8_t **q_ptr, const char *str)
  246. {
  247. uint8_t *q;
  248. int len;
  249. q = *q_ptr;
  250. if (!str)
  251. len = 0;
  252. else
  253. len = strlen(str);
  254. *q++ = len;
  255. memcpy(q, str, len);
  256. q += len;
  257. *q_ptr = q;
  258. }
  259. static void mpegts_write_sdt(AVFormatContext *s)
  260. {
  261. MpegTSWrite *ts = s->priv_data;
  262. MpegTSService *service;
  263. uint8_t data[1012], *q, *desc_list_len_ptr, *desc_len_ptr;
  264. int i, running_status, free_ca_mode, val;
  265. q = data;
  266. put16(&q, ts->onid);
  267. *q++ = 0xff;
  268. for(i = 0; i < ts->nb_services; i++) {
  269. service = ts->services[i];
  270. put16(&q, service->sid);
  271. *q++ = 0xfc | 0x00; /* currently no EIT info */
  272. desc_list_len_ptr = q;
  273. q += 2;
  274. running_status = 4; /* running */
  275. free_ca_mode = 0;
  276. /* write only one descriptor for the service name and provider */
  277. *q++ = 0x48;
  278. desc_len_ptr = q;
  279. q++;
  280. *q++ = 0x01; /* digital television service */
  281. putstr8(&q, service->provider_name);
  282. putstr8(&q, service->name);
  283. desc_len_ptr[0] = q - desc_len_ptr - 1;
  284. /* fill descriptor length */
  285. val = (running_status << 13) | (free_ca_mode << 12) |
  286. (q - desc_list_len_ptr - 2);
  287. desc_list_len_ptr[0] = val >> 8;
  288. desc_list_len_ptr[1] = val;
  289. }
  290. mpegts_write_section1(&ts->sdt, SDT_TID, ts->tsid, 0, 0, 0,
  291. data, q - data);
  292. }
  293. static MpegTSService *mpegts_add_service(MpegTSWrite *ts,
  294. int sid,
  295. const char *provider_name,
  296. const char *name)
  297. {
  298. MpegTSService *service;
  299. service = av_mallocz(sizeof(MpegTSService));
  300. if (!service)
  301. return NULL;
  302. service->pmt.pid = DEFAULT_PMT_START_PID + ts->nb_services - 1;
  303. service->sid = sid;
  304. service->provider_name = av_strdup(provider_name);
  305. service->name = av_strdup(name);
  306. service->pcr_pid = 0x1fff;
  307. dynarray_add(&ts->services, &ts->nb_services, service);
  308. return service;
  309. }
  310. static void section_write_packet(MpegTSSection *s, const uint8_t *packet)
  311. {
  312. AVFormatContext *ctx = s->opaque;
  313. put_buffer(&ctx->pb, packet, TS_PACKET_SIZE);
  314. }
  315. static int mpegts_write_header(AVFormatContext *s)
  316. {
  317. MpegTSWrite *ts = s->priv_data;
  318. MpegTSWriteStream *ts_st;
  319. MpegTSService *service;
  320. AVStream *st;
  321. int i, total_bit_rate;
  322. const char *service_name;
  323. ts->tsid = DEFAULT_TSID;
  324. ts->onid = DEFAULT_ONID;
  325. /* allocate a single DVB service */
  326. service_name = s->title;
  327. if (service_name[0] == '\0')
  328. service_name = DEFAULT_SERVICE_NAME;
  329. service = mpegts_add_service(ts, DEFAULT_SID,
  330. DEFAULT_PROVIDER_NAME, service_name);
  331. service->pmt.write_packet = section_write_packet;
  332. service->pmt.opaque = s;
  333. ts->pat.pid = PAT_PID;
  334. ts->pat.cc = 0;
  335. ts->pat.write_packet = section_write_packet;
  336. ts->pat.opaque = s;
  337. ts->sdt.pid = SDT_PID;
  338. ts->sdt.cc = 0;
  339. ts->sdt.write_packet = section_write_packet;
  340. ts->sdt.opaque = s;
  341. /* assign pids to each stream */
  342. total_bit_rate = 0;
  343. for(i = 0;i < s->nb_streams; i++) {
  344. st = s->streams[i];
  345. ts_st = av_mallocz(sizeof(MpegTSWriteStream));
  346. if (!ts_st)
  347. goto fail;
  348. st->priv_data = ts_st;
  349. ts_st->service = service;
  350. ts_st->pid = DEFAULT_START_PID + i;
  351. ts_st->payload_pts = AV_NOPTS_VALUE;
  352. /* update PCR pid by using the first video stream */
  353. if (st->codec->codec_type == CODEC_TYPE_VIDEO &&
  354. service->pcr_pid == 0x1fff)
  355. service->pcr_pid = ts_st->pid;
  356. total_bit_rate += st->codec->bit_rate;
  357. }
  358. /* if no video stream, use the first stream as PCR */
  359. if (service->pcr_pid == 0x1fff && s->nb_streams > 0) {
  360. ts_st = s->streams[0]->priv_data;
  361. service->pcr_pid = ts_st->pid;
  362. }
  363. if (total_bit_rate <= 8 * 1024)
  364. total_bit_rate = 8 * 1024;
  365. service->pcr_packet_freq = (total_bit_rate * PCR_RETRANS_TIME) /
  366. (TS_PACKET_SIZE * 8 * 1000);
  367. ts->sdt_packet_freq = (total_bit_rate * SDT_RETRANS_TIME) /
  368. (TS_PACKET_SIZE * 8 * 1000);
  369. ts->pat_packet_freq = (total_bit_rate * PAT_RETRANS_TIME) /
  370. (TS_PACKET_SIZE * 8 * 1000);
  371. #if 0
  372. printf("%d %d %d\n",
  373. total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq);
  374. #endif
  375. /* write info at the start of the file, so that it will be fast to
  376. find them */
  377. mpegts_write_sdt(s);
  378. mpegts_write_pat(s);
  379. for(i = 0; i < ts->nb_services; i++) {
  380. mpegts_write_pmt(s, ts->services[i]);
  381. }
  382. put_flush_packet(&s->pb);
  383. return 0;
  384. fail:
  385. for(i = 0;i < s->nb_streams; i++) {
  386. st = s->streams[i];
  387. av_free(st->priv_data);
  388. }
  389. return -1;
  390. }
  391. /* send SDT, PAT and PMT tables regulary */
  392. static void retransmit_si_info(AVFormatContext *s)
  393. {
  394. MpegTSWrite *ts = s->priv_data;
  395. int i;
  396. if (++ts->sdt_packet_count == ts->sdt_packet_freq) {
  397. ts->sdt_packet_count = 0;
  398. mpegts_write_sdt(s);
  399. }
  400. if (++ts->pat_packet_count == ts->pat_packet_freq) {
  401. ts->pat_packet_count = 0;
  402. mpegts_write_pat(s);
  403. for(i = 0; i < ts->nb_services; i++) {
  404. mpegts_write_pmt(s, ts->services[i]);
  405. }
  406. }
  407. }
  408. /* NOTE: pes_data contains all the PES packet */
  409. static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
  410. const uint8_t *payload, int payload_size,
  411. int64_t pts)
  412. {
  413. MpegTSWriteStream *ts_st = st->priv_data;
  414. uint8_t buf[TS_PACKET_SIZE];
  415. uint8_t *q;
  416. int val, is_start, len, header_len, write_pcr, private_code;
  417. int afc_len, stuffing_len;
  418. int64_t pcr = -1; /* avoid warning */
  419. is_start = 1;
  420. while (payload_size > 0) {
  421. retransmit_si_info(s);
  422. write_pcr = 0;
  423. if (ts_st->pid == ts_st->service->pcr_pid) {
  424. ts_st->service->pcr_packet_count++;
  425. if (ts_st->service->pcr_packet_count >=
  426. ts_st->service->pcr_packet_freq) {
  427. ts_st->service->pcr_packet_count = 0;
  428. write_pcr = 1;
  429. /* XXX: this is incorrect, but at least we have a PCR
  430. value */
  431. pcr = pts;
  432. }
  433. }
  434. /* prepare packet header */
  435. q = buf;
  436. *q++ = 0x47;
  437. val = (ts_st->pid >> 8);
  438. if (is_start)
  439. val |= 0x40;
  440. *q++ = val;
  441. *q++ = ts_st->pid;
  442. *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0);
  443. ts_st->cc = (ts_st->cc + 1) & 0xf;
  444. if (write_pcr) {
  445. *q++ = 7; /* AFC length */
  446. *q++ = 0x10; /* flags: PCR present */
  447. *q++ = pcr >> 25;
  448. *q++ = pcr >> 17;
  449. *q++ = pcr >> 9;
  450. *q++ = pcr >> 1;
  451. *q++ = (pcr & 1) << 7;
  452. *q++ = 0;
  453. }
  454. if (is_start) {
  455. /* write PES header */
  456. *q++ = 0x00;
  457. *q++ = 0x00;
  458. *q++ = 0x01;
  459. private_code = 0;
  460. if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
  461. *q++ = 0xe0;
  462. } else if (st->codec->codec_type == CODEC_TYPE_AUDIO &&
  463. (st->codec->codec_id == CODEC_ID_MP2 ||
  464. st->codec->codec_id == CODEC_ID_MP3)) {
  465. *q++ = 0xc0;
  466. } else {
  467. *q++ = 0xbd;
  468. if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) {
  469. private_code = 0x20;
  470. }
  471. }
  472. if (pts != AV_NOPTS_VALUE)
  473. header_len = 8;
  474. else
  475. header_len = 3;
  476. if (private_code != 0)
  477. header_len++;
  478. len = payload_size + header_len;
  479. *q++ = len >> 8;
  480. *q++ = len;
  481. val = 0x80;
  482. /* data alignment indicator is required for subtitle data */
  483. if (st->codec->codec_type == CODEC_TYPE_SUBTITLE)
  484. val |= 0x04;
  485. *q++ = val;
  486. if (pts != AV_NOPTS_VALUE) {
  487. *q++ = 0x80; /* PTS only */
  488. *q++ = 0x05; /* header len */
  489. val = (0x02 << 4) |
  490. (((pts >> 30) & 0x07) << 1) | 1;
  491. *q++ = val;
  492. val = (((pts >> 15) & 0x7fff) << 1) | 1;
  493. *q++ = val >> 8;
  494. *q++ = val;
  495. val = (((pts) & 0x7fff) << 1) | 1;
  496. *q++ = val >> 8;
  497. *q++ = val;
  498. } else {
  499. *q++ = 0x00;
  500. *q++ = 0x00;
  501. }
  502. if (private_code != 0)
  503. *q++ = private_code;
  504. is_start = 0;
  505. }
  506. /* header size */
  507. header_len = q - buf;
  508. /* data len */
  509. len = TS_PACKET_SIZE - header_len;
  510. if (len > payload_size)
  511. len = payload_size;
  512. stuffing_len = TS_PACKET_SIZE - header_len - len;
  513. if (stuffing_len > 0) {
  514. /* add stuffing with AFC */
  515. if (buf[3] & 0x20) {
  516. /* stuffing already present: increase its size */
  517. afc_len = buf[4] + 1;
  518. memmove(buf + 4 + afc_len + stuffing_len,
  519. buf + 4 + afc_len,
  520. header_len - (4 + afc_len));
  521. buf[4] += stuffing_len;
  522. memset(buf + 4 + afc_len, 0xff, stuffing_len);
  523. } else {
  524. /* add stuffing */
  525. memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4);
  526. buf[3] |= 0x20;
  527. buf[4] = stuffing_len - 1;
  528. if (stuffing_len >= 2) {
  529. buf[5] = 0x00;
  530. memset(buf + 6, 0xff, stuffing_len - 2);
  531. }
  532. }
  533. }
  534. memcpy(buf + TS_PACKET_SIZE - len, payload, len);
  535. payload += len;
  536. payload_size -= len;
  537. put_buffer(&s->pb, buf, TS_PACKET_SIZE);
  538. }
  539. put_flush_packet(&s->pb);
  540. }
  541. static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
  542. {
  543. AVStream *st = s->streams[pkt->stream_index];
  544. int size= pkt->size;
  545. uint8_t *buf= pkt->data;
  546. MpegTSWriteStream *ts_st = st->priv_data;
  547. int len, max_payload_size;
  548. if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) {
  549. /* for subtitle, a single PES packet must be generated */
  550. mpegts_write_pes(s, st, buf, size, pkt->pts);
  551. return 0;
  552. }
  553. max_payload_size = DEFAULT_PES_PAYLOAD_SIZE;
  554. while (size > 0) {
  555. len = max_payload_size - ts_st->payload_index;
  556. if (len > size)
  557. len = size;
  558. memcpy(ts_st->payload + ts_st->payload_index, buf, len);
  559. buf += len;
  560. size -= len;
  561. ts_st->payload_index += len;
  562. if (ts_st->payload_pts == AV_NOPTS_VALUE)
  563. ts_st->payload_pts = pkt->pts;
  564. if (ts_st->payload_index >= max_payload_size) {
  565. mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
  566. ts_st->payload_pts);
  567. ts_st->payload_pts = AV_NOPTS_VALUE;
  568. ts_st->payload_index = 0;
  569. }
  570. }
  571. return 0;
  572. }
  573. static int mpegts_write_end(AVFormatContext *s)
  574. {
  575. MpegTSWrite *ts = s->priv_data;
  576. MpegTSWriteStream *ts_st;
  577. MpegTSService *service;
  578. AVStream *st;
  579. int i;
  580. /* flush current packets */
  581. for(i = 0; i < s->nb_streams; i++) {
  582. st = s->streams[i];
  583. ts_st = st->priv_data;
  584. if (ts_st->payload_index > 0) {
  585. mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
  586. ts_st->payload_pts);
  587. }
  588. }
  589. put_flush_packet(&s->pb);
  590. for(i = 0; i < ts->nb_services; i++) {
  591. service = ts->services[i];
  592. av_freep(&service->provider_name);
  593. av_freep(&service->name);
  594. av_free(service);
  595. }
  596. av_free(ts->services);
  597. return 0;
  598. }
  599. AVOutputFormat mpegts_muxer = {
  600. "mpegts",
  601. "MPEG2 transport stream format",
  602. "video/x-mpegts",
  603. "ts",
  604. sizeof(MpegTSWrite),
  605. CODEC_ID_MP2,
  606. CODEC_ID_MPEG2VIDEO,
  607. mpegts_write_header,
  608. mpegts_write_packet,
  609. mpegts_write_end,
  610. };