0

I am writing an image processing application to align a set of images, and I would like there to be functionality to write those images into a video. The image processing part is done in OpenCV 3.2.0 (C++), and currently outputs still images that aren't stitched together.

I have successfully used the VideoWriter with one of the codecs available to my machine to write the output images to an .avi, but to my knowledge there is no guarantee that any codec will be available on different platforms. As I would like to be able to share this application, this is a problem.

If it matters, the GUI is built in wxWidgets 3.1.0, so if there is something that can help me there that I didn't find, I would love to know.

My assumption is that there is no way of guaranteeing a successful video without somehow shipping a codec with the app, but is there a way of browsing available codecs at run time?

I know that on some platforms the following brings up a dialog of additional codecs, which would be perfect if I could automatically interpret it:

cv::Size outputSize = myImage.size();
cv::VideoWriter("output.avi", -1, 30, outputSize);

But this also doesn't work on every platform. So is there any way of scrubbing available codecs from the machine at run time or do I have to supply a codec somehow in order to write videos cross platform?

  • you can try to supply the codecs along with you software, but you need to check their license first. Also, check how you will get all this in *nix/Mac. – Igor Sep 01 '17 at 02:01
  • I believe the `MJPG` codec in `.avi` container is built-in to OpenCV 3.0 and above... https://stackoverflow.com/a/31401095/2836621 – Mark Setchell Sep 01 '17 at 06:58

1 Answers1

0

There is no such function in OpenCV to list all the available codecs. However, if you've ffmpeg or LibAV on your machine - as you should've while building/installing OpenCV - then you can use ffmpeg/LibAV to list all the available codecs. Following is code that does that:

#include <iostream>

extern "C" {
    #include <libavcodec/avcodec.h>
}

int main(int argc, char **argv)
{
    /* initialize libavcodec, and register all codecs and formats */
    avcodec_register_all();

    // struct to hold the codecs
    AVCodec* current_codec = NULL;

    // initialize the AVCodec* object with first codec
    current_codec = av_codec_next(current_codec);

    std::cout<<"List of codecs:"<<std::endl;

    // loop over all codecs
    while (current_codec != NULL)
    {

        if(av_codec_is_encoder(current_codec) | av_codec_is_decoder(current_codec))
        {
            std::cout<<current_codec->name<<std::endl;
        }
        current_codec = av_codec_next(current_codec);
    }
}

Compile with:

g++ listcodecs.cpp -o listcodecs `pkg-config libavcodec --cflags --libs`

zindarod
  • 6,328
  • 3
  • 30
  • 58