comparison mpegtsenc.c @ 4216:de2177071c01 libavformat

calculate pat, pmt and sdt exact size and adjust total bitrate
author bcoudurier
date Wed, 14 Jan 2009 23:49:13 +0000
parents f7321bb14421
children 2f3780431c5a
comparison
equal deleted inserted replaced
4215:f7321bb14421 4216:de2177071c01
383 MpegTSWriteStream *ts_st; 383 MpegTSWriteStream *ts_st;
384 MpegTSService *service; 384 MpegTSService *service;
385 AVStream *st; 385 AVStream *st;
386 int i, total_bit_rate; 386 int i, total_bit_rate;
387 const char *service_name; 387 const char *service_name;
388 uint64_t sdt_size, pat_pmt_size, pos;
388 389
389 ts->tsid = DEFAULT_TSID; 390 ts->tsid = DEFAULT_TSID;
390 ts->onid = DEFAULT_ONID; 391 ts->onid = DEFAULT_ONID;
391 /* allocate a single DVB service */ 392 /* allocate a single DVB service */
392 service_name = s->title; 393 service_name = s->title;
438 (TS_PACKET_SIZE * 8 * 1000); 439 (TS_PACKET_SIZE * 8 * 1000);
439 ts->sdt_packet_freq = (total_bit_rate * SDT_RETRANS_TIME) / 440 ts->sdt_packet_freq = (total_bit_rate * SDT_RETRANS_TIME) /
440 (TS_PACKET_SIZE * 8 * 1000); 441 (TS_PACKET_SIZE * 8 * 1000);
441 ts->pat_packet_freq = (total_bit_rate * PAT_RETRANS_TIME) / 442 ts->pat_packet_freq = (total_bit_rate * PAT_RETRANS_TIME) /
442 (TS_PACKET_SIZE * 8 * 1000); 443 (TS_PACKET_SIZE * 8 * 1000);
443 #if 0 444
444 printf("%d %d %d\n", 445 ts->mux_rate = 1; // avoid div by 0
446
447 /* write info at the start of the file, so that it will be fast to
448 find them */
449 pos = url_ftell(s->pb);
450 mpegts_write_sdt(s);
451 sdt_size = url_ftell(s->pb) - pos;
452 pos = url_ftell(s->pb);
453 mpegts_write_pat(s);
454 for(i = 0; i < ts->nb_services; i++) {
455 mpegts_write_pmt(s, ts->services[i]);
456 }
457 pat_pmt_size = url_ftell(s->pb) - pos;
458
459 total_bit_rate +=
460 total_bit_rate * 25 / (8 * DEFAULT_PES_PAYLOAD_SIZE) + /* PES header size */
461 total_bit_rate * 4 / (8 * TS_PACKET_SIZE) + /* TS header size */
462 SDT_RETRANS_TIME * sdt_size + /* SDT size */
463 PAT_RETRANS_TIME * pat_pmt_size + /* PAT+PMT size */
464 PCR_RETRANS_TIME * 8; /* PCR size */
465
466 av_log(s, AV_LOG_DEBUG, "muxrate %d freq sdt %d pat %d\n",
445 total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq); 467 total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq);
446 #endif
447 468
448 if (s->mux_rate) 469 if (s->mux_rate)
449 ts->mux_rate = s->mux_rate; 470 ts->mux_rate = s->mux_rate;
450 else 471 else
451 ts->mux_rate = total_bit_rate; 472 ts->mux_rate = total_bit_rate;
452 473
453 /* write info at the start of the file, so that it will be fast to 474 // adjust pcr
454 find them */ 475 ts->cur_pcr /= ts->mux_rate;
455 mpegts_write_sdt(s); 476
456 mpegts_write_pat(s);
457 for(i = 0; i < ts->nb_services; i++) {
458 mpegts_write_pmt(s, ts->services[i]);
459 }
460 put_flush_packet(s->pb); 477 put_flush_packet(s->pb);
461 478
462 return 0; 479 return 0;
463 480
464 fail: 481 fail: