On Fri, 28 Mar 2014 21:19:55 +0100 Lucas Soltic <[email protected]> wrote:
> Hello! > > Does av_frame_get_best_effort_timestamp() gives a PTS or DTS? > > At first I would have thought it's a PTS, because it's impossible for > decoding to correctly happen if DTS does not exist in the packet, but then I > read that the packet DTS may be AV_NOPTS_VALUE (DTS being a NOPTS..??!). If > that is correct, is there a reliable way to know the DTS too (in the core > meaning of DTS, even if the file does not set it)? Some files have PTS and DTS mixed (mpeg mostly), some files have PTS only (e.g. Matroska), some files have DTS only (e.g. AVI). The general solution is to use DTS if PTS is set to NOPTS. Here's how av_frame_get_best_effort_timestamp() is calculated: https://git.videolan.org/?p=ffmpeg.git;a=blob;f=libavcodec/utils.c;h=b43f67540e834d45058f9d694cc6c090d1b4c27d;hb=HEAD#l1995 Looks complicated, but is rather simple. As I understand, this is mostly a workaround if PTS or DTS are set incorrectly. This function takes AVFrame.pkt_pts and AVFrame.pkt_dts as inputs. It returns what will be used as AVFrame.best_effort_timestamp. What this function does is: 1. count how often it happens that PTS or DTS are not monotonic (normally, the DTS _and_ PTS should not decrease after the decoder; this is not true _before_ the decoder, but the decoder should reorder them so that they're monotonic, and some broken files might violate this) 2. if PTS is more often wrong than DTS, use the DTS as output timestamp Libav does not have the AVFrame.best_effort_timestamp field. Butthe Libav command line tools (avplay, avconv) calculates it the same way: https://git.libav.org/?p=libav.git;a=blob;f=cmdutils.c;h=69a11bdd4fb33ccdc1420e15edb7c47c8ce84098;hb=HEAD#l1431 And that's why I would recommend just copying the code. It's trivial anyway, at least once you understand it, and your project will be compatible to both FFmpeg and Libav. _______________________________________________ Libav-user mailing list [email protected] http://ffmpeg.org/mailman/listinfo/libav-user
