Handle null video_in_ctx. Better debug. Always flush codecs

This commit is contained in:
Isaac Connor 2021-01-26 12:24:43 -05:00
parent e73e6aaabc
commit a209d493ef
1 changed files with 6 additions and 9 deletions

View File

@ -161,7 +161,7 @@ bool VideoStore::open() {
wanted_codec = AV_CODEC_ID_H264; wanted_codec = AV_CODEC_ID_H264;
// FIXME what is the optimal codec? Probably low latency h264 which is effectively mjpeg // FIXME what is the optimal codec? Probably low latency h264 which is effectively mjpeg
} else { } else {
Debug(2, "Codec is %d, wanted %d", video_in_ctx->codec_id, wanted_codec); Debug(2, "Codec wanted %d", wanted_codec);
} }
std::string wanted_encoder = monitor->Encoder(); std::string wanted_encoder = monitor->Encoder();
@ -192,7 +192,7 @@ bool VideoStore::open() {
#endif #endif
} }
video_out_ctx->time_base = video_in_ctx->time_base; video_out_ctx->time_base = video_in_ctx ? video_in_ctx->time_base : AV_TIME_BASE_Q;
if ( ! (video_out_ctx->time_base.num && video_out_ctx->time_base.den) ) { if ( ! (video_out_ctx->time_base.num && video_out_ctx->time_base.den) ) {
Debug(2, "No timebase found in video in context, defaulting to Q which is microseconds"); Debug(2, "No timebase found in video in context, defaulting to Q which is microseconds");
video_out_ctx->time_base = AV_TIME_BASE_Q; video_out_ctx->time_base = AV_TIME_BASE_Q;
@ -307,7 +307,7 @@ bool VideoStore::open() {
Warning("Unsupported Orientation(%d)", orientation); Warning("Unsupported Orientation(%d)", orientation);
} }
} // end if orientation } // end if orientation
video_out_stream->time_base = AV_TIME_BASE_Q; video_out_stream->time_base = video_in_stream ? video_in_stream->time_base : AV_TIME_BASE_Q;
zm_dump_stream_format(oc, 0, 0, 1); zm_dump_stream_format(oc, 0, 0, 1);
if ( audio_in_stream ) { if ( audio_in_stream ) {
@ -587,10 +587,7 @@ void VideoStore::flush_codecs() {
VideoStore::~VideoStore() { VideoStore::~VideoStore() {
if ( oc->pb ) { if ( oc->pb ) {
if ( ( video_out_ctx->codec_id != video_in_ctx->codec_id ) || audio_out_codec ) {
Debug(2, "Different codecs between in and out. flushing codecs");
flush_codecs(); flush_codecs();
} // end if buffers
// Flush Queues // Flush Queues
Debug(1, "Flushing interleaved queues"); Debug(1, "Flushing interleaved queues");
@ -1211,7 +1208,6 @@ int VideoStore::writeAudioFramePacket(ZMPacket *zm_packet) {
} // end while there is data in the resampler } // end while there is data in the resampler
} else { } else {
Debug(2, "copying");
av_init_packet(&opkt); av_init_packet(&opkt);
opkt.data = ipkt->data; opkt.data = ipkt->data;
opkt.size = ipkt->size; opkt.size = ipkt->size;
@ -1221,6 +1217,7 @@ int VideoStore::writeAudioFramePacket(ZMPacket *zm_packet) {
opkt.pts = ipkt->pts; opkt.pts = ipkt->pts;
opkt.dts = ipkt->dts; opkt.dts = ipkt->dts;
av_packet_rescale_ts(&opkt, audio_in_stream->time_base, audio_out_stream->time_base); av_packet_rescale_ts(&opkt, audio_in_stream->time_base, audio_out_stream->time_base);
dumpPacket(audio_out_stream, &opkt, "after stream pts adjustment");
write_packet(&opkt, audio_out_stream); write_packet(&opkt, audio_out_stream);
zm_av_packet_unref(&opkt); zm_av_packet_unref(&opkt);
@ -1281,7 +1278,7 @@ int VideoStore::write_packet(AVPacket *pkt, AVStream *stream) {
Error("Error writing packet: %s", Error("Error writing packet: %s",
av_make_error_string(ret).c_str()); av_make_error_string(ret).c_str());
} else { } else {
Debug(2, "Success writing packet"); Debug(4, "Success writing packet");
} }
return ret; return ret;
} // end int VideoStore::write_packet(AVPacket *pkt, AVStream *stream) } // end int VideoStore::write_packet(AVPacket *pkt, AVStream *stream)