Skip to content

Commit 2a391b6

Browse files
committed
Better comments
1 parent 0e61aba commit 2a391b6

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

src/torchcodec/_core/CpuDeviceInterface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ void CpuDeviceInterface::initializeVideo(
6969
first = false;
7070
}
7171
if (!transforms.empty()) {
72-
// Note that we ensure that the transforms come BEFORE the format
73-
// conversion. This means that the transforms are applied in the frame's
74-
// original pixel format and colorspace.
72+
// Note that we ensure that the transforms come AFTER the format conversion.
73+
// This means that the transforms are applied in the output pixel format and
74+
// colorspace.
7575
filters_ += "," + filters.str();
7676
}
7777

src/torchcodec/_core/CpuDeviceInterface.h

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,18 @@ class CpuDeviceInterface : public DeviceInterface {
9393
// initialization, we convert the user-supplied transforms into this string of
9494
// filters.
9595
//
96-
// TODO: make sure Scott corrects the below:
9796
// Note that we start with just the format conversion, and then we ensure that
98-
// the user-supplied filters always happen BEFORE the format conversion. We
99-
// want the user-supplied filters to operate on frames in their original pixel
97+
// the user-supplied filters always happen AFTER the format conversion. We
98+
// want the user-supplied filters to operate on frames in the output pixel
10099
// format and colorspace.
101100
//
102-
// The reason why is not obvious: when users do not need to perform any
103-
// transforms, or the only transform they apply is a single resize, we can
104-
// sometimes just call swscale directly; see getColorConversionLibrary() for
105-
// the full conditions. A single call to swscale's sws_scale() will always do
106-
// the scaling (resize) in the frame's original pixel format and colorspace.
107-
// In order for calling swscale directly to be an optimization, we must make
108-
// sure that the behavior between calling it directly and using filtergraph
109-
// is identical.
101+
// We apply the transforms on the output pixel format and colorspace because
102+
// then decoder-native transforms are as close as possible to returning
103+
// untransformed frames and applying TochVision transforms to them.
110104
//
111-
// If we had to apply transforms in the output pixel format and colorspace,
112-
// we could achieve that by calling sws_scale() twice: once to do the resize
113-
// and another time to do the format conversion. But that will be slower,
114-
// which goes against the whole point of calling sws_scale() directly.
115-
//
116-
// Further note that we also configure the sink node of the filtergraph to
117-
// be AV_PIX_FMT_RGB24. However, the explicit format conversion in the
118-
// filters is not redundant. Filtergraph will automatically insert scale
119-
// filters that will change the resolution and format of frames to meet the
120-
// requirements of downstream filters. If we don't put an explicit format
121-
// conversion to rgb24 at the end, filtergraph may automatically insert format
122-
// conversions before our filters.
105+
// We ensure that the transforms happen on the output pixel format and
106+
// colorspace by making sure all of the user-supplied filters happen AFTER
107+
// an explicit format conversion.
123108
std::string filters_ = "format=rgb24";
124109

125110
// The flags we supply to swsContext_, if it used. The flags control the

0 commit comments

Comments
 (0)