MCPcopy Create free account
hub / github.com/IENT/YUView / createDecoder

Method createDecoder

YUViewLib/src/decoder/decoderFFmpeg.cpp:438–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

436}
437
438bool 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

Callers 1

decoderFFmpegMethod · 0.95

Calls 14

setErrorBMethod · 0.80
findDecoderMethod · 0.80
allocDecoderMethod · 0.80
configureDecoderMethod · 0.80
dictSetMethod · 0.80
avcodecOpen2Method · 0.80
allocateFrameMethod · 0.80
getCodecNameMethod · 0.45
getSizeMethod · 0.45
getPixelFormatMethod · 0.45
getRawFormatMethod · 0.45

Tested by

no test coverage detected