diff mbox series

[FFmpeg-devel] fix rounding errors in .ass subtitles format timings

Message ID b99ef82d-95e7-45ed-b62c-d667b72f187f@gmail.com
State New
Headers show
Series [FFmpeg-devel] fix rounding errors in .ass subtitles format timings | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch
yinshiyou/configure_loongarch64 warning Failed to apply patch

Commit Message

Muhammed Nov. 21, 2023, 1:38 p.m. UTC
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(+)

   */

Comments

Muhammed Jan. 1, 2024, 3:11 p.m. UTC | #1
Would appreciate it if someone could look at this.
Muhammed Jan. 1, 2024, 3:23 p.m. UTC | #2
Would appreciate it if someone could look at this.
Muhammed Jan. 1, 2024, 3:28 p.m. UTC | #3
for some reason the reply mailto link didn't work properly. sorry for 
spamming.
here's the patch: 
https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2023-November/317250.html
diff mbox series

Patch

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);
+
  /**
   * @}