MCPcopy Create free account
hub / github.com/FFMS/ffms2 / FindBestPixelFormat

Function FindBestPixelFormat

src/core/videoutils.cpp:191–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191AVPixelFormat FindBestPixelFormat(const std::vector<AVPixelFormat> &Dsts, AVPixelFormat Src) {
192 // some trivial special cases to make sure there's as little conversion as possible
193 if (Dsts.empty())
194 return AV_PIX_FMT_NONE;
195 if (Dsts.size() == 1)
196 return Dsts[0];
197
198 // is the input in the output?
199 auto i = std::find(Dsts.begin(), Dsts.end(), Src);
200 if (i != Dsts.end())
201 return Src;
202
203 // If it's an evil paletted format pretend it's normal RGB when calculating loss
204 if (Src == AV_PIX_FMT_PAL8)
205 Src = AV_PIX_FMT_RGB32;
206
207 std::vector<AVPixelFormat> OutputDsts;
208 for (auto DstFmt = Dsts.begin(); DstFmt != Dsts.end(); ++DstFmt) {
209 // Skip outputing to formwats we can't convert to, this avoids swscale init failures later in the code
210 if (sws_isSupportedOutput(*DstFmt))
211 OutputDsts.push_back(*DstFmt);
212 }
213
214 if (OutputDsts.empty())
215 return AV_PIX_FMT_NONE;
216
217 i = OutputDsts.begin();
218 LossAttributes Loss = CalculateLoss(*i++, Src);
219 for (; i != OutputDsts.end(); ++i) {
220 LossAttributes CLoss = CalculateLoss(*i, Src);
221 if (Loss.CSLoss >= 3 && CLoss.CSLoss < Loss.CSLoss) { // favor the same color format output
222 Loss = CLoss;
223 } else if (Loss.DepthDifference >= 0 && CLoss.DepthDifference >= 0) { // focus on chroma undersamling and conversion loss if the target depth has been achieved
224 if ((CLoss.ChromaUndersampling < Loss.ChromaUndersampling)
225 || (CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss < Loss.CSLoss)
226 || (CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss == Loss.CSLoss && CLoss.DepthDifference < Loss.DepthDifference)
227 || (CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss == Loss.CSLoss
228 && CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaOversampling < Loss.ChromaOversampling))
229 Loss = CLoss;
230 } else { // put priority on reaching the same depth as the input
231 if ((CLoss.DepthDifference > Loss.DepthDifference)
232 || (CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaUndersampling < Loss.ChromaUndersampling)
233 || (CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaUndersampling == Loss.ChromaUndersampling && CLoss.CSLoss < Loss.CSLoss)
234 || (CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaUndersampling == Loss.ChromaUndersampling
235 && CLoss.CSLoss == Loss.CSLoss && CLoss.ChromaOversampling < Loss.ChromaOversampling))
236 Loss = CLoss;
237 else if (CLoss.DepthDifference == Loss.DepthDifference && CLoss.ChromaUndersampling == Loss.ChromaUndersampling
238 && CLoss.CSLoss == Loss.CSLoss && CLoss.ChromaOversampling == Loss.ChromaOversampling && CLoss.CSGain < Loss.CSGain)
239 Loss = CLoss;
240 }
241 }
242
243 return Loss.Format;
244}
245
246void ParseVP8(const uint8_t Buf, bool *Invisible, int *PictType) {
247 *PictType = (Buf & 0x01) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;

Callers 1

ReAdjustOutputFormatMethod · 0.85

Calls 5

CalculateLossFunction · 0.85
emptyMethod · 0.80
sizeMethod · 0.80
beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected