[MPlayer-dev-eng] [PATCH] unified timing patch for H264

Pásztor Szilárd don at tricon.hu
Fri Aug 20 19:39:32 CEST 2010


Reimar Döffinger:
> But it is an error, FFmpeg requires the data for a full frame for all
> decoders. As such, if there is only a single field in a packet, the decoder
> should return an error (preferably a special value meaning "well, I can
> handle this, but this is insufficient data").

Ok, here I attach what works for me perfectly at every sample I could get.
This is the best solution I could come up with. Notable changes to the code:

* If correct-pts is on, either by default or specified, only PTS values for
displayable frames get buffered and reordered as this resulted in the
smoothest playback and, besides, it makes PTS buffer length handling coherent
with the decoder lag reported by the codec. My sample (m2hd.ts in HDTV dir) is
perfect for this purpose because it has mixed parts of where first fields
are in separate packets and of where both fields are in one packet. Playback
timing is preserved at both modes, look for the reported A-V sync at the
command line.

* If correct-pts is off (nocorrect-pts is on), PTS values from the stream are
usually ignored and REPLACED by a frametime-based calculation. This makes A-V
sync stable and results in the sync algorithm not trying to correct all the
time, making playback jerky in the process. Time display in OSD is also
turned into smooth counting because PTS values aren't jumpy any more. To
avoid drifting due to rounding errors, PTS values are readjusted to the
original when the difference is less than one tenth of the frametime (that
is, we're pretty sure that we found a frame in place). This method also
preserves A-V sync at jumps between differing field-packet modes.

To make all this possible, I had to change one return value to -1 in
libavcodec/h264.c to be able to detect first field-only packets. It's
unfortunately the only way to NOT break all other interfaces to lavc by
adding a new output parameter. This value is set exclusively in H.264
streams, so all other types should remain completely unaffected.

If the stream is heavily bugged (for example danish_dvb.ts), use
-nocorrect-pts. This patch makes it play perfectly (with -delay -0.4 though).
With -correct-pts it is able to find A-V sync because PTS values aren't
replaced but they make the video jerky.

I hope this patch can make it into the main branch. All hail smooth H.264 HD
playback. *whew*

               --------------------------------------------------
               |  I have seen the truth and it makes no sense.  |
               --------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mplayer-h264-timing-20100820.diff
Type: application/octet-stream
Size: 9854 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20100820/5f2891b4/attachment.obj>


More information about the MPlayer-dev-eng mailing list