[FFmpeg-devel] [PATCH] mpegtsenc: Force writing PCR-only packet to PCR stream if the current stream is not the PCR stream

Baptiste Coudurier baptiste.coudurier
Thu Oct 7 00:10:18 CEST 2010


On 10/06/2010 04:33 AM, Tomas H?rdin wrote:
> Hi
>
> This is yet another mpegtsenc patch. It makes sure PCR for a given
> service is written at even intervals, regardless of how large the
> non-video packets are. Without this patch, a large subtitle packet can
> cause PCR to be written far too late - we measured up to 100 ms delay
> instead of the intended 20 ms (PCR_RETRANS_TIME). This is of course not
> limited to subs.
>
> What the patch does is count all streams in a service towards
> pcr_packet_count, not just the first video stream. In other words, if
> the PCR period is 4 then every fourth iteration of the while-loop in
> mpegts_write_pes() results in PCR being written. In fact, this is what
> the existing code already does for video streams.
>
> When writing non-video streams PCR still needs to be written
> periodically, but PCR may only be written for streams whose PID matches
> a service's PCR PID (typically the first video stream). The patch uses a
> simple solution for this: write a PCR-only packet with the video
> stream's PID, similarly to how such packets are written when padding for
> CBR mode. This is of course a bit wasteful when muxing VBR, but it is
> more correct AFAICT.

I agree, although the perfect solution would be write PCR based on 
timing. Specifications says that delta between PCRs shall be <= 0.1s

> I am unsure how well the patch behaves with multiple services. One might
> want move pcr_packet_count to MpegTSWrite and write PCR for all services
> when it is time, which is of course even more wasteful.
>
> A better solution would of course be to interleave the PES packets that
> make up the last few packets of each stream of each service, and make
> sure PCR is written for all services when required. At the moment I am
> more concerned with the muxer outputting a compliant bitstream though,
> rather than being the most efficient implementation.

I agree with that.

> This patch works well with the high-res PCR patch I mailed six days ago.
> Together they produce output whose PCR is written at reliable intervals
> (20-22 ms) and whose jitter is around +- 35 ns.
>
> Patch and indent patch attached. Output differs, so lavf-ts regtest
> obviously failed.
>
> [...]
 >
> +
> +        if(write_pcr&&  ts_st->pid != ts_st->service->pcr_pid) {
> +            /* write a pcr-only packet to the pcr stream since pcr needs to be
> +             * written but the current stream is not the pcr stream
> +             * FIXME: this is slightly wasteful in VBR mode */

Please no new FIXME, you can check wether you are in VBR mode or not.

Indent patch is ok.

-- 
Baptiste COUDURIER
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
FFmpeg maintainer                                  http://www.ffmpeg.org



More information about the ffmpeg-devel mailing list