Skip to content

Commit

Permalink
[VIDEO] Add, store and process HDR type flags
Browse files Browse the repository at this point in the history
  • Loading branch information
phunkyfish committed Jan 29, 2024
1 parent 50a4815 commit 6b8a9fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/stream/DemuxStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class DemuxStreamVideo : public DemuxStream
std::shared_ptr<AVContentLightMetadata> contentLightMetaData;

std::string stereo_mode; // expected stereo mode
StreamHdrType hdr_type = StreamHdrType::HDR_TYPE_NONE; // type of HDR for this stream (hdr10, etc)
};

class DemuxStreamAudio : public DemuxStream
Expand Down
23 changes: 21 additions & 2 deletions src/stream/FFmpegStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,13 +728,17 @@ bool FFmpegStream::Open(bool fileinfo)

bool skipCreateStreams = false;
bool isBluray = false;
if (iformat && (strcmp(iformat->name, "mpegts") == 0) && !fileinfo && !isBluray)
// don't re-open mpegts streams with hevc encoding as the params are not correctly detected again
if (iformat && (strcmp(iformat->name, "mpegts") == 0) && !fileinfo && !isBluray &&
m_pFormatContext->streams[0]->codecpar->codec_id != AV_CODEC_ID_HEVC)
{
av_opt_set_int(m_pFormatContext, "analyzeduration", 500000, 0);
m_checkTransportStream = true;
skipCreateStreams = true;
}
else if (!iformat || (strcmp(iformat->name, "mpegts") != 0))
else if (!iformat || ((strcmp(iformat->name, "mpegts") != 0) ||
((strcmp(iformat->name, "mpegts") == 0) &&
m_pFormatContext->streams[0]->codecpar->codec_id == AV_CODEC_ID_HEVC)))
{
m_streaminfo = true;
}
Expand Down Expand Up @@ -2039,11 +2043,26 @@ DemuxStream* FFmpegStream::AddStream(int streamIdx)
size_t size = 0;
uint8_t* side_data = nullptr;

side_data = av_stream_get_side_data(pStream, AV_PKT_DATA_DOVI_CONF, &size);
if (side_data && size)
st->hdr_type = StreamHdrType::HDR_TYPE_DOLBYVISION;
else if (st->colorPrimaries == AVCOL_PRI_BT2020)
{
if (st->colorTransferCharacteristic == AVCOL_TRC_SMPTE2084) // hdr10
st->hdr_type = StreamHdrType::HDR_TYPE_HDR10;
else if (st->colorTransferCharacteristic == AVCOL_TRC_ARIB_STD_B67) // hlg
st->hdr_type = StreamHdrType::HDR_TYPE_HLG;
}

side_data = av_stream_get_side_data(pStream, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, &size);
if (side_data && size)
{
st->masteringMetaData = std::make_shared<AVMasteringDisplayMetadata>(
*reinterpret_cast<AVMasteringDisplayMetadata*>(side_data));
// file could be SMPTE2086 which FFmpeg currently returns as unknown so use the presence
// of static metadata to detect it
if (st->masteringMetaData->has_primaries && st->masteringMetaData->has_luminance)
st->hdr_type = StreamHdrType::HDR_TYPE_HDR10;
}

side_data = av_stream_get_side_data(pStream, AV_PKT_DATA_CONTENT_LIGHT_LEVEL, &size);
Expand Down

0 comments on commit 6b8a9fe

Please sign in to comment.