Implement last_dts[] because next_dts[] isn't actually useful. This fixes another ffmpeg deprecation problem by keep our own copy of cur_dts

pull/3466/head
Isaac Connor 2022-04-07 13:12:34 -04:00
parent 55efd859c3
commit 2b1aa90b8e
2 changed files with 19 additions and 9 deletions

View File

@ -391,6 +391,8 @@ bool VideoStore::open() {
} // end if video_in_stream } // end if video_in_stream
max_stream_index = video_out_stream->index; max_stream_index = video_out_stream->index;
last_dts[video_out_stream->index] = AV_NOPTS_VALUE;
video_out_stream->time_base = video_in_stream ? video_in_stream->time_base : AV_TIME_BASE_Q; video_out_stream->time_base = video_in_stream ? video_in_stream->time_base : AV_TIME_BASE_Q;
if (audio_in_stream and audio_in_ctx) { if (audio_in_stream and audio_in_ctx) {
@ -472,6 +474,7 @@ bool VideoStore::open() {
// We will assume that subsequent stream allocations will increase the index // We will assume that subsequent stream allocations will increase the index
max_stream_index = audio_out_stream->index; max_stream_index = audio_out_stream->index;
last_dts[audio_out_stream->index] = AV_NOPTS_VALUE;
} // end if audio_in_stream } // end if audio_in_stream
//max_stream_index is 0-based, so add 1 //max_stream_index is 0-based, so add 1
@ -1239,15 +1242,19 @@ int VideoStore::write_packet(AVPacket *pkt, AVStream *stream) {
} }
#else #else
if (pkt->dts == AV_NOPTS_VALUE) { if (pkt->dts == AV_NOPTS_VALUE) {
Error("undefined dts"); if (last_dts[stream->index] == AV_NOPTS_VALUE) {
// Debug(1, "undef dts, fixing by setting to stream cur_dts %" PRId64, stream->cur_dts); last_dts[stream->index] = 0;
// pkt->dts = stream->cur_dts; }
} else if (pkt->dts < next_dts[stream->index]) { pkt->dts = last_dts[stream->index];
Debug(1, "non increasing dts, fixing. our dts %" PRId64 " stream next_dts %" PRId64, pkt->dts, next_dts[stream->index]); } else if (pkt->dts < last_dts[stream->index]) {
pkt->dts = next_dts[stream->index]; Warning("non increasing dts, fixing. our dts %" PRId64 " stream %d next_dts %" PRId64,
pkt->dts, stream->index, next_dts[stream->index]);
pkt->dts = last_dts[stream->index];
} }
if (pkt->dts > pkt->pts) { if (pkt->pts == AV_NOPTS_VALUE) {
pkt->pts = pkt->dts;
} else if (pkt->dts > pkt->pts) {
Warning("pkt.dts(%" PRId64 ") must be <= pkt.pts(%" PRId64 ")." Warning("pkt.dts(%" PRId64 ") must be <= pkt.pts(%" PRId64 ")."
"Decompression must happen before presentation.", "Decompression must happen before presentation.",
pkt->dts, pkt->pts); pkt->dts, pkt->pts);
@ -1261,8 +1268,9 @@ int VideoStore::write_packet(AVPacket *pkt, AVStream *stream) {
ZM_DUMP_STREAM_PACKET(stream, (*pkt), "finished pkt"); ZM_DUMP_STREAM_PACKET(stream, (*pkt), "finished pkt");
next_dts[stream->index] = pkt->dts + pkt->duration; next_dts[stream->index] = pkt->dts + pkt->duration;
Debug(3, "next_dts for stream %d has become %" PRId64, last_dts[stream->index] = pkt->dts;
stream->index, next_dts[stream->index]); Debug(3, "next_dts for stream %d has become %" PRId64 " last_dts %" PRId64,
stream->index, next_dts[stream->index], last_dts[stream->index]);
int ret = av_interleaved_write_frame(oc, pkt); int ret = av_interleaved_write_frame(oc, pkt);
if (ret != 0) { if (ret != 0) {

View File

@ -7,6 +7,7 @@
#include "zm_swscale.h" #include "zm_swscale.h"
#include <memory> #include <memory>
#include <map>
extern "C" { extern "C" {
#include <libswresample/swresample.h> #include <libswresample/swresample.h>
@ -85,6 +86,7 @@ class VideoStore {
// These are for out, should start at zero. We assume they do not wrap because we just aren't going to save files that big. // These are for out, should start at zero. We assume they do not wrap because we just aren't going to save files that big.
int64_t *next_dts; int64_t *next_dts;
std::map<int, int64_t> last_dts;
int64_t audio_next_pts; int64_t audio_next_pts;
int max_stream_index; int max_stream_index;