* [FFmpeg-devel] [PATCH v2 1/6] avformat/mux: Remove assert based on faulty assumptions
@ 2022-01-19 21:19 Andreas Rheinhardt
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 2/6] fate/matroska: Add test for avoiding negative timestamps Andreas Rheinhardt
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-01-19 21:19 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This assert is based upon the wrong assumption that
the noninterleaved codepath is never used; if it is used,
max_interleave_delta is irrelevant. It furthermore
ignores audio_preload.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavformat/mux.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/libavformat/mux.c b/libavformat/mux.c
index c387f8ec6e..e34fd88f05 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -697,7 +697,6 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
);
}
} else {
- av_assert2(pkt->dts == AV_NOPTS_VALUE || pkt->dts >= 0 || s->max_interleave_delta > 0);
if (pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) {
av_log(s, AV_LOG_WARNING,
"Packets poorly interleaved, failed to avoid negative "
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/6] fate/matroska: Add test for avoiding negative timestamps
2022-01-19 21:19 [FFmpeg-devel] [PATCH v2 1/6] avformat/mux: Remove assert based on faulty assumptions Andreas Rheinhardt
@ 2022-01-19 21:29 ` Andreas Rheinhardt
[not found] ` <20220119212940.1071477-1-andreas.rheinhardt@outlook.com>
2022-01-21 12:14 ` [FFmpeg-devel] [PATCH v2 1/6] avformat/mux: Remove assert based on faulty assumptions Andreas Rheinhardt
2 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-01-19 21:29 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This tests the issue from tickets #4536, #5784;
the output of this test is currently broken.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
Now only performing codec copy.
tests/fate/matroska.mak | 17 +++++++++
tests/ref/fate/matroska-avoid-negative-ts | 42 +++++++++++++++++++++++
2 files changed, 59 insertions(+)
create mode 100644 tests/ref/fate/matroska-avoid-negative-ts
diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak
index 2fcac34d62..b65a76411b 100644
--- a/tests/fate/matroska.mak
+++ b/tests/fate/matroska.mak
@@ -90,6 +90,23 @@ FATE_MATROSKA_FFMPEG_FFPROBE-$(call ALLYES, FILE_PROTOCOL MOV_DEMUXER \
+= fate-matroska-dovi-write-config7
fate-matroska-dovi-write-config7: CMD = transcode mov $(TARGET_SAMPLES)/mov/dovi-p7.mp4 matroska "-map 0 -c copy -cues_to_front yes -reserve_index_space 40 -metadata_header_padding 64339" "-map 0 -c copy" "" "-show_entries stream_side_data_list"
+# This tests the scenario like tickets #4536, #5784 where
+# the first packet (with the overall lowest dts) is a video packet,
+# whereas an audio packet to be muxed later has the overall lowest pts
+# which happens to be negative and therefore needs to be shifted.
+# This is currently buggy (the timestamps of the video frames muxed
+# before the first audio frame are not shifted).
+# (-ss 1.09 ensures that a video frame has the lowest dts of all packets;
+# yet there is an audio packet with the overall lowest pts. output_ts_offset
+# makes the pts of the audio packet, but not the leading video packet negative
+# so that we run into the above issue.)
+FATE_MATROSKA-$(call ALLYES, FILE_PROTOCOL MPEGTS_DEMUXER MPEGVIDEO_PARSER \
+ MPEG2VIDEO_DECODER EXTRACT_EXTRADATA_BSF \
+ MP3FLOAT_DECODER MATROSKA_MUXER \
+ MATROSKA_DEMUXER FRAMECRC_MUXER PIPE_PROTOCOL) \
+ += fate-matroska-avoid-negative-ts
+fate-matroska-avoid-negative-ts: CMD = transcode mpegts $(TARGET_SAMPLES)/mpeg2/t.mpg matroska "-c copy -ss 1.09 -output_ts_offset -60ms" "-c copy -t 0.4"
+
# This tests writing the MS-compatibility modes V_MS/VFW/FOURCC and A_MS/ACM.
# It furthermore tests writing the Cues at the front if the cues_to_front
# option is set and more than enough space has been reserved in advance.
diff --git a/tests/ref/fate/matroska-avoid-negative-ts b/tests/ref/fate/matroska-avoid-negative-ts
new file mode 100644
index 0000000000..a687c8f63c
--- /dev/null
+++ b/tests/ref/fate/matroska-avoid-negative-ts
@@ -0,0 +1,42 @@
+3349536550047c5c553215003ba2acb7 *tests/data/fate/matroska-avoid-negative-ts.matroska
+973070 tests/data/fate/matroska-avoid-negative-ts.matroska
+#extradata 0: 22, 0x2885037c
+#tb 0: 1/1000
+#media_type 0: video
+#codec_id 0: mpeg2video
+#dimensions 0: 352x288
+#sar 0: 12/11
+#tb 1: 1/1000
+#media_type 1: audio
+#codec_id 1: mp3
+#sample_rate 1: 44100
+#channel_layout 1: 4
+#channel_layout_name 1: mono
+0, -37, 24, 40, 9156, 0xe5bd034a, S=1, 40
+1, 0, 0, 26, 417, 0x7198c15e
+0, 3, 3, 40, 1740, 0x29ac4480, F=0x0
+0, 24, 123, 40, 3672, 0x98652013, F=0x0
+1, 26, 26, 26, 417, 0x3c67c32d
+1, 52, 52, 26, 417, 0x8c24b1ca
+1, 78, 78, 26, 417, 0x6ee576b7
+0, 83, 83, 40, 2532, 0xa2c42769, F=0x0
+1, 104, 104, 26, 417, 0x407603db
+0, 123, 203, 40, 1728, 0xae823d3b, F=0x0
+1, 130, 130, 26, 417, 0xcf2804d2
+1, 156, 156, 26, 417, 0xcf2804d2
+0, 163, 163, 40, 1028, 0x286ac52a, F=0x0
+1, 182, 182, 26, 417, 0xcf2804d2
+0, 203, 283, 40, 1916, 0xd378899e, F=0x0
+1, 208, 208, 26, 417, 0xcf2804d2
+1, 235, 235, 26, 417, 0xcf2804d2
+0, 243, 243, 40, 1168, 0x424e12cf, F=0x0
+1, 261, 261, 26, 417, 0xcf2804d2
+0, 283, 363, 40, 1660, 0x5cec156c, F=0x0
+1, 287, 287, 26, 417, 0xcf2804d2
+1, 313, 313, 26, 417, 0xef163d04
+0, 323, 323, 40, 1004, 0xac0dce29, F=0x0
+1, 339, 339, 26, 417, 0x2a009b3a
+0, 363, 443, 40, 3008, 0x0fc798bf, F=0x0
+1, 365, 365, 26, 417, 0xbedccb9d
+1, 365, 365, 26, 417, 0x2214be3f
+1, 391, 391, 26, 417, 0x8953b878
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/6] avformat/avformat: Add AVFMT_AVOID_NEG_TS_DISABLED
[not found] ` <20220119212940.1071477-1-andreas.rheinhardt@outlook.com>
@ 2022-01-19 21:29 ` Andreas Rheinhardt
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 4/6] avformat/mux: Preserve sync even if later packet has negative ts Andreas Rheinhardt
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-01-19 21:29 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
And also don't use explicit constants in the movenc test.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavformat/avformat.h | 1 +
libavformat/mux.c | 2 +-
libavformat/options_table.h | 2 +-
libavformat/tests/movenc.c | 4 ++--
libavformat/webm_chunk.c | 2 +-
5 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 6ce367e854..cd253fb28e 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1533,6 +1533,7 @@ typedef struct AVFormatContext {
*/
int avoid_negative_ts;
#define AVFMT_AVOID_NEG_TS_AUTO -1 ///< Enabled when required by target format
+#define AVFMT_AVOID_NEG_TS_DISABLED 0 ///< Do not shift timestamps even when they are negative.
#define AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE 1 ///< Shift timestamps so they are non negative
#define AVFMT_AVOID_NEG_TS_MAKE_ZERO 2 ///< Shift timestamps so that they start at 0
diff --git a/libavformat/mux.c b/libavformat/mux.c
index e34fd88f05..a1917878a5 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -421,7 +421,7 @@ static int init_pts(AVFormatContext *s)
if (s->avoid_negative_ts < 0) {
av_assert2(s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO);
if (s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS)) {
- s->avoid_negative_ts = 0;
+ s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_DISABLED;
} else
s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE;
}
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index 62c5bb40a3..86d836cfeb 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -95,7 +95,7 @@ static const AVOption avformat_options[] = {
{"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 },
{"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"},
{"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"},
-{"disabled", "do not change timestamps", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, INT_MIN, INT_MAX, E, "avoid_negative_ts"},
+{"disabled", "do not change timestamps", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_AVOID_NEG_TS_DISABLED }, INT_MIN, INT_MAX, E, "avoid_negative_ts"},
{"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"},
{"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"},
{"dump_separator", "set information dump field separator", OFFSET(dump_separator), AV_OPT_TYPE_STRING, {.str = ", "}, 0, 0, D|E},
diff --git a/libavformat/tests/movenc.c b/libavformat/tests/movenc.c
index 2af72f11c7..ddcb053bf2 100644
--- a/libavformat/tests/movenc.c
+++ b/libavformat/tests/movenc.c
@@ -455,7 +455,7 @@ int main(int argc, char **argv)
init_count_warnings();
init_out("empty-moov-no-elst-no-adjust");
av_dict_set(&opts, "movflags", "frag_keyframe+empty_moov", 0);
- av_dict_set(&opts, "avoid_negative_ts", "0", 0);
+ av_dict_set(&opts, "avoid_negative_ts", "disabled", 0);
init(1, 0);
mux_gops(2);
finish();
@@ -578,7 +578,7 @@ int main(int argc, char **argv)
// one before.
av_dict_set(&opts, "movflags", "frag_custom+empty_moov+dash+frag_discont", 0);
av_dict_set(&opts, "fragment_index", "2", 0);
- av_dict_set(&opts, "avoid_negative_ts", "0", 0);
+ av_dict_set(&opts, "avoid_negative_ts", "disabled", 0);
av_dict_set(&opts, "use_editlist", "0", 0);
init(0, 0);
skip_gops(1);
diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c
index 24390e8e74..9348e6680a 100644
--- a/libavformat/webm_chunk.c
+++ b/libavformat/webm_chunk.c
@@ -127,7 +127,7 @@ fail:
s->avoid_negative_ts = oc->avoid_negative_ts;
ffformatcontext(s)->avoid_negative_ts_use_pts =
ffformatcontext(oc)->avoid_negative_ts_use_pts;
- oc->avoid_negative_ts = 0;
+ oc->avoid_negative_ts = AVFMT_AVOID_NEG_TS_DISABLED;
return 0;
}
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH v2 4/6] avformat/mux: Preserve sync even if later packet has negative ts
[not found] ` <20220119212940.1071477-1-andreas.rheinhardt@outlook.com>
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 3/6] avformat/avformat: Add AVFMT_AVOID_NEG_TS_DISABLED Andreas Rheinhardt
@ 2022-01-19 21:29 ` Andreas Rheinhardt
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 5/6] avformat/mux: Peek into the muxing queue for avoid_negative_ts Andreas Rheinhardt
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 6/6] avformat/hls: Remove redundant cast Andreas Rheinhardt
3 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-01-19 21:29 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
write_packet() has code to shift the packets timestamps
to make them nonnegative or even make them start at ts zero;
this code inspects every packet that is written and if a packet
with negative timestamp (whether this is dts or pts depends upon
another flag; basically: Matroska uses pts, everyone else dts)
is encountered, this is offset to make the timestamp zero.
All further packets will be offset accordingly (with the offset
converted according to the streams' timebases).
This is based around an assumption, namely that the timestamps
are indeed non-decreasing, so that the first packet with negative
timestamps is the first packet with timestamps. This assumption
is often fulfilled given that the default interleavement function
by default interleaves per dts; yet there are scenarios in which
it may not be fulfilled:
a) av_write_frame() instead of av_interleaved_write_frame() is used.
b) The audio_preload option is used.
c) When the timestamps that are made nonnegative/zero are pts
(i.e. with Matroska), because the packet with the smallest dts
is not necessarily the packet with the smallest pts.
d) Possibly with custom interleavement functions.
In these cases the relative sync of the first few packet(s) is offset
relative to the later packets. This contradicts the documentation
("When shifting is enabled, all output timestamps are shifted by
the same amount").
Therefore this commit changes this: As soon as the first packet
with valid timestamps is output, it is checked and recorded whether
the timestamps need to be shifted. Further packets are no longer
checked for needing to be offset; instead they are simply offset.
In the cases above this leads to packets with negative timestamps
(and the appropriate warnings) instead of desync. This will mostly
be fixed in the next commit.
This commit also factors handling the avoid_negative_ts stuff out
of write_packet() in order to be able to return immediately.
Tickets #4536 and #5784 as well as the matroska-avoid-negative-ts-test
are examples of c); as has been said, some timestamps are now negative,
yet the ref file update does not show it because ffmpeg.c sanitizes
the timestamps (-copyts disables it; ffprobe and mkvinfo also show
the original timestamps).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavformat/internal.h | 23 +++--
libavformat/mux.c | 111 +++++++++++++---------
libavformat/options.c | 1 -
tests/fate/matroska.mak | 4 +-
tests/ref/fate/matroska-avoid-negative-ts | 6 +-
5 files changed, 81 insertions(+), 64 deletions(-)
diff --git a/libavformat/internal.h b/libavformat/internal.h
index bffb8e66ff..f24c68703f 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -82,6 +82,17 @@ typedef struct FFFormatContext {
*/
int nb_interleaved_streams;
+ /**
+ * Whether the timestamp shift offset has already been determined.
+ * -1: disabled, 0: not yet determined, 1: determined.
+ */
+ enum {
+ AVOID_NEGATIVE_TS_DISABLED = -1,
+ AVOID_NEGATIVE_TS_UNKNOWN = 0,
+ AVOID_NEGATIVE_TS_KNOWN = 1,
+ } avoid_negative_ts_status;
+#define AVOID_NEGATIVE_TS_ENABLED(status) ((status) >= 0)
+
/**
* The interleavement function in use. Always set for muxers.
*/
@@ -135,18 +146,6 @@ typedef struct FFFormatContext {
*/
int raw_packet_buffer_size;
- /**
- * Offset to remap timestamps to be non-negative.
- * Expressed in timebase units.
- * @see AVStream.mux_ts_offset
- */
- int64_t offset;
-
- /**
- * Timebase for the timestamp offset.
- */
- AVRational offset_timebase;
-
#if FF_API_COMPUTE_PKT_FIELDS2
int missing_ts_warning;
#endif
diff --git a/libavformat/mux.c b/libavformat/mux.c
index a1917878a5..0810b674a7 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -388,6 +388,8 @@ fail:
static int init_pts(AVFormatContext *s)
{
+ FFFormatContext *const si = ffformatcontext(s);
+
/* init PTS generation */
for (unsigned i = 0; i < s->nb_streams; i++) {
AVStream *const st = s->streams[i];
@@ -418,13 +420,16 @@ static int init_pts(AVFormatContext *s)
}
}
+ si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_UNKNOWN;
if (s->avoid_negative_ts < 0) {
av_assert2(s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO);
if (s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS)) {
s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_DISABLED;
+ si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_DISABLED;
} else
s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE;
- }
+ } else if (s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_DISABLED)
+ si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_DISABLED;
return 0;
}
@@ -638,6 +643,64 @@ static void guess_pkt_duration(AVFormatContext *s, AVStream *st, AVPacket *pkt)
}
}
+static void handle_avoid_negative_ts(FFFormatContext *si, FFStream *sti,
+ AVPacket *pkt)
+{
+ AVFormatContext *const s = &si->pub;
+ int64_t offset;
+
+ if (!AVOID_NEGATIVE_TS_ENABLED(si->avoid_negative_ts_status))
+ return;
+
+ if (si->avoid_negative_ts_status == AVOID_NEGATIVE_TS_UNKNOWN) {
+ int use_pts = si->avoid_negative_ts_use_pts;
+ int64_t ts = use_pts ? pkt->pts : pkt->dts;
+
+ if (ts == AV_NOPTS_VALUE)
+ return;
+ if (ts < 0 ||
+ ts > 0 && s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO) {
+ for (unsigned i = 0; i < s->nb_streams; i++) {
+ AVStream *const st2 = s->streams[i];
+ FFStream *const sti2 = ffstream(st2);
+ sti2->mux_ts_offset = av_rescale_q_rnd(-ts,
+ sti->pub.time_base,
+ st2->time_base,
+ AV_ROUND_UP);
+ }
+ }
+ si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_KNOWN;
+ }
+
+ offset = sti->mux_ts_offset;
+
+ if (pkt->dts != AV_NOPTS_VALUE)
+ pkt->dts += offset;
+ if (pkt->pts != AV_NOPTS_VALUE)
+ pkt->pts += offset;
+
+ if (si->avoid_negative_ts_use_pts) {
+ if (pkt->pts != AV_NOPTS_VALUE && pkt->pts < 0) {
+ av_log(s, AV_LOG_WARNING, "failed to avoid negative "
+ "pts %s in stream %d.\n"
+ "Try -avoid_negative_ts 1 as a possible workaround.\n",
+ av_ts2str(pkt->pts),
+ pkt->stream_index
+ );
+ }
+ } else {
+ if (pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) {
+ av_log(s, AV_LOG_WARNING,
+ "Packets poorly interleaved, failed to avoid negative "
+ "timestamp %s in stream %d.\n"
+ "Try -max_interleave_delta 0 as a possible workaround.\n",
+ av_ts2str(pkt->dts),
+ pkt->stream_index
+ );
+ }
+ }
+}
+
/**
* Shift timestamps and call muxer; the original pts/dts are not kept.
*
@@ -663,51 +726,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
if (pkt->pts != AV_NOPTS_VALUE)
pkt->pts += offset;
}
-
- if (s->avoid_negative_ts > 0) {
- int64_t offset = sti->mux_ts_offset;
- int64_t ts = si->avoid_negative_ts_use_pts ? pkt->pts : pkt->dts;
-
- if (si->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE &&
- (ts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
- si->offset = -ts;
- si->offset_timebase = st->time_base;
- }
-
- if (si->offset != AV_NOPTS_VALUE && !offset) {
- offset = sti->mux_ts_offset =
- av_rescale_q_rnd(si->offset,
- si->offset_timebase,
- st->time_base,
- AV_ROUND_UP);
- }
-
- if (pkt->dts != AV_NOPTS_VALUE)
- pkt->dts += offset;
- if (pkt->pts != AV_NOPTS_VALUE)
- pkt->pts += offset;
-
- if (si->avoid_negative_ts_use_pts) {
- if (pkt->pts != AV_NOPTS_VALUE && pkt->pts < 0) {
- av_log(s, AV_LOG_WARNING, "failed to avoid negative "
- "pts %s in stream %d.\n"
- "Try -avoid_negative_ts 1 as a possible workaround.\n",
- av_ts2str(pkt->pts),
- pkt->stream_index
- );
- }
- } else {
- if (pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) {
- av_log(s, AV_LOG_WARNING,
- "Packets poorly interleaved, failed to avoid negative "
- "timestamp %s in stream %d.\n"
- "Try -max_interleave_delta 0 as a possible workaround.\n",
- av_ts2str(pkt->dts),
- pkt->stream_index
- );
- }
- }
- }
+ handle_avoid_negative_ts(si, sti, pkt);
if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) {
AVFrame **frame = (AVFrame **)pkt->data;
diff --git a/libavformat/options.c b/libavformat/options.c
index 1634388acb..2d55d3ad6e 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -174,7 +174,6 @@ AVFormatContext *avformat_alloc_context(void)
return NULL;
}
- si->offset = AV_NOPTS_VALUE;
si->shortest_end = AV_NOPTS_VALUE;
return s;
diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak
index b65a76411b..da1fdbd5ea 100644
--- a/tests/fate/matroska.mak
+++ b/tests/fate/matroska.mak
@@ -94,8 +94,8 @@ fate-matroska-dovi-write-config7: CMD = transcode mov $(TARGET_SAMPLES)/mov/dovi
# the first packet (with the overall lowest dts) is a video packet,
# whereas an audio packet to be muxed later has the overall lowest pts
# which happens to be negative and therefore needs to be shifted.
-# This is currently buggy (the timestamps of the video frames muxed
-# before the first audio frame are not shifted).
+# This is currently buggy (the timestamps are not shifted properly:
+# the first audio packet has negative pts).
# (-ss 1.09 ensures that a video frame has the lowest dts of all packets;
# yet there is an audio packet with the overall lowest pts. output_ts_offset
# makes the pts of the audio packet, but not the leading video packet negative
diff --git a/tests/ref/fate/matroska-avoid-negative-ts b/tests/ref/fate/matroska-avoid-negative-ts
index a687c8f63c..1b9b2f2786 100644
--- a/tests/ref/fate/matroska-avoid-negative-ts
+++ b/tests/ref/fate/matroska-avoid-negative-ts
@@ -1,4 +1,4 @@
-3349536550047c5c553215003ba2acb7 *tests/data/fate/matroska-avoid-negative-ts.matroska
+90cf5a330659140d47ec11208f525908 *tests/data/fate/matroska-avoid-negative-ts.matroska
973070 tests/data/fate/matroska-avoid-negative-ts.matroska
#extradata 0: 22, 0x2885037c
#tb 0: 1/1000
@@ -12,11 +12,11 @@
#sample_rate 1: 44100
#channel_layout 1: 4
#channel_layout_name 1: mono
-0, -37, 24, 40, 9156, 0xe5bd034a, S=1, 40
+0, -37, 43, 40, 9156, 0xe5bd034a, S=1, 40
1, 0, 0, 26, 417, 0x7198c15e
0, 3, 3, 40, 1740, 0x29ac4480, F=0x0
-0, 24, 123, 40, 3672, 0x98652013, F=0x0
1, 26, 26, 26, 417, 0x3c67c32d
+0, 43, 123, 40, 3672, 0x98652013, F=0x0
1, 52, 52, 26, 417, 0x8c24b1ca
1, 78, 78, 26, 417, 0x6ee576b7
0, 83, 83, 40, 2532, 0xa2c42769, F=0x0
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH v2 5/6] avformat/mux: Peek into the muxing queue for avoid_negative_ts
[not found] ` <20220119212940.1071477-1-andreas.rheinhardt@outlook.com>
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 3/6] avformat/avformat: Add AVFMT_AVOID_NEG_TS_DISABLED Andreas Rheinhardt
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 4/6] avformat/mux: Preserve sync even if later packet has negative ts Andreas Rheinhardt
@ 2022-01-19 21:29 ` Andreas Rheinhardt
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 6/6] avformat/hls: Remove redundant cast Andreas Rheinhardt
3 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-01-19 21:29 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Peeking into the muxing queue can improve the estimate of
the lowest timestamp needed for avoid_negative_ts in case
the lowest timestamp is in a packet other than the first packet
to be muxed.
This fixes tickets #4536 and #5784 as well as the output from
the matroska-avoid-negative-ts FATE-test.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavformat/avformat.h | 2 +-
libavformat/mux.c | 21 +++++++++++++++++++--
tests/fate/matroska.mak | 2 --
tests/ref/fate/matroska-avoid-negative-ts | 2 +-
4 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index cd253fb28e..b4b8075ae6 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1527,7 +1527,7 @@ typedef struct AVFormatContext {
/**
* Avoid negative timestamps during muxing.
* Any value of the AVFMT_AVOID_NEG_TS_* constants.
- * Note, this only works when using av_interleaved_write_frame. (interleave_packet_per_dts is in use)
+ * Note, this works better when using av_interleaved_write_frame().
* - muxing: Set by user
* - demuxing: unused
*/
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 0810b674a7..53eb56f0af 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -655,16 +655,33 @@ static void handle_avoid_negative_ts(FFFormatContext *si, FFStream *sti,
if (si->avoid_negative_ts_status == AVOID_NEGATIVE_TS_UNKNOWN) {
int use_pts = si->avoid_negative_ts_use_pts;
int64_t ts = use_pts ? pkt->pts : pkt->dts;
+ AVRational tb = sti->pub.time_base;
if (ts == AV_NOPTS_VALUE)
return;
+
+ /* Peek into the muxing queue to improve our estimate
+ * of the lowest timestamp if av_interleaved_write_frame() is used. */
+ for (const PacketListEntry *pktl = si->packet_buffer.head;
+ pktl; pktl = pktl->next) {
+ AVRational cmp_tb = s->streams[pktl->pkt.stream_index]->time_base;
+ int64_t cmp_ts = use_pts ? pktl->pkt.pts : pktl->pkt.dts;
+ if (cmp_ts == AV_NOPTS_VALUE)
+ continue;
+ if (s->output_ts_offset)
+ cmp_ts += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, cmp_tb);
+ if (av_compare_ts(cmp_ts, cmp_tb, ts, tb) < 0) {
+ ts = cmp_ts;
+ tb = cmp_tb;
+ }
+ }
+
if (ts < 0 ||
ts > 0 && s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO) {
for (unsigned i = 0; i < s->nb_streams; i++) {
AVStream *const st2 = s->streams[i];
FFStream *const sti2 = ffstream(st2);
- sti2->mux_ts_offset = av_rescale_q_rnd(-ts,
- sti->pub.time_base,
+ sti2->mux_ts_offset = av_rescale_q_rnd(-ts, tb,
st2->time_base,
AV_ROUND_UP);
}
diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak
index da1fdbd5ea..784b55f6e0 100644
--- a/tests/fate/matroska.mak
+++ b/tests/fate/matroska.mak
@@ -94,8 +94,6 @@ fate-matroska-dovi-write-config7: CMD = transcode mov $(TARGET_SAMPLES)/mov/dovi
# the first packet (with the overall lowest dts) is a video packet,
# whereas an audio packet to be muxed later has the overall lowest pts
# which happens to be negative and therefore needs to be shifted.
-# This is currently buggy (the timestamps are not shifted properly:
-# the first audio packet has negative pts).
# (-ss 1.09 ensures that a video frame has the lowest dts of all packets;
# yet there is an audio packet with the overall lowest pts. output_ts_offset
# makes the pts of the audio packet, but not the leading video packet negative
diff --git a/tests/ref/fate/matroska-avoid-negative-ts b/tests/ref/fate/matroska-avoid-negative-ts
index 1b9b2f2786..02790a3985 100644
--- a/tests/ref/fate/matroska-avoid-negative-ts
+++ b/tests/ref/fate/matroska-avoid-negative-ts
@@ -1,4 +1,4 @@
-90cf5a330659140d47ec11208f525908 *tests/data/fate/matroska-avoid-negative-ts.matroska
+804842437b2be0a1604ce33c6b08c800 *tests/data/fate/matroska-avoid-negative-ts.matroska
973070 tests/data/fate/matroska-avoid-negative-ts.matroska
#extradata 0: 22, 0x2885037c
#tb 0: 1/1000
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH v2 6/6] avformat/hls: Remove redundant cast
[not found] ` <20220119212940.1071477-1-andreas.rheinhardt@outlook.com>
` (2 preceding siblings ...)
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 5/6] avformat/mux: Peek into the muxing queue for avoid_negative_ts Andreas Rheinhardt
@ 2022-01-19 21:29 ` Andreas Rheinhardt
3 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-01-19 21:29 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavformat/hls.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavformat/hls.c b/libavformat/hls.c
index 8c526f748f..4568e72cb2 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -2024,7 +2024,7 @@ static int hls_read_header(AVFormatContext *s)
if (seg && seg->key_type == KEY_SAMPLE_AES && pls->is_id3_timestamped &&
pls->audio_setup_info.codec_id != AV_CODEC_ID_NONE) {
void *iter = NULL;
- while ((in_fmt = (const AVInputFormat *)av_demuxer_iterate(&iter)))
+ while ((in_fmt = av_demuxer_iterate(&iter)))
if (in_fmt->raw_codec_id == pls->audio_setup_info.codec_id)
break;
} else {
--
2.32.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 1/6] avformat/mux: Remove assert based on faulty assumptions
2022-01-19 21:19 [FFmpeg-devel] [PATCH v2 1/6] avformat/mux: Remove assert based on faulty assumptions Andreas Rheinhardt
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 2/6] fate/matroska: Add test for avoiding negative timestamps Andreas Rheinhardt
[not found] ` <20220119212940.1071477-1-andreas.rheinhardt@outlook.com>
@ 2022-01-21 12:14 ` Andreas Rheinhardt
2 siblings, 0 replies; 7+ messages in thread
From: Andreas Rheinhardt @ 2022-01-21 12:14 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> This assert is based upon the wrong assumption that
> the noninterleaved codepath is never used; if it is used,
> max_interleave_delta is irrelevant. It furthermore
> ignores audio_preload.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavformat/mux.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index c387f8ec6e..e34fd88f05 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -697,7 +697,6 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
> );
> }
> } else {
> - av_assert2(pkt->dts == AV_NOPTS_VALUE || pkt->dts >= 0 || s->max_interleave_delta > 0);
> if (pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) {
> av_log(s, AV_LOG_WARNING,
> "Packets poorly interleaved, failed to avoid negative "
>
Will apply this patchset tomorrow unless there are objections.
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-01-21 12:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-19 21:19 [FFmpeg-devel] [PATCH v2 1/6] avformat/mux: Remove assert based on faulty assumptions Andreas Rheinhardt
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 2/6] fate/matroska: Add test for avoiding negative timestamps Andreas Rheinhardt
[not found] ` <20220119212940.1071477-1-andreas.rheinhardt@outlook.com>
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 3/6] avformat/avformat: Add AVFMT_AVOID_NEG_TS_DISABLED Andreas Rheinhardt
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 4/6] avformat/mux: Preserve sync even if later packet has negative ts Andreas Rheinhardt
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 5/6] avformat/mux: Peek into the muxing queue for avoid_negative_ts Andreas Rheinhardt
2022-01-19 21:29 ` [FFmpeg-devel] [PATCH v2 6/6] avformat/hls: Remove redundant cast Andreas Rheinhardt
2022-01-21 12:14 ` [FFmpeg-devel] [PATCH v2 1/6] avformat/mux: Remove assert based on faulty assumptions Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git