Code Monkey home page Code Monkey logo

Comments (2)

h4tr3d avatar h4tr3d commented on August 28, 2024

Hi,

All magic located here:

vdec = VideoDecoderContext(vst);

Just look into CodecContext2::CodecContext2(const Stream &st, const Codec &codec, Direction direction, AVMediaType type)

To simplify research, CodecContext2() called like:

CodecContext2(vst, Codec(), Direction::Decoding, AVMEDIA_TYPE_VIDEO)

Null Codec here means "use vst for the codec selection" and needed only for some corner cases, when codec overriding are needed:

... CodecContext2()...
...
    Codec c = codec;
    if (codec.isNull())
    {
        if (st.direction() == Direction::Decoding)
            c = findDecodingCodec(codecId);
        else
            c = findEncodingCodec(codecId);
    }
...

Open routine can be simplified to:

vdec.open(ec);

This mostly same to

vdec.open(Codec(), ec);

For opening this routine are used:

void CodecContext2::open(const Codec &codec, AVDictionary **options, OptionalErrorCode ec)
{
    clear_if(ec);

    if (isOpened() || !isValid()) {
        throws_if(ec, isOpened() ? Errors::CodecAlreadyOpened : Errors::CodecInvalid);
        return;
    }

    int stat = avcodec_open2(m_raw, codec.raw(), options);
    if (stat < 0)
        throws_if(ec, stat, ffmpeg_category());
}

You may be confused, that avcodec_open2() calls with NULL codec. But, look into avcodec_open2() description:

 * @param codec The codec to open this context for. If a non-NULL codec has been
 *              previously passed to avcodec_alloc_context3() or
 *              for this context, then this parameter MUST be either NULL or
 *              equal to the previously passed codec.

We are initialized VideoDecoderContext with the Stream reference. And already pass correct codec to the avcodec_alloc_context3(). So, now you have two ways:

  1. Add extra unuseful code to pass correct codec into open()
  2. Or just pass Empty/Null codec in to it )

from avcpp.

h4tr3d avatar h4tr3d commented on August 28, 2024

Ah! Codec() provides Null Codec :-)

And sorry for the long delay :-)

from avcpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.