Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/torchcodec/_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function(make_torchcodec_libraries
Transform.cpp
Metadata.cpp
SwScale.cpp
ToneMap.cpp
NVDECCacheConfig.cpp
)

Expand Down
7 changes: 7 additions & 0 deletions src/torchcodec/_core/CpuDeviceInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// LICENSE file in the root directory of this source tree.

#include "CpuDeviceInterface.h"
#include "ToneMap.h"

namespace facebook::torchcodec {
namespace {
Expand Down Expand Up @@ -176,6 +177,12 @@ void CpuDeviceInterface::convertVideoAVFrameToFrameOutput(
// Both cases cause problems for our batch APIs, as we allocate
// FrameBatchOutputs based on the the stream metadata. But single-frame APIs
// can still work in such situations, so they should.
// If tone mapping is enabled and the frame is HDR, convert to SDR RGB24.
if (videoStreamOptions_.toneMapping.has_value() &&
isHDRFrame(avFrame.get())) {
avFrame = toneMapHDRFrame(avFrame);
}

auto outputDims =
resizedOutputDims_.value_or(FrameDims(avFrame->height, avFrame->width));

Expand Down
5 changes: 5 additions & 0 deletions src/torchcodec/_core/StreamOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ struct VideoStreamOptions {
// Device variant (e.g., "ffmpeg", "beta", etc.)
std::string_view deviceVariant = "ffmpeg";

// Tone mapping algorithm for HDR→SDR conversion.
// If set, HDR frames (PQ/HLG) will be tone-mapped to SDR.
// Supported values: "hable".
std::optional<std::string> toneMapping;

// Encoding options
std::optional<std::string> codec;
// Optional pixel format for video encoding (e.g., "yuv420p", "yuv444p")
Expand Down
Loading
Loading