[FFmpeg-devel] [bug/patch] MPEG-TS muxer: PCR not in sync withPTS/DTS

Stratford, Alan Alan.Stratford
Wed Sep 9 12:07:42 CEST 2009



>On 07 Sep 2009, at 18:05, Stratford, Alan wrote:
>> I have been looking at the calculation of total_bit_rate in the
latest
>> update to this patch. I think that I understand the calculation but  
>> I am
>> confused by the line
>>
>> total_bit_rate +=
>>  4 * total_bit_rate / (TS_PACKET_SIZE-4)   + /* TS  header size */
>>  1000 * 8 * sdt_size             / SDT_RETRANS_TIME    + /* SDT size

>> */
>>  1000 * 8 * pat_pmt_size         / PAT_RETRANS_TIME    + /* PAT+PMT
>> size */
>>  1000 * 8 * 8                    / PCR_RETRANS_TIME;      /* PCR size
>> */
>>
>> It is the following part that is causing confusion:
>>
>>  4 * total_bit_rate / (TS_PACKET_SIZE-4)   + /* TS  header size */
>>
>> I believe that this is trying to adjust the total_bit_rate to allow  
>> for
>> the
>> fact that the stream will be sent as TS packets, and, therefore, will
>> require an extra 4 bytes of data for each 184 bytes in the stream. If
>> this is not the case then please ignore the rest of this post, but I
>> would greatly appreciate an explanation of what the line does.
>Correct
>
>> If my understanding is correct this part should be:
>>
>>  total_bit_rate * TS_PACKET_SIZE / (TS_PACKET_SIZE-4) + /*TS header
>> size*/
>
>Also correct, but:
>total_bit_rate * TS_PACKET_SIZE / (TS_PACKET_SIZE-4)
>= total_bit_rate * (TS_PACKET_SIZE - 4  + 4 ) / (TS_PACKET_SIZE-4)
>= total_bit_rate * (1 +  4/(TS_PACKET_SIZE-4) )
>= total_bit_rate + 4 * total_bit_rate / (TS_PACKET_SIZE-4)
>
>Hence it's exactly equivalent to
>total_bit_rate += 4 * total_bit_rate / (TS_PACKET_SIZE-4);
>which is what I used
>
>Niobos

Thanks for the explanation. My algebra skills must be going rusty.
However, while I can see that your rearrangement is equivalent I don't
see the reason for it. It seems to make it less clear what the
calculation does for no obvious gain.

I have a couple of further points on the total_bit_rate calculation. 

1. It seems that the PCRs are accounted for, but the fact that they
contribute to extra TS headers are not. i.e. I think that the extra
bytes due to PCRs should be added to total_bit_rate before adjusting it
for TS headers. Something like this:

total_bit_rate += 1000 * 8 * 8 / PCR_RETRANS_TIME;
total_bit_rate += 4 * total_bit_rate / (TS_PACKET_SIZE-4)
                  + 1000 * 8 * sdt_size / SDT_RETRANS_TIME
                  + 1000 * 8 * pat_pmt_size / PAT_RETRANS_TIME;

2. It seems that the stuffing bytes in the last TS packet in each PES
are also not accounted for. I don't know how one would account for these
as the size would depend on the achieved compression rate. Any ideas?

I am very new to MPEG, so please forgive any errors in the above. Again
I would greatly appreciate any explanation you can give.

Alan

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel at mplayerhq.hu
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel

--------------------------------------------------------------------------
Rosemount Aerospace Limited.
Registered Office: Stratford Road, Solihull, West Midlands, B90 4LA.
Registered in England No. 02849033.
--------------------------------------------------------------------------



More information about the ffmpeg-devel mailing list