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

Mike Scheutzow scheutzow
Thu Oct 29 15:30:35 CET 2009


Baptiste Coudurier wrote:
> I think TS header size must be added first, then PCR, then SDT/PAT. 
> Let's compute the bitrate correctly :)

Yes, you're right. Good catch.

>> +    // calc current pcr value using new ts->mux_rate (first ts pkt is 
>> pcr=0)
>> +    nb_pkt = (sdt_size + pat_pmt_size) / TS_PACKET_SIZE;
>> +    ts->cur_pcr = (nb_pkt * TS_PACKET_SIZE * 8 * 90000LL) / 
>> ts->mux_rate;
> 
> This should not be needed. cur_pcr is already adjusted in write_pat and 
> write_pmt. That's why cur_pcr is adjusted below in the code.

Yes, now I understand why that adjustment works.

>> +/* Write a single null transport stream packet */
>> +static void mpegts_insert_null_packet( AVFormatContext *s )
> 
> No space after '(' and before ')', this applies to the whole patch.

Spaces removed.

>> +        if ( dts != AV_NOPTS_VALUE&&  (dts - (int64_t)ts->cur_pcr)>  
>> delay ) {
>> +
>> +            /* pcr insert gets priority over null packet insert */
>> +            if ( write_pcr ) {
>> +                mpegts_insert_pcr_only(s, st);
>> +            } else {
>> +                mpegts_insert_null_packet(s);
>> +            }
>> +
>> +            continue; /* recalculate write_pcr and possibly 
>> retransmit si_info */
>> +        }
>> +
> 
> Can't pcr be written along with data ?
> 
> Maybe something like:
> 
> if (!write_pcr && dts != AV_NOPTS_VALUE && dts - .. > delay) {
>     mpegts_insert_null_packet(s);
>     ts_st->service->pcr_packet_count++;
>     continue;
> }

No, the situation being handled is that (dts-pcr) exceeds max_delay. 
When this occurs, the correct behavior is to output a PCR without 
outputting any video pes data.

This situation occurs when multiple small video frames arrive at the 
muxer, where 'small' means the frame bitrate is less than the average 
bitrate allocated to that stream in the muxer.

>> -    const uint64_t delay = av_rescale(s->max_delay, 90000, 
>> AV_TIME_BASE);
>> +    const int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
> 
> Left over ?

change removed.

v2 of the patch is attached.

--
Mike Scheutzow


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mpeg-mux-cbr-v2.patch
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091029/b162d48d/attachment.txt>



More information about the ffmpeg-devel mailing list