| 313 | } |
| 314 | |
| 315 | void VSVideoSource4::InitOutputFormat(int ResizeToWidth, int ResizeToHeight, |
| 316 | const char *ResizerName, int ConvertToFormat, const VSAPI *vsapi, VSCore *core) { |
| 317 | |
| 318 | char ErrorMsg[1024]; |
| 319 | FFMS_ErrorInfo E; |
| 320 | E.Buffer = ErrorMsg; |
| 321 | E.BufferSize = sizeof(ErrorMsg); |
| 322 | |
| 323 | const FFMS_Frame *F = FFMS_GetFrame(V, 0, &E); |
| 324 | if (!F) { |
| 325 | std::string buf = "Source: "; |
| 326 | buf += E.Buffer; |
| 327 | throw std::runtime_error(buf); |
| 328 | } |
| 329 | |
| 330 | std::vector<int> TargetFormats; |
| 331 | int npixfmt = GetNumPixFmts(); |
| 332 | for (int i = 0; i < npixfmt; i++) |
| 333 | if (IsRealNativeEndianPlanar(*av_pix_fmt_desc_get((AVPixelFormat)i))) |
| 334 | TargetFormats.push_back(i); |
| 335 | TargetFormats.push_back(AV_PIX_FMT_NONE); |
| 336 | |
| 337 | int TargetPixelFormat = AV_PIX_FMT_NONE; |
| 338 | if (ConvertToFormat != pfNone) { |
| 339 | TargetPixelFormat = FormatConversionToPixelFormat(ConvertToFormat, OutputAlpha, core, vsapi); |
| 340 | if (TargetPixelFormat == AV_PIX_FMT_NONE) |
| 341 | throw std::runtime_error(std::string("Source: Invalid output colorspace specified")); |
| 342 | |
| 343 | TargetFormats.clear(); |
| 344 | TargetFormats.push_back(TargetPixelFormat); |
| 345 | TargetFormats.push_back(-1); |
| 346 | } |
| 347 | |
| 348 | if (ResizeToWidth <= 0) |
| 349 | ResizeToWidth = F->EncodedWidth; |
| 350 | |
| 351 | if (ResizeToHeight <= 0) |
| 352 | ResizeToHeight = F->EncodedHeight; |
| 353 | |
| 354 | int Resizer = ResizerNameToSWSResizer(ResizerName); |
| 355 | if (Resizer == 0) |
| 356 | throw std::runtime_error(std::string("Source: Invalid resizer name specified")); |
| 357 | |
| 358 | if (FFMS_SetOutputFormatV2(V, &TargetFormats[0], |
| 359 | ResizeToWidth, ResizeToHeight, Resizer, &E)) |
| 360 | throw std::runtime_error(std::string("Source: No suitable output format found")); |
| 361 | |
| 362 | F = FFMS_GetFrame(V, 0, &E); |
| 363 | TargetFormats.clear(); |
| 364 | TargetFormats.push_back(F->ConvertedPixelFormat); |
| 365 | TargetFormats.push_back(-1); |
| 366 | |
| 367 | // This trick is required to first get the "best" default format and then set only that format as the output |
| 368 | if (FFMS_SetOutputFormatV2(V, TargetFormats.data(), ResizeToWidth, ResizeToHeight, Resizer, &E)) |
| 369 | throw std::runtime_error(std::string("Source: No suitable output format found")); |
| 370 | |
| 371 | F = FFMS_GetFrame(V, 0, &E); |
| 372 |
nothing calls this directly
no test coverage detected