예제 #1
0
void FormatContext::openCustomIOOutput(CustomIO *io, size_t internalBufferSize, OptionalErrorCode ec)
{
    if (isOpened())
    {
        throws_if(ec, Errors::FormatAlreadyOpened);
        return;
    }

    if (m_raw)
    {
        OutputFormat format = outputFormat();
        if (format.isNull())
        {
            fflog(AV_LOG_ERROR, "You must set output format for use with custom IO\n");
            throws_if(ec, Errors::FormatNullOutputFormat);
            return;
        }
    }
    openCustomIO(io, internalBufferSize, true, ec);
}
예제 #2
0
void FormatContext::openOutput(const string &uri, OutputFormat format, AVDictionary **options, OptionalErrorCode ec)
{
    clear_if(ec);
    if (!m_raw)
    {
        throws_if(ec, Errors::Unallocated);
        return;
    }

    if (isOpened())
    {
        throws_if(ec, Errors::FormatAlreadyOpened);
        return;
    }

    if (format.isNull())
        format = outputFormat();
    else
        setFormat(format);

    if (format.isNull())
    {
        // Guess format
        format = guessOutputFormat(string(), uri);

        if (format.isNull())
        {
            fflog(AV_LOG_ERROR, "Can't guess output format");
            throws_if(ec, Errors::FormatNullOutputFormat);
            return;
        }
        setFormat(format);
    }

    // Fix stream flags
#if !USE_CODECPAR
    FF_DISABLE_DEPRECATION_WARNINGS
    for (size_t i = 0; i < streamsCount(); ++i) {
        auto st = stream(i);
        if (st.raw()->codec) {
            if (outputFormat().isFlags(AVFMT_GLOBALHEADER)) {
                st.raw()->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
            }
        }
    }
    FF_ENABLE_DEPRECATION_WARNINGS
#endif

    resetSocketAccess();
    if (!(format.flags() & AVFMT_NOFILE))
    {
        int sts = avio_open2(&m_raw->pb, uri.c_str(), AVIO_FLAG_WRITE, nullptr, options);
        if (sts < 0)
        {
            throws_if(ec, sts, ffmpeg_category());
            return;
        }
    }

    m_uri = uri;
    m_isOpened = true;
}