Opened 13 years ago

Closed 12 years ago

#177 closed defect (fixed)

"non monotone timestamps" error patch

Reported by: andrixnet Owned by:
Priority: minor Component: avformat
Version: unspecified Keywords: mkv av_interleaved_write_frame
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I have been using this patch for some time now, and so far I haven't had problems with the streams produced by FFMPEG.

It has long been discussed on the internet, mailing lists, forums, etc, about people having problems with some files when they tried converting them with FFMPEG. The error reported was :
"non monotone timestamps 123>=123"
The test is a sane one, but including the equality in the test breaks usability with lots of cases like DTS audio in the source, or simply having a multi language audio MKV.

While FFMPEG was able to read the input, it was unable to produce a proper multi language audio output.
The attached patch is based on a suggestion I read on a forum and I am submitting it to the developers for consideration.

My question is : why that test has to be >= instead of > ?

Upon request I can provide some streams with multiple audio that are not convertable because of this.

Attachments (1)

ffmpeg-0.5_utils.c.patch (508 bytes ) - added by andrixnet 13 years ago.

Download all attachments as: .zip

Change History (9)

by andrixnet, 13 years ago

Attachment: ffmpeg-0.5_utils.c.patch added

comment:1 by tracey jaquith, 13 years ago

For what it's worth, I have had the *exact* same issues here at archive.org
I've made our own patch to "move on if = timestamps" due to *way too common*
hitting this and failing transcodes on AAC source audio inputs, especially.

++ for your patch idea

[michael / bug owner -- in case helpful, this ~169MB file is a nice poster child http://www.archive.org/download/Xacti1010_trim2_test_2010_02_04/Xacti1010_trim2_test_2010_02_04.mp4 ]

Last edited 13 years ago by tracey jaquith (previous) (diff)

comment:2 by Michael Niedermayer, 13 years ago

Status: newopen

the patch needs to be updated, adding AVFMT_TS_NONSTRICT to formats that support it is what it should do

comment:3 by Michael Niedermayer, 13 years ago

Owner: Michael Niedermayer removed

comment:4 by Roger Pack, 13 years ago

I'm interested in this...I'd like to offer a small bounty $75 for an accepted patch. That'll be my contribution :)
-roger-

in reply to:  2 comment:5 by andrixnet, 13 years ago

Replying to michael:

the patch needs to be updated, adding AVFMT_TS_NONSTRICT to formats that support it is what it should do

If anyone could help improve the patch, my knowledge of ffmpeg internals is too limited. Thanks.

comment:6 by andrixnet, 13 years ago

Taken from ~alien builds for Slackware :

http://connie.slackware.com/~alien/slackbuilds/ffmpeg/build/ffmpeg-HEAD-VP8_param_mapping.diff

Seems to do the job nicely, with the additions as michael said.

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 767356a..17418bc 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -258,6 +258,9 @@ typedef struct AVFormatParameters {
 #define AVFMT_VARIABLE_FPS  0x0400 /**< Format allows variable fps. */
 #define AVFMT_NODIMENSIONS  0x0800 /**< Format does not need width/height */
 #define AVFMT_NOSTREAMS     0x1000 /**< Format does not require any streams */
+#define AVFMT_TS_NONSTRICT  0x2000 /**< Format does not require strictly
+                                        increasing timestamps, but they must
+                                        still be monotonic */
 
 typedef struct AVOutputFormat {
     const char *name;
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 5e4552a..2c846c8 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1199,7 +1199,7 @@ AVOutputFormat ff_webm_muxer = {
     mkv_write_header,
     mkv_write_packet,
     mkv_write_trailer,
-    .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
+    .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,
 };
 #endif
 
diff --git a/libavformat/utils.c b/libavformat/utils.c
index e7ce911..bc9d38f 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2901,7 +2901,7 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt){
         pkt->dts= st->pts_buffer[0];
     }
 
-    if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){
+    if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)){
         av_log(s, AV_LOG_ERROR,
                "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %"PRId64" >= %"PRId64"\n",
                st->index, st->cur_dts, pkt->dts);

comment:7 by Damian, 13 years ago

See also: https://ffmpeg.org/trac/ffmpeg/ticket/415. Can the AVFMT_TS_NONSTRICT flag also be applied to the mp4/mov container formats?

comment:8 by Carl Eugen Hoyos, 12 years ago

Component: FFmpegavformat
Keywords: mkv av_interleaved_write_frame added; monotone timestamp removed
Resolution: fixed
Status: openclosed

The patch was applied.

Note: See TracTickets for help on using tickets.