@@ -15,6 +15,18 @@ static bool g_cpu = registerDeviceInterface(
15
15
16
16
} // namespace
17
17
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
+
18
30
bool CpuDeviceInterface::SwsFrameContext::operator ==(
19
31
const CpuDeviceInterface::SwsFrameContext& other) const {
20
32
return inputWidth == other.inputWidth && inputHeight == other.inputHeight &&
@@ -97,13 +109,12 @@ void CpuDeviceInterface::convertAVFrameToFrameOutput(
97
109
// And we sometimes re-create them because it's possible for frame
98
110
// resolution to change mid-stream. Finally, we want to reuse the colorspace
99
111
// 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);
107
118
108
119
outputTensor = preAllocatedOutputTensor.value_or (allocateEmptyHWCTensor (
109
120
expectedOutputHeight, expectedOutputWidth, torch::kCPU ));
@@ -128,22 +139,20 @@ void CpuDeviceInterface::convertAVFrameToFrameOutput(
128
139
} else if (colorConversionLibrary == ColorConversionLibrary::FILTERGRAPH) {
129
140
// See comment above in swscale branch about the filterGraphContext_
130
141
// 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
-
142
142
std::stringstream filters;
143
143
filters << " scale=" << expectedOutputWidth << " :" << expectedOutputHeight;
144
144
filters << " :sws_flags=bilinear" ;
145
145
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);
147
156
148
157
if (!filterGraphContext_ || prevFiltersContext_ != filtersContext) {
149
158
filterGraphContext_ =
0 commit comments