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
13 13
14API changes, most recent first:14API changes, most recent first:
15 15
162014-11-xx - xxxxxxx - lavf 56.06.3 - avformat.h
17 Add AVFormatContext.avoid_negative_ts.
18
162014-11-xx - xxxxxxx - lavc 56.6.0 - vorbis_parser.h192014-11-xx - xxxxxxx - lavc 56.6.0 - vorbis_parser.h
17 Add a public API for parsing vorbis packets.20 Add a public API for parsing vorbis packets.
18 21
libavformat/avformat.h+12−0
@@ -1198,6 +1198,18 @@ typedef struct AVFormatContext { · 1197 unmodified lines
1198 */1198 */
1199 int max_ts_probe;1199 int max_ts_probe;
1200 1200
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
1201 /*****************************************************************1213 /*****************************************************************
1202 * All fields below this line are not part of the public API. They1214 * All fields below this line are not part of the public API. They
1203 * may not be used outside of libavformat and can be changed and1215 * 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
248 return ret;248 return ret;
249 }249 }
250 250
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
251 return 0;258 return 0;
252}259}
253 260
@@ -318,11 +325,12 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) · 64 unmodified lines
318static int write_packet(AVFormatContext *s, AVPacket *pkt)325static int write_packet(AVFormatContext *s, AVPacket *pkt)
319{326{
320 int ret;327 int ret;
321 if (!(s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS))) {328 if (s->avoid_negative_ts > 0) {
322 AVRational time_base = s->streams[pkt->stream_index]->time_base;329 AVRational time_base = s->streams[pkt->stream_index]->time_base;
323 int64_t offset = 0;330 int64_t offset = 0;
324 331
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)) {
326 s->offset = -pkt->dts;334 s->offset = -pkt->dts;
327 s->offset_timebase = time_base;335 s->offset_timebase = time_base;
328 }336 }
libavformat/options_table.h+4−0
@@ -66,6 +66,10 @@ static const AVOption avformat_options[] = { · 65 unmodified lines
66{"normal", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_NORMAL }, INT_MIN, INT_MAX, D|E, "strict"},66{"normal", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_NORMAL }, INT_MIN, INT_MAX, D|E, "strict"},
67{"experimental", "allow non-standardized experimental variants", 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_EXPERIMENTAL }, INT_MIN, INT_MAX, D|E, "strict"},67{"experimental", "allow non-standardized experimental variants", 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_EXPERIMENTAL }, INT_MIN, INT_MAX, D|E, "strict"},
68{"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 },68{"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"},
69{NULL},73{NULL},
70};74};
71 75
libavformat/version.h+1−1
@@ -31,7 +31,7 @@ · 30 unmodified lines
31 31
32#define LIBAVFORMAT_VERSION_MAJOR 5632#define LIBAVFORMAT_VERSION_MAJOR 56
33#define LIBAVFORMAT_VERSION_MINOR 633#define LIBAVFORMAT_VERSION_MINOR 6
34#define LIBAVFORMAT_VERSION_MICRO 234#define LIBAVFORMAT_VERSION_MICRO 3
35 35
36#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \36#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
37 LIBAVFORMAT_VERSION_MINOR, \37 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