History

lavf: Add an option for avoiding negative timestamps

This is the same logic as is invoked on AVFMT_TS_NEGATIVE, but which can be enabled manually, or can be enabled in muxers which only need it in certain conditions. Also allow using the same mechanism to force streams to start at 0.

Michael Niedermayer committed 14 years ago

Commit 1384df61 parent 4981baf5 files · +30 −3Browse files

Unified · Split

5 files
  1. doc/APIchanges +3 −0
  2. libavformat/avformat.h +12 −0
  3. libavformat/mux.c +10 −2
  4. libavformat/options_table.h +4 −0
  5. libavformat/version.h +1 −1
doc/APIchanges+3−0
@@ -13,6 +13,9 @@ libavutil: 2014-08-09 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2014-11-xx - xxxxxxx - lavf 56.06.3 - avformat.h
17+ Add AVFormatContext.avoid_negative_ts.
18+
1619 2014-11-xx - xxxxxxx - lavc 56.6.0 - vorbis_parser.h
1720 Add a public API for parsing vorbis packets.
1821
libavformat/avformat.h+12−0
@@ -1198,6 +1198,18 @@ typedef struct AVFormatContext { · 1197 unmodified lines
11981198 */
11991199 int max_ts_probe;
12001200
1201+ /**
1202+ * Avoid negative timestamps during muxing.
1203+ * Any value of the AVFMT_AVOID_NEG_TS_* constants.
1204+ * Note, this only works when using av_interleaved_write_frame.
1205+ * - muxing: Set by user
1206+ * - demuxing: unused
1207+ */
1208+ int avoid_negative_ts;
1209+#define AVFMT_AVOID_NEG_TS_AUTO -1 ///< Enabled when required by target format
1210+#define AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE 1 ///< Shift timestamps so they are non negative
1211+#define AVFMT_AVOID_NEG_TS_MAKE_ZERO 2 ///< Shift timestamps so that they start at 0
1212+
12011213 /*****************************************************************
12021214 * All fields below this line are not part of the public API. They
12031215 * may not be used outside of libavformat and can be changed and
libavformat/mux.c+10−2
@@ -248,6 +248,13 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) · 247 unmodified lines
248248 return ret;
249249 }
250250
251+ if (s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO) {
252+ if (s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS)) {
253+ s->avoid_negative_ts = 0;
254+ } else
255+ s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE;
256+ }
257+
251258 return 0;
252259 }
253260
@@ -318,11 +325,12 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) · 64 unmodified lines
318325 static int write_packet(AVFormatContext *s, AVPacket *pkt)
319326 {
320327 int ret;
321− if (!(s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS))) {
328+ if (s->avoid_negative_ts > 0) {
322329 AVRational time_base = s->streams[pkt->stream_index]->time_base;
323330 int64_t offset = 0;
324331
325− if (!s->offset && pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) {
332+ if (!s->offset && pkt->dts != AV_NOPTS_VALUE &&
333+ (pkt->dts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
326334 s->offset = -pkt->dts;
327335 s->offset_timebase = time_base;
328336 }
libavformat/options_table.h+4−0
@@ -66,6 +66,10 @@ static const AVOption avformat_options[] = { · 65 unmodified lines
6666 {"normal", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_NORMAL }, INT_MIN, INT_MAX, D|E, "strict"},
6767 {"experimental", "allow non-standardized experimental variants", 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_EXPERIMENTAL }, INT_MIN, INT_MAX, D|E, "strict"},
6868 {"max_ts_probe", "maximum number of packets to read while waiting for the first timestamp", OFFSET(max_ts_probe), AV_OPT_TYPE_INT, { .i64 = 50 }, 0, INT_MAX, D },
69+{"avoid_negative_ts", "shift timestamps so they start at 0", OFFSET(avoid_negative_ts), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, E, "avoid_negative_ts"},
70+{"auto", "enabled when required by target format", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_AVOID_NEG_TS_AUTO }, INT_MIN, INT_MAX, E, "avoid_negative_ts"},
71+{"make_non_negative", "shift timestamps so they are non negative", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE }, INT_MIN, INT_MAX, E, "avoid_negative_ts"},
72+{"make_zero", "shift timestamps so they start at 0", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_AVOID_NEG_TS_MAKE_ZERO }, INT_MIN, INT_MAX, E, "avoid_negative_ts"},
6973 {NULL},
7074 };
7175
libavformat/version.h+1−1
@@ -31,7 +31,7 @@ · 30 unmodified lines
3131
3232 #define LIBAVFORMAT_VERSION_MAJOR 56
3333 #define LIBAVFORMAT_VERSION_MINOR 6
34−#define LIBAVFORMAT_VERSION_MICRO 2
34+#define LIBAVFORMAT_VERSION_MICRO 3
3535
3636 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
3737 LIBAVFORMAT_VERSION_MINOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t