Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Miguel Borges de Freitas <ffmpegagent@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Miguel Borges de Freitas <enen92@kodi.tv>,
	Miguel Borges de Freitas <92enen@gmail.com>
Subject: [FFmpeg-devel] [PATCH 1/2] libavformat/matroskadec: set fixed duration for subtitles
Date: Tue, 10 Jan 2023 15:42:07 +0000
Message-ID: <5985bf780ecddd2a608537c4cf91d4514660b8da.1673365329.git.ffmpegagent@gmail.com> (raw)
In-Reply-To: <pull.48.ffstaging.FFmpeg.1673365328.ffmpegagent@gmail.com>

From: Miguel Borges de Freitas <enen92@kodi.tv>

The matroska specification states the start time and duration of
subtitle entries are encoded in the block TimeStamp
and BlockDuration. Furthermore, for all subtitle formats except
S_HDMV/PGS the BlockDuration must always be defined and have an
absolute value even if it is simply 0. ffmpeg assumes that a duration
of 0 means the duration is still unknown and tries to adjust based on
the next packet pts. This is wrong for all formats except S_HDMV/PGS.
Since changing the semantics of duration 0 is not an option (touches
too many parts of the code) this change introduces
AV_PKT_FLAG_FIXED_DURATION flag which decoders might use to flag the
duration of a given packet should not be changed.

Signed-off-by: Miguel Borges de Freitas <enen92@kodi.tv>
---
 libavcodec/packet.h       | 5 +++++
 libavformat/demux.c       | 3 ++-
 libavformat/matroskadec.c | 4 ++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index f28e7e7011..699dcc6f79 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -446,6 +446,11 @@ typedef struct AVPacketList {
  * be discarded by the decoder.  I.e. Non-reference frames.
  */
 #define AV_PKT_FLAG_DISPOSABLE 0x0010
+/**
+ * Flag is used to indicate packets in which the duration is absolute
+ * and should not be changed.
+ */
+#define AV_PKT_FLAG_FIXED_DURATION 0x0020
 
 enum AVSideDataParamChangeFlags {
 #if FF_API_OLD_CHANNEL_LAYOUT
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 2dfd82a63c..471be5d3dd 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -914,7 +914,8 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st,
             pktl->pkt.dts = cur_dts;
             if (!sti->avctx->has_b_frames)
                 pktl->pkt.pts = cur_dts;
-            pktl->pkt.duration = duration;
+            if ((pktl->pkt.flags & AV_PKT_FLAG_FIXED_DURATION) != AV_PKT_FLAG_FIXED_DURATION)
+                pktl->pkt.duration = duration;
         } else
             break;
         cur_dts = pktl->pkt.dts + pktl->pkt.duration;
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d582f566a2..e887f43e1a 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3673,6 +3673,10 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
     pkt->pos = pos;
     pkt->duration = lace_duration;
 
+    if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE && 
+        st->codecpar->codec_id != AV_CODEC_ID_HDMV_PGS_SUBTITLE)
+        pkt->flags |= AV_PKT_FLAG_FIXED_DURATION;
+
     res = avpriv_packet_list_put(&matroska->queue, pkt, NULL, 0);
     if (res < 0) {
         av_packet_unref(pkt);
-- 
ffmpeg-codebot

_______________________________________________
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".

  reply	other threads:[~2023-01-10 15:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10 15:42 [FFmpeg-devel] [PATCH 0/2] " ffmpegagent
2023-01-10 15:42 ` Miguel Borges de Freitas [this message]
2023-01-10 15:42 ` [FFmpeg-devel] [PATCH 2/2] fate: update test reference data to include AV_PKT_FLAG_FIXED_DURATION Miguel Borges de Freitas
2023-01-22 18:21 ` [FFmpeg-devel] [PATCH 0/2] libavformat/matroskadec: set fixed duration for subtitles Miguel Borges de Freitas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5985bf780ecddd2a608537c4cf91d4514660b8da.1673365329.git.ffmpegagent@gmail.com \
    --to=ffmpegagent@gmail.com \
    --cc=92enen@gmail.com \
    --cc=enen92@kodi.tv \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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