@@ -15,6 +15,18 @@ static bool g_cpu = registerDeviceInterface(
1515
1616} // namespace
1717
18+ CpuDeviceInterface::SwsFrameContext::SwsFrameContext (
19+ int inputWidth,
20+ int inputHeight,
21+ AVPixelFormat inputFormat,
22+ int outputWidth,
23+ int outputHeight)
24+ : inputWidth(inputWidth),
25+ inputHeight (inputHeight),
26+ inputFormat(inputFormat),
27+ outputWidth(outputWidth),
28+ outputHeight(outputHeight) {}
29+
1830bool CpuDeviceInterface::SwsFrameContext::operator ==(
1931 const CpuDeviceInterface::SwsFrameContext& other) const {
2032 return inputWidth == other.inputWidth && inputHeight == other.inputHeight &&
@@ -97,13 +109,12 @@ void CpuDeviceInterface::convertAVFrameToFrameOutput(
97109 // And we sometimes re-create them because it's possible for frame
98110 // resolution to change mid-stream. Finally, we want to reuse the colorspace
99111 // conversion objects as much as possible for performance reasons.
100- SwsFrameContext swsFrameContext;
101-
102- swsFrameContext.inputWidth = avFrame->width ;
103- swsFrameContext.inputHeight = avFrame->height ;
104- swsFrameContext.inputFormat = frameFormat;
105- swsFrameContext.outputWidth = expectedOutputWidth;
106- swsFrameContext.outputHeight = expectedOutputHeight;
112+ SwsFrameContext swsFrameContext (
113+ avFrame->width ,
114+ avFrame->height ,
115+ frameFormat,
116+ expectedOutputWidth,
117+ expectedOutputHeight);
107118
108119 outputTensor = preAllocatedOutputTensor.value_or (allocateEmptyHWCTensor (
109120 expectedOutputHeight, expectedOutputWidth, torch::kCPU ));
@@ -128,22 +139,20 @@ void CpuDeviceInterface::convertAVFrameToFrameOutput(
128139 } else if (colorConversionLibrary == ColorConversionLibrary::FILTERGRAPH) {
129140 // See comment above in swscale branch about the filterGraphContext_
130141 // creation. creation
131- FiltersContext filtersContext;
132-
133- filtersContext.inputWidth = avFrame->width ;
134- filtersContext.inputHeight = avFrame->height ;
135- filtersContext.inputFormat = frameFormat;
136- filtersContext.inputAspectRatio = avFrame->sample_aspect_ratio ;
137- filtersContext.outputWidth = expectedOutputWidth;
138- filtersContext.outputHeight = expectedOutputHeight;
139- filtersContext.outputFormat = AV_PIX_FMT_RGB24;
140- filtersContext.timeBase = timeBase;
141-
142142 std::stringstream filters;
143143 filters << " scale=" << expectedOutputWidth << " :" << expectedOutputHeight;
144144 filters << " :sws_flags=bilinear" ;
145145
146- filtersContext.filtergraphStr = filters.str ();
146+ FiltersContext filtersContext (
147+ avFrame->width ,
148+ avFrame->height ,
149+ frameFormat,
150+ avFrame->sample_aspect_ratio ,
151+ expectedOutputWidth,
152+ expectedOutputHeight,
153+ AV_PIX_FMT_RGB24,
154+ filters.str (),
155+ timeBase);
147156
148157 if (!filterGraphContext_ || prevFiltersContext_ != filtersContext) {
149158 filterGraphContext_ =
0 commit comments