From db9d3c39a1bccc0a67507234e964e2a9991a4aba Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Sun, 28 Aug 2016 11:24:15 +0300 Subject: [PATCH] handling some cases of wrong pts/dts --- main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.cpp b/main.cpp index 0830a8e..87300ee 100644 --- a/main.cpp +++ b/main.cpp @@ -78,6 +78,7 @@ int main(int argc, char** argv) { AVFrame* frame = nullptr; int gotPicture = 0, gotPacket = 0, decodedFrames = 1; + int64_t oldPts = 0, oldDts = 0; while(true) { AVPacket packet; packet.data = nullptr; @@ -112,6 +113,20 @@ int main(int argc, char** argv) { if(res < 0) break; if(!gotPacket) continue; + // try to recover in case of bad pts/dts + if(encPacket.pts < encPacket.dts) { + encPacket.dts = encPacket.pts; + } + + if(encPacket.pts < oldPts) + encPacket.pts = oldPts; + + if(encPacket.dts < oldDts) + encPacket.dts = oldDts; + + oldPts = encPacket.pts; + oldDts = encPacket.dts; + av_packet_rescale_ts(&encPacket, videoStream->time_base, outVideoStream->time_base); res = av_interleaved_write_frame(outFmtCtx, &encPacket);