Opened 23 months ago

Last modified 23 months ago

#11200 new enhancement

FFmpeg unintelligently meddled input timestamps during "-c copy"

Reported by: hachi Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: Non-monotonic DTS
Cc: MasterQuestionable Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by hachi)

Summary of the bug:

FFmpeg incorrecly alters timestamps, which results in subtitles not displayed when viewing output file:

[sost#0:6/copy @ 0x127e150b0] Non-monotonic DTS; previous: 1268750, current: 150; changing to 1268750. This may result in incorrect timestamps in the output file.
[sost#0:6/copy @ 0x127e150b0] Non-monotonic DTS; previous: 1268750, current: 2020; changing to 1268750. This may result in incorrect timestamps in the output file.
[sost#0:6/copy @ 0x127e150b0] Non-monotonic DTS; previous: 1268750, current: 5070; changing to 1268750. This may result in incorrect timestamps in the output file.

I have not found an option to preserve original timestamps and bypass this error.

How to reproduce:

% cat input_*.mkv > input.mkv
% ffmpeg -i input.mkv -c copy -map 0 output.mkv

ffmpeg version 7.0.2 Copyright (c) 2000-2024 the FFmpeg developers
built with Apple clang version 15.0.0 (clang-1500.3.9.4)

Attachments (7)

input_01.mkv (2.0 MB ) - added by hachi 23 months ago.
input_02.mkv (2.0 MB ) - added by hachi 23 months ago.
input_03.mkv (1.9 MB ) - added by hachi 23 months ago.
4.sup (119.8 KB ) - added by MasterQuestionable 23 months ago.
5.ass (7.7 KB ) - added by MasterQuestionable 23 months ago.
͏    I guess this is the one of interest: ͏    Tagged default; also had alike error messages during extraction.
6.ass (8.2 KB ) - added by MasterQuestionable 23 months ago.
0.h265.xml (124.8 KB ) - added by MasterQuestionable 23 months ago.
͏    ffprobe -hide_banner -threads 0 -show_entries "frame" -select_streams v:0 -of "xml" "input.mkv" -o "0.h265.xml"

Change History (15)

comment:1 by hachi, 23 months ago

If needed I can attach a 10MB file to see how subtitles are affected

comment:2 by Balling, 23 months ago

Please do.

comment:3 by MasterQuestionable, 23 months ago

Cc: MasterQuestionable added
Component: undeterminedavformat
Keywords: Non-monotonic added; Non-monotonous removed
Summary: FFmpeg setting all timestamps to endFFmpeg unintelligently meddled input timestamps during "-c copy"
Type: defectenhancement
Version: unspecifiedgit-master

͏    Try "-copyts" whatsoever..?
͏    https://trac.ffmpeg.org/ticket/11034#comment:1

͏    Such peculiar timestamps indicated input seemingly broken.
͏    Caution that FFmpeg currently may not handle non-perfectly-valid files in the most sensible way:
͏    https://trac.ffmpeg.org/ticket/11056#comment:18

comment:4 by MasterQuestionable, 23 months ago

Keywords: timestamp removed

͏    Also, the "DTS" here likely refers presentation timestamp ("PTS"). (misuse)
͏    Non-monotonic DTS (count in presentation order) is valid involving B-frames.

͏    See also: https://trac.ffmpeg.org/ticket/11055#comment:16

comment:5 by Balling, 23 months ago

"Also, the "DTS" here likely refers presentation timestamp ("PTS"). (misuse)"

Mkv has no DTS. But here it appears that ffmpeg is generating DTS that are wrong. Each next DTS must be strictly bigger than previous one.

by hachi, 23 months ago

Attachment: input_01.mkv added

by hachi, 23 months ago

Attachment: input_02.mkv added

by hachi, 23 months ago

Attachment: input_03.mkv added

comment:6 by hachi, 23 months ago

I have uploaded a 10 seconds mkv split into 3 parts, because of the 2.5M upload limit.
To concatenate the parts simply do:
cat input_*.mkv > input.mkv

comment:7 by hachi, 23 months ago

Description: modified (diff)

comment:8 by MasterQuestionable, 23 months ago

͏    "input.mkv" is a blob of attachments... (mostly TTF, subtitles, and metadata)

͏    Same bothersome... https://trac.ffmpeg.org/ticket/10891#comment:5
͏    Anyway, I extracted some of the subtitles best-effort:

by MasterQuestionable, 23 months ago

Attachment: 4.sup added

by MasterQuestionable, 23 months ago

Attachment: 5.ass added

͏    I guess this is the one of interest:
͏    Tagged default; also had alike error messages during extraction.

by MasterQuestionable, 23 months ago

Attachment: 6.ass added

by MasterQuestionable, 23 months ago

Attachment: 0.h265.xml added

͏    ffprobe -hide_banner -threads 0 -show_entries "frame" -select_streams v:0 -of "xml" "input.mkv" -o "0.h265.xml"

Note: See TracTickets for help on using tickets.