diff --git a/libavformat/mux.c b/libavformat/mux.c index e9973edd08..a427f4659b 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -657,6 +657,10 @@ FF_ENABLE_DEPRECATION_WARNINGS static int write_packet(AVFormatContext *s, AVPacket *pkt) { int ret, did_split; + int64_t pts_backup, dts_backup; + + pts_backup = pkt->pts; + dts_backup = pkt->dts; if (s->output_ts_offset) { AVStream *st = s->streams[pkt->stream_index]; @@ -743,6 +747,11 @@ fail: if (did_split) av_packet_merge_side_data(pkt); + if (ret < 0) { + pkt->pts = pts_backup; + pkt->dts = dts_backup; + } + return ret; }