diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 7a924db..180fa42 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -91,6 +91,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);
+
 /**
  * @}
  */
