[FFmpeg-devel] Bugreport: mpegts-demuxer gives wrong pts/dts with avchd files
Thu Feb 28 14:58:27 CET 2008
M?ns Rullg?rd schrieb:
> Thorsten Jordan <tjordan at macrosystem.de> writes:
>> i just stumbled over misbehvaiour of the mpegts-demuxer of ffmpeg. I
>> Who maintains the mpegts demuxer?
> That would be me. Please upload a sample to mphq.
i debugged a bit more and deeper and found out more things.
Intro (again): What is the problem?
I have here AVCHD-files from a Camera (kind of transport-stream) that
store h.264 video (and AC3 audio) in PAFF mode - that is field after
field. Only every top field has PTS values, only I/P frames have DTS
values. When reading the file with libavformat, wrong values are given
for AVPacket's pts/dts, the pts of the top field of the second frame
(B-frame) is associated to the bottom field of the first frame (I-frame).
After some debugging i suppose this is not h.264/PAFF specific but could
happen with mpeg2 video as well.
Here is the reason: payload of ts packets is given to av_parser_parse()
in libavformat/utils.c line ca. 795 together with pts/dts that is
available for the data chunk. Then in libavcodec/parser.c, in
av_parser_parse() line ca. 125 the pts/dts values are stored. AFTER that
parser->parser_parse() is called - the format specific frame parser.
It will report a frame (here a field) as finished when the current data
chunk allows to find its end. The TS-packet payload here just starts
with a new frame/field. But there the pts/dts values of the NEXT
frame/field are already stored and attached in line 142 ff.
ISO 13818-1 states explicity that the pts is for the access unit that
starts after the pts is given.
A possible first-thought fix would be here to call the parser first and
then associate the pts afterwards - but it would be wrong as well. One
more complex but correct solution would be to give the pts/dts to the
parser itself and let it associate it with the material. Alternativly at
that part of the code a one-stage buffering would be needed, so the
buffered pts/dts (if existing) is associated to a completely parsed
frame/field and afterwards replaced by the newly given pts/dts.
An example file has already been uploaded ca. one week ago.
Mit freundlichen Gr??en, Thorsten
More information about the ffmpeg-devel