FFmpeg
Loading...
Searching...
No Matches
libavcodec
dts_gen.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2026 Zhao Zhili <quinkblack@foxmail.com>
3
*
4
* This file is part of FFmpeg.
5
*
6
* FFmpeg is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
10
*
11
* FFmpeg is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with FFmpeg; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
#ifndef AVCODEC_DTS_GEN_H
22
#define AVCODEC_DTS_GEN_H
23
24
#include <stdint.h>
25
26
#include "
libavutil/opt.h
"
27
28
#include "
avcodec.h
"
29
30
// Special value for reorder delay.
31
// Asks the encoder to pick a value itself.
32
#define FF_DTS_GEN_DELAY_AUTO -1
33
// Leaves pkt->dts unset.
34
#define FF_DTS_GEN_DELAY_SKIP -2
35
#define FF_DTS_GEN_DELAY_MAX 16
36
37
/* AVOption entries for the reorder_delay option. The encoder resolves
38
* FF_DTS_GEN_DELAY_AUTO before passing the value to ff_dts_gen_init().
39
*/
40
#define FF_DTS_GEN_REORDER_DELAY_OPTION(offset, flags) \
41
{ "reorder_delay", "Reorder delay in frames used to generate dts; a value below the real reorder depth makes dts non-monotonic", \
42
offset, AV_OPT_TYPE_INT, { .i64 = FF_DTS_GEN_DELAY_AUTO }, FF_DTS_GEN_DELAY_SKIP, FF_DTS_GEN_DELAY_MAX, flags, .unit = "reorder_delay" }, \
43
{ "auto", "Derive the delay from the encoder configuration", \
44
0, AV_OPT_TYPE_CONST, { .i64 = FF_DTS_GEN_DELAY_AUTO }, 0, 0, flags, .unit = "reorder_delay" }, \
45
{ "skip", "Leave dts unset for codecs that support reordering", \
46
0, AV_OPT_TYPE_CONST, { .i64 = FF_DTS_GEN_DELAY_SKIP }, 0, 0, flags, .unit = "reorder_delay" }
47
48
/* Derives pkt->dts for packets emitted in decode order from their pts and
49
* the reorder delay. Packets are not reordered.
50
*/
51
typedef
struct
FFDTSGen
{
52
/* Configuration, fixed by ff_dts_gen_init(). */
53
int
delay
;
54
55
/* Input side: the pts of input frames. */
56
int64_t
first_in_pts
;
57
int64_t
prev_in_pts
;
58
/* First increasing interval between two input pts. */
59
int64_t
step
;
60
61
/* Output side: the dts of output packets. */
62
/* pts values kept in ascending order; window[0] is the next dts. */
63
int64_t
window
[
FF_DTS_GEN_DELAY_MAX
+ 1];
64
int64_t
prev_dts
;
65
int
started
;
66
int
warned
;
67
}
FFDTSGen
;
68
69
/* Prepares g for packets emitted in decode order. delay is the reorder
70
* depth: the largest number of frames that precede a frame in decode
71
* order but follow it in display order. It is FF_DTS_GEN_DELAY_SKIP or a
72
* count in [0, FF_DTS_GEN_DELAY_MAX]; the caller resolves
73
* FF_DTS_GEN_DELAY_AUTO.
74
*
75
* Codecs without AV_CODEC_PROP_REORDER get dts == pts whatever delay is.
76
* g->delay holds the effective value, which a caller can publish as
77
* avctx->has_b_frames. A count above the real depth lowers every dts by
78
* the excess frames; a count below it produces dts values that do not
79
* increase, which is logged.
80
*
81
* Returns 0 on success or AVERROR(EINVAL) for any other delay.
82
*/
83
av_cold
int
ff_dts_gen_init
(
const
AVCodecContext
*avctx,
FFDTSGen
*
g
,
84
int
delay);
85
86
/* Records the pts of an input frame, in display order. The first
87
* increasing interval spaces the dts values of the first packets, so it is
88
* latched. AV_NOPTS_VALUE is ignored.
89
*/
90
void
ff_dts_gen_record_pts
(
FFDTSGen
*
g
,
int64_t
pts
);
91
92
/* Sets pkt->dts. Call once per output packet, in output order, after
93
* setting pkt->pts. pkt->dts becomes AV_NOPTS_VALUE when g uses
94
* FF_DTS_GEN_DELAY_SKIP or pkt->pts is AV_NOPTS_VALUE.
95
*
96
* The first delay packets get dts values below the first input pts, or
97
* below the pts of the first packet when that is earlier, spaced by the
98
* interval recorded by ff_dts_gen_record_pts(), or by avctx->framerate, or
99
* by one tick when neither is known.
100
*/
101
void
ff_dts_gen_fill_pkt
(
AVCodecContext
*avctx,
FFDTSGen
*
g
,
AVPacket
*
pkt
);
102
103
/* Drops the buffered timestamps and the recorded input pts and interval,
104
* keeping the configured delay.
105
*/
106
av_cold
void
ff_dts_gen_reset
(
FFDTSGen
*
g
);
107
108
#endif
/* AVCODEC_DTS_GEN_H */
avcodec.h
Libavcodec external API header.
int64_t
long long int64_t
Definition
coverity.c:34
pkt
static AVPacket * pkt
Definition
demux_decode.c:55
ff_dts_gen_fill_pkt
void ff_dts_gen_fill_pkt(AVCodecContext *avctx, FFDTSGen *g, AVPacket *pkt)
Definition
dts_gen.c:79
FF_DTS_GEN_DELAY_MAX
#define FF_DTS_GEN_DELAY_MAX
Definition
dts_gen.h:35
ff_dts_gen_reset
av_cold void ff_dts_gen_reset(FFDTSGen *g)
Definition
dts_gen.c:130
ff_dts_gen_record_pts
void ff_dts_gen_record_pts(FFDTSGen *g, int64_t pts)
Definition
dts_gen.c:51
ff_dts_gen_init
av_cold int ff_dts_gen_init(const AVCodecContext *avctx, FFDTSGen *g, int delay)
Definition
dts_gen.c:28
av_cold
#define av_cold
Definition
attributes.h:117
opt.h
AVOptions.
AVCodecContext
main external API structure.
Definition
avcodec.h:443
AVPacket
This structure stores compressed data.
Definition
packet.h:587
FFDTSGen
Definition
dts_gen.h:51
FFDTSGen::prev_in_pts
int64_t prev_in_pts
Definition
dts_gen.h:57
FFDTSGen::delay
int delay
Definition
dts_gen.h:53
FFDTSGen::first_in_pts
int64_t first_in_pts
Definition
dts_gen.h:56
FFDTSGen::window
int64_t window[FF_DTS_GEN_DELAY_MAX+1]
Definition
dts_gen.h:63
FFDTSGen::prev_dts
int64_t prev_dts
Definition
dts_gen.h:64
FFDTSGen::started
int started
Definition
dts_gen.h:65
FFDTSGen::step
int64_t step
Definition
dts_gen.h:59
FFDTSGen::warned
int warned
Definition
dts_gen.h:66
pts
static int64_t pts
Definition
transcode_aac.c:649
g
const char * g
Definition
vf_curves.c:128
Generated on Wed Dec 2 2026 19:21:02 for FFmpeg by
1.13.2