Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] fix rounding errors in .ass subtitles format timings
@ 2023-11-21 13:38 Muhammed
  2024-01-01 15:11 ` Muhammed
  2024-01-01 15:23 ` Muhammed
  0 siblings, 2 replies; 4+ messages in thread
From: Muhammed @ 2023-11-21 13:38 UTC (permalink / raw)
  To: ffmpeg-devel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-01 15:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21 13:38 [FFmpeg-devel] [PATCH] fix rounding errors in .ass subtitles format timings Muhammed
2024-01-01 15:11 ` Muhammed
2024-01-01 15:23 ` Muhammed
2024-01-01 15:28   ` Muhammed

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