X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mux.cpp;h=1fd8e30ba3ff836a6b92521f96cda2b91a20f611;hb=a315ebb10446bc372016bc0e9cd29d1aa3696eaa;hp=df974f0644520aa7c31ffb757abe1b733af2e480;hpb=f50d8a87fe399541b73c4e36ba2c78c4a8443447;p=nageru diff --git a/mux.cpp b/mux.cpp index df974f0..1fd8e30 100644 --- a/mux.cpp +++ b/mux.cpp @@ -1,12 +1,28 @@ -#include +#include "mux.h" +#include +#include +#include +#include +#include #include #include #include +#include #include +extern "C" { +#include +#include +#include +#include +#include +#include +#include +} + #include "defs.h" -#include "mux.h" +#include "flags.h" #include "timebase.h" using namespace std; @@ -29,8 +45,8 @@ struct PacketBefore { const AVFormatContext * const ctx; }; -Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const string &video_extradata, const AVCodecParameters *audio_codecpar, int time_base) - : avctx(avctx) +Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const string &video_extradata, const AVCodecParameters *audio_codecpar, int time_base, std::function write_callback) + : avctx(avctx), write_callback(write_callback) { avstream_video = avformat_new_stream(avctx, nullptr); if (avstream_video == nullptr) { @@ -53,9 +69,16 @@ Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const // as noted in each comment. // Note that the H.264 stream also contains this information and depending on the // mux, this might simply get ignored. See sps_rbsp(). + // 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_space = AVCOL_SPC_SMPTE170M; // YUV colorspace (output_ycbcr_format.luma_coefficients). + // YUV colorspace (output_ycbcr_format.luma_coefficients). + if (global_flags.ycbcr_rec709_coefficients) { + avstream_video->codecpar->color_space = AVCOL_SPC_BT709; + } else { + avstream_video->codecpar->color_space = AVCOL_SPC_SMPTE170M; + } avstream_video->codecpar->color_range = AVCOL_RANGE_MPEG; // Full vs. limited range (output_ycbcr_format.full_range). avstream_video->codecpar->chroma_location = AVCHROMA_LOC_LEFT; // Chroma sample location. See chroma_offset_0[] in Mixer::subsample_chroma(). avstream_video->codecpar->field_order = AV_FIELD_PROGRESSIVE; @@ -130,6 +153,14 @@ void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts) } av_packet_unref(&pkt_copy); + + // Note: This will be wrong in the case of plugged packets, but that only happens + // for network streams, not for files, and write callbacks are only really relevant + // for files. (We don't want to do this from write_packet_or_die, as it only has + // the rescaled pts, which is unsuitable for callback.) + if (pkt.stream_index == 0 && write_callback != nullptr) { + write_callback(pts); + } } void Mux::write_packet_or_die(const AVPacket &pkt)