X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mux.cpp;h=b1b9db683081528e8aa15c640288e0d8a2d5b9e6;hb=8e86ae071c057a26e933b8452ac541050ba2cb9f;hp=cfe38b63a67041eb2a6f0f3b7cb0b1cec945f490;hpb=eedf61e845d7f5aab0ec8ce79efd19d6bfe686f2;p=nageru diff --git a/mux.cpp b/mux.cpp index cfe38b6..b1b9db6 100644 --- a/mux.cpp +++ b/mux.cpp @@ -145,18 +145,22 @@ Mux::~Mux() avformat_free_context(avctx); } -void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts, AVRational timebase) +void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts, AVRational timebase, int stream_index_override) { AVPacket pkt_copy; - if (av_copy_packet(&pkt_copy, &pkt) < 0) { + av_init_packet(&pkt_copy); + if (av_packet_ref(&pkt_copy, &pkt) < 0) { fprintf(stderr, "av_copy_packet() failed\n"); exit(1); } - if (pkt.stream_index == 0) { + if (stream_index_override != -1) { + pkt_copy.stream_index = stream_index_override; + } + if (pkt_copy.stream_index == 0) { pkt_copy.pts = av_rescale_q(pts, timebase, avstream_video->time_base); pkt_copy.dts = av_rescale_q(dts, timebase, avstream_video->time_base); pkt_copy.duration = av_rescale_q(pkt.duration, timebase, avstream_video->time_base); - } else if (pkt.stream_index == 1) { + } else if (pkt_copy.stream_index == 1) { pkt_copy.pts = av_rescale_q(pts, timebase, avstream_audio->time_base); pkt_copy.dts = av_rescale_q(dts, timebase, avstream_audio->time_base); pkt_copy.duration = av_rescale_q(pkt.duration, timebase, avstream_audio->time_base);