X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mux.cpp;h=b1b9db683081528e8aa15c640288e0d8a2d5b9e6;hb=refs%2Ftags%2F1.7.4;hp=5c6a150edd80e80e1e2825e6ab1d012f1a33253f;hpb=f932301ce7f23ef4c14dd0d4f52dee662d0b4ef6;p=nageru diff --git a/mux.cpp b/mux.cpp index 5c6a150..b1b9db6 100644 --- a/mux.cpp +++ b/mux.cpp @@ -75,7 +75,7 @@ Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const // Note that there's no way to change this per-frame as the H.264 stream // would like to be able to. avstream_video->codecpar->color_primaries = AVCOL_PRI_BT709; // RGB colorspace (inout_format.color_space). - avstream_video->codecpar->color_trc = AVCOL_TRC_UNSPECIFIED; // Gamma curve (inout_format.gamma_curve). + avstream_video->codecpar->color_trc = AVCOL_TRC_IEC61966_2_1; // Gamma curve (inout_format.gamma_curve). // YUV colorspace (output_ycbcr_format.luma_coefficients). if (global_flags.ycbcr_rec709_coefficients) { avstream_video->codecpar->color_space = AVCOL_SPC_BT709; @@ -145,21 +145,25 @@ Mux::~Mux() avformat_free_context(avctx); } -void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts) +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) { - pkt_copy.pts = av_rescale_q(pts, AVRational{1, TIMEBASE}, avstream_video->time_base); - pkt_copy.dts = av_rescale_q(dts, AVRational{1, TIMEBASE}, avstream_video->time_base); - pkt_copy.duration = av_rescale_q(pkt.duration, AVRational{1, TIMEBASE}, avstream_video->time_base); - } else if (pkt.stream_index == 1) { - pkt_copy.pts = av_rescale_q(pts, AVRational{1, TIMEBASE}, avstream_audio->time_base); - pkt_copy.dts = av_rescale_q(dts, AVRational{1, TIMEBASE}, avstream_audio->time_base); - pkt_copy.duration = av_rescale_q(pkt.duration, AVRational{1, 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); }