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

Tomas Härdin tomas.hardin
Wed Oct 6 13:33:10 CEST 2010


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 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.

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.

/Tomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: force_pcr.patch
Type: text/x-patch
Size: 1633 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101006/f37f65ce/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: force_pcr_indent.patch
Type: text/x-patch
Size: 1133 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101006/f37f65ce/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101006/f37f65ce/attachment.pgp>



More information about the ffmpeg-devel mailing list