1 /*
2 * Copyright (c) 2021 Paul B Mahol
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 /**
22 * @file
23 * Change the PTS/DTS timestamps.
24 */
25
28
31
33 "N", ///< frame number (starting at zero)
34 "TS",
35 "POS", ///< original position in the file of the frame
36 "PREV_INPTS", ///< previous input PTS
37 "PREV_INDTS", ///< previous input DTS
38 "PREV_INDURATION", ///< previous input duration
39 "PREV_OUTPTS", ///< previous output PTS
40 "PREV_OUTDTS", ///< previous output DTS
41 "PREV_OUTDURATION", ///< previous output duration
42 "NEXT_PTS", ///< next input PTS
43 "NEXT_DTS", ///< next input DTS
44 "NEXT_DURATION", ///< next input duration
45 "PTS", ///< original PTS in the file of the frame
46 "DTS", ///< original DTS in the file of the frame
47 "DURATION", ///< original duration in the file of the frame
48 "STARTPTS", ///< PTS at start of movie
49 "STARTDTS", ///< DTS at start of movie
50 "TB", ///< input timebase of the stream
51 "TB_OUT", ///< output timebase of the stream
52 "SR", ///< sample rate of the stream
53 "NOPTS", ///< The AV_NOPTS_VALUE constant
55 };
56
80 };
81
84
89
91
93
95
100
105
107 {
110
114 if (!
s->prev_inpkt || !
s->prev_outpkt || !
s->cur_pkt)
116
121 }
122
127 }
128
134 }
135 }
136
142 }
143 }
144
145 if (
s->time_base.num > 0 &&
s->time_base.den > 0)
146 ctx->time_base_out =
s->time_base;
147
154 s->var_values[
VAR_SR] =
ctx->par_in->sample_rate;
155
156 return 0;
157 }
158
160 {
162 int64_t new_ts, new_pts, new_dts, new_duration;
164
168
169 if (!
s->cur_pkt->data) {
172 }
173
176
179
180 s->var_values[
VAR_N] =
s->frame_number++;
181 s->var_values[
VAR_TS] =
s->cur_pkt->dts;
182 s->var_values[
VAR_POS] =
s->cur_pkt->pos;
183 s->var_values[
VAR_PTS] =
s->cur_pkt->pts;
184 s->var_values[
VAR_DTS] =
s->cur_pkt->dts;
195
198
200 s->var_values[
VAR_TS] =
s->cur_pkt->pts;
202 } else {
203 new_pts = new_ts;
204 }
205
207 s->var_values[
VAR_TS] =
s->cur_pkt->dts;
209 } else {
210 new_dts = new_ts;
211 }
212
217
221
225
229
231 }
232
234 {
236
240
248 s->duration_expr =
NULL;
249 }
250
251 #define OFFSET(x) offsetof(SetTSContext, x)
252 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM|AV_OPT_FLAG_BSF_PARAM)
253
261 };
262
268 };
269
277 };