[FFmpeg-devel] [PATCH] Fix output rate of mpegts CBR muxer

Dan Dennedy dan
Wed Apr 21 20:30:56 CEST 2010


Hi,
On Wed, Apr 21, 2010 at 12:55 AM, Baptiste Coudurier
<baptiste.coudurier at gmail.com> wrote:
> Hi,
>
> On 4/21/10 12:28 AM, Dan Dennedy wrote:
>>
>> Hi,
>> Currently, the mpegts muxer outputs a higher rate than requested using
>> -muxrate due to the cur_pcr accumulating division truncation errors.
>> For a 10 mbps stream, I see about 172 kbps higher than I requested.
>> This fixes it by simply counting packets and then taking the division
>> only when PCR is actually needed.
>>
>> Index: libavformat/mpegtsenc.c
>> ===================================================================
>> --- libavformat/mpegtsenc.c ? ? (revision 22926)
>> +++ libavformat/mpegtsenc.c ? ? (working copy)
>> @@ -60,6 +60,7 @@
>> ? ? ?int nb_services;
>> ? ? ?int onid;
>> ? ? ?int tsid;
>> + ? ?uint64_t pcr_delay;
>
> Is a field really necessary ?
>
> It seems pcr is only written at 2 places.

It is not necessary. At first I did not have that, then added it to
simplify expressions and remove that redundant calculation that occurs
at a high frequency, in particular that test for null packet
insertion. Let me know your preference. Also, I was thinking perhaps
rename cur_pcr to something like pcr_counter.

I am fairly certain this affects PCR accuracy as well and not just a
matter of getting what I asked for. A PCR calculated from an
inaccurate muxrate is not going to be accurate, let alone basing it on
previous PCRs with the truncation.

-- 
+-DRD-+



More information about the ffmpeg-devel mailing list