]> git.sesse.net Git - nageru/blobdiff - shared/mux.cpp
Fix another crash with newer SVT-AV1.
[nageru] / shared / mux.cpp
index 2130752b4c98f0e8bfa5f94c228bc7a947ff215c..819638c480c04f22a98a6364ecf1b1cb59ef569c 100644 (file)
@@ -50,6 +50,13 @@ struct PacketBefore {
 Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const string &video_extradata, const AVCodecParameters *audio_codecpar, AVColorSpace color_space, int time_base, function<void(int64_t)> write_callback, WriteStrategy write_strategy, const vector<MuxMetrics *> &metrics, WithSubtitles with_subtitles)
        : write_strategy(write_strategy), avctx(avctx), write_callback(write_callback), metrics(metrics)
 {
+       // MPEG-TS ostensibly needs some conversions (e.g. for differing start codes),
+       // so let FFmpeg insert them as needed in case we are muxing to that.
+       // Curiously enough, things actually seem to go quite fine without
+       // (and it also seems FFmpeg's MPEG-TS muxer automatically does stuff like
+       // repeat PPS/SPS before keyframes for us), but it can't hurt.
+       avctx->flags |= AVFMT_FLAG_AUTO_BSF;
+
        AVStream *avstream_video = avformat_new_stream(avctx, nullptr);
        if (avstream_video == nullptr) {
                fprintf(stderr, "avformat_new_stream() failed\n");
@@ -164,6 +171,8 @@ Mux::~Mux()
 
 void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts, AVRational timebase, int stream_index_override)
 {
+       assert(pts >= dts);
+
        AVPacket pkt_copy;
        av_init_packet(&pkt_copy);
        if (av_packet_ref(&pkt_copy, &pkt) < 0) {