]> git.sesse.net Git - nageru/blobdiff - mux.cpp
Release Nageru 1.7.4.
[nageru] / mux.cpp
diff --git a/mux.cpp b/mux.cpp
index e554ec5de0c694481c9e8fec9fa2116016d6bb7a..b1b9db683081528e8aa15c640288e0d8a2d5b9e6 100644 (file)
--- a/mux.cpp
+++ b/mux.cpp
@@ -145,7 +145,7 @@ 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;
        av_init_packet(&pkt_copy);
@@ -153,10 +153,17 @@ void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts, AVRational t
                fprintf(stderr, "av_copy_packet() failed\n");
                exit(1);
        }
-       if (pkt.stream_index == 0) {
-               av_packet_rescale_ts(&pkt_copy, timebase, avstream_video->time_base);
-       } else if (pkt.stream_index == 1) {
-               av_packet_rescale_ts(&pkt_copy, timebase, avstream_audio->time_base);
+       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_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);
        } else {
                assert(false);
        }