[Libav-user] Libavdevice. Reading formats info.

Hristo Ivanov hivanov.ffmailing at gmail.com
Tue Oct 23 19:53:35 EEST 2018


Hi.

The different devices ffmpeg supports have different options, I am
interested in the 'list_formats' of the decklink devices. Using the
ffmpeg.exe tool the following command:

    ffmpeg -f decklink -list_formats 1 -i 'Intensity Pro'

prints the formats that can be used with the device.

I want to recover this information from my program which uses the libav
libraries. My current solution looks like this.


std::string formatListing;

int main(int argc, char* argv[]) {
    av_log_set_level(AV_LOG_VERBOSE);
    av_log_set_callback(my_log_callback);

    AVInputFormat* inpF = av_find_input_format("decklink");
    AVFormatContext* ifmt_ctx = avformat_alloc_context();
    AVDictionary* options = NULL;
    av_dict_set(&options, "list_formats", "1", NULL);

    avformat_open_input(&ifmt_ctx, deviceName.c_str(), inpF, &options);

    ........... // Parse the string in formatListing.
}

void my_log_callback(void *ptr, int level, const char *fmt, va_list vl) {
    AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
    std::string className = avc ? avc->item_name(ptr) : "";

    if (className == "decklink") {
        char buf[500];
        vsnprintf(buf, 500, fmt, vl);
        formatListing += buf;
    }

    if (avc != NULL)
        const char* aux = avc->item_name(ptr);

    av_log_default_callback(ptr, level, fmt, vl);
}


This code works fine, but I don't like it. Is there a more elegant solution
to this which doesn't involve a log callback?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20181023/535fb6b8/attachment.html>


More information about the Libav-user mailing list