Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Muhammed <mohammedkaabi64@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] fix rounding errors in .ass subtitles format timings
Date: Tue, 21 Nov 2023 16:38:08 +0300
Message-ID: <b99ef82d-95e7-45ed-b62c-d667b72f187f@gmail.com> (raw)

Signed-off-by: mohad12211 <mohammedkaabi64@gmail.com>
---
  fftools/ffmpeg_mux.c  | 2 ++
  libavcodec/avpacket.c | 9 +++++++++
  libavcodec/packet.h   | 2 ++
  3 files changed, 13 insertions(+)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 30c0330..7c9f03c 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -92,6 +92,8 @@ static int write_packet(Muxer *mux, OutputStream *ost, 
AVPacket *pkt)
          pkt->pts = pkt->dts;
           pkt->duration = av_rescale_q(pkt->duration, pkt->time_base, 
ost->st->time_base);
+    } else if (ost->type == AVMEDIA_TYPE_SUBTITLE && 
ost->par_in->codec_id == AV_CODEC_ID_ASS) {
+        av_packet_rescale_ts_end(pkt, pkt->time_base, ost->st->time_base);
      } else
          av_packet_rescale_ts(pkt, pkt->time_base, ost->st->time_base);
      pkt->time_base = ost->st->time_base;
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index e29725c..3926590 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -524,6 +524,15 @@ int av_packet_make_writable(AVPacket *pkt)
      return 0;
  }
  +void av_packet_rescale_ts_end(AVPacket *pkt, AVRational src_tb, 
AVRational dst_tb)
+{
+    int64_t old_pts = pkt->pts;
+    pkt->pts = av_rescale_q(pkt->pts, src_tb, dst_tb);
+    if (pkt->dts != AV_NOPTS_VALUE)
+        pkt->dts = av_rescale_q(pkt->dts, src_tb, dst_tb);
+    pkt->duration = av_rescale_q(pkt->duration + old_pts, src_tb, 
dst_tb) - pkt->pts;
+}
+
  void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational 
dst_tb)
  {
      if (pkt->pts != AV_NOPTS_VALUE)
diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index b19409b..49be5cd 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -839,6 +839,8 @@ int av_packet_make_writable(AVPacket *pkt);
   */
  void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational 
tb_dst);
  +void av_packet_rescale_ts_end(AVPacket *pkt, AVRational tb_src, 
AVRational tb_dst);
+
  /**
   * @}
   */
-- 
2.42.1

My proposed fix for https://trac.ffmpeg.org/ticket/10659

_______________________________________________
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-11-21 13:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21 13:38 Muhammed [this message]
2024-01-01 15:11 ` Muhammed
2024-01-01 15:23 ` Muhammed
2024-01-01 15:28   ` Muhammed

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=b99ef82d-95e7-45ed-b62c-d667b72f187f@gmail.com \
    --to=mohammedkaabi64@gmail.com \
    --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