From 4b41f5983b5196589cb1ef6fa2bc0b93d28b8732 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 1 Apr 2016 10:34:32 +0200 Subject: [PATCH] Start a mux only on a keyframe, so that transcoding clients do not get too confused. --- httpd.cpp | 6 ++++++ httpd.h | 1 + 2 files changed, 7 insertions(+) diff --git a/httpd.cpp b/httpd.cpp index b9b1d6f..6a92699 100644 --- a/httpd.cpp +++ b/httpd.cpp @@ -196,6 +196,12 @@ HTTPD::Mux::~Mux() void HTTPD::Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts) { + if (!seen_keyframe && !(pkt.stream_index == 0 && (pkt.flags & AV_PKT_FLAG_KEY))) { + // Wait until we see the first (video) key frame. + return; + } + seen_keyframe = true; + AVPacket pkt_copy; av_copy_packet(&pkt_copy, &pkt); if (pkt.stream_index == 0) { diff --git a/httpd.h b/httpd.h index e739f70..88aeecc 100644 --- a/httpd.h +++ b/httpd.h @@ -61,6 +61,7 @@ private: void add_packet(const AVPacket &pkt, int64_t pts, int64_t dts); private: + bool seen_keyframe = false; AVFormatContext *avctx; AVStream *avstream_video, *avstream_audio; }; -- 2.39.2