handling some cases of wrong pts/dts

This commit is contained in:
Selim Mustafaev 2016-08-28 11:24:15 +03:00
parent 141e8bdd4c
commit db9d3c39a1

View File

@ -78,6 +78,7 @@ int main(int argc, char** argv) {
AVFrame* frame = nullptr; AVFrame* frame = nullptr;
int gotPicture = 0, gotPacket = 0, decodedFrames = 1; int gotPicture = 0, gotPacket = 0, decodedFrames = 1;
int64_t oldPts = 0, oldDts = 0;
while(true) { while(true) {
AVPacket packet; AVPacket packet;
packet.data = nullptr; packet.data = nullptr;
@ -112,6 +113,20 @@ int main(int argc, char** argv) {
if(res < 0) break; if(res < 0) break;
if(!gotPacket) continue; 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); av_packet_rescale_ts(&encPacket, videoStream->time_base, outVideoStream->time_base);
res = av_interleaved_write_frame(outFmtCtx, &encPacket); res = av_interleaved_write_frame(outFmtCtx, &encPacket);