| 436 | } |
| 437 | |
| 438 | bool decoderFFmpeg::createDecoder(FFmpeg::AVCodecIDWrapper codecID, |
| 439 | FFmpeg::AVCodecParametersWrapper codecpar) |
| 440 | { |
| 441 | // Allocate the decoder context |
| 442 | if (this->videoCodec) |
| 443 | return this->setErrorB(QStringLiteral("Video codec already allocated.")); |
| 444 | this->videoCodec = this->ff.findDecoder(codecID); |
| 445 | if (!this->videoCodec) |
| 446 | return this->setErrorB(QStringLiteral("Could not find a video decoder for the given codec ") + |
| 447 | codecID.getCodecName()); |
| 448 | |
| 449 | if (this->decCtx) |
| 450 | return this->setErrorB(QStringLiteral("Decoder context already allocated.")); |
| 451 | this->decCtx = this->ff.allocDecoder(this->videoCodec); |
| 452 | if (!this->decCtx) |
| 453 | return this->setErrorB( |
| 454 | QStringLiteral("Could not allocate video decoder (avcodec_alloc_context3)")); |
| 455 | |
| 456 | if (codecpar && !this->ff.configureDecoder(decCtx, codecpar)) |
| 457 | return this->setErrorB(QStringLiteral("Unable to configure decoder from codecpar")); |
| 458 | |
| 459 | // Get some parameters from the decoder context |
| 460 | this->frameSize = decCtx.getSize(); |
| 461 | |
| 462 | auto ffmpegPixFormat = this->ff.getAvPixFmtDescriptionFromAvPixelFormat(decCtx.getPixelFormat()); |
| 463 | this->rawFormat = ffmpegPixFormat.getRawFormat(); |
| 464 | if (this->rawFormat == video::RawFormat::YUV) |
| 465 | this->formatYUV = ffmpegPixFormat.getPixelFormatYUV(); |
| 466 | else if (this->rawFormat == video::RawFormat::RGB) |
| 467 | this->formatRGB = ffmpegPixFormat.getRGBPixelFormat(); |
| 468 | |
| 469 | // Ask the decoder to provide motion vectors (if possible) |
| 470 | FFmpeg::AVDictionaryWrapper opts; |
| 471 | int ret = this->ff.dictSet(opts, "flags2", "+export_mvs", 0); |
| 472 | if (ret < 0) |
| 473 | return this->setErrorB( |
| 474 | QStringLiteral("Could not request motion vector retrieval. Return code %1").arg(ret)); |
| 475 | |
| 476 | // Open codec |
| 477 | ret = this->ff.avcodecOpen2(decCtx, videoCodec, opts); |
| 478 | if (ret < 0) |
| 479 | return this->setErrorB( |
| 480 | QStringLiteral("Could not open the video codec (avcodec_open2). Return code %1.").arg(ret)); |
| 481 | |
| 482 | this->frame = ff.allocateFrame(); |
| 483 | if (!this->frame) |
| 484 | return this->setErrorB(QStringLiteral("Could not allocate frame (av_frame_alloc).")); |
| 485 | |
| 486 | return true; |
| 487 | } |
| 488 | |
| 489 | } // namespace decoder |
no test coverage detected