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");
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) {