Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

1st of all, codecs must be available on your system at runtime and doesn't depends on OpenCV but depends on codec you have installed on your system. This means that the codec must be available on the machine that runs the OpenCV application.

OpenCV doesn't have a function to get the list of available codecs. But, it's really useful to programmatically get this list or you just need to know if a codec is available or to know its fourcc ?

after this, some points:

  • Use int codec=CV_FOURCC('M','R','L',E') for Microsoft RLE (see this http://www.fourcc.org/mrle/). This codec is native on Windows.
  • If FFMPEG is enabled in your OpenCV bin, using codec=0; fps=0; you can create an uncompressed (raw) video file. In this case you have to deploy the ffmpeg's DLL with your exe.
  • You can save image sequence using a proper filename (eg. img_%02d.jpg) and fourcc=0 OR fps=0. Use uncompressed image format (eg. img_%02d.BMP) to save raw frames.
  • not compressed... did you mean lossless ? In this case you might install and use some lossless codec like Huffman (HFYU), Lagarith (LAGS). You will have about 30% of compression without quality loss. Even in this case the codec must be available on target system.

I would suggest to install some 3rd party codec pack, (take a look also to ffdshow). This will install on your system a lot of codecs (e.g. MPEG, DIVX, H264, HFYU,...) that you can use with many applications including OpenCV or VirtualDub.

Remember that on Windows, VideoWriter uses VFW (Video For Windows API) thus any available codec that is VFW compliant can be used with VideoWriter.

To check for Installed Video Codecs on you system:

  • just run Windows Media Player, enable the menu bar than About > Technical Info
  • OR run MSINFO32.exe than components > Multimedia > Codec video
  • OR use OpenCV with codec = -1. VideoWriter pops up codec selection dialog from the system, the list include all available and compatible codecs.

Finally, get the 4 char code (fourcc) for your selected codec from http://www.fourcc.org/ and create the int code using int codec = CV_FOURCC(...) macro as above.

I hope this helps

1st of all, codecs must be available on your system at runtime and doesn't depends on OpenCV but depends on codec you have installed on your system. This means that the codec must be available on the machine that runs the OpenCV application.

OpenCV doesn't have a function to get the list of available codecs. But, it's really useful to programmatically get this list or you just need to know if a codec is available or to know its fourcc ?

after this, some points:

  • Use int codec=CV_FOURCC('M','R','L',E') for Microsoft RLE (see this http://www.fourcc.org/mrle/). This codec is native on Windows.
  • If FFMPEG is enabled in your OpenCV bin, using codec=0; fps=0; you can create an uncompressed (raw) video file. In this case you have to deploy the ffmpeg's DLL with your exe.
  • You can save image sequence using a proper filename (eg. img_%02d.jpg) and fourcc=0 OR fps=0. Use uncompressed image format (eg. img_%02d.BMP) to save raw frames.
  • not compressed... did you mean lossless ? In this case you might install and use some lossless codec like Huffman (HFYU), Lagarith (LAGS). You will have about 30% of compression without quality loss. Even in this case the codec must be available on target system.

I would suggest to install some 3rd party codec pack, (take a look also to ffdshow). This will install on your system a lot of codecs (e.g. MPEG, DIVX, H264, HFYU,...) that you can use with many applications including OpenCV or VirtualDub.

Remember that on Windows, VideoWriter cv::VideoWriter uses VFW (Video For Windows API) thus any available codec that is VFW compliant can be used with VideoWriter.

To check for Installed installed Video Codecs on you your system:

  • just run Windows Media Player, enable the menu bar than About > Technical Info
  • OR run MSINFO32.exe than components > Multimedia > Codec video
  • OR use OpenCV with codec = -1. VideoWriter pops up codec selection dialog from the system, the list include all available and compatible codecs.

Finally, get the 4 char code (fourcc) for your selected codec from http://www.fourcc.org/ and create the int code using int codec = CV_FOURCC(...) macro as above.

I hope this helps

1st of all, codecs must be available on your system at runtime and doesn't depends on OpenCV but depends on codec you have installed on your system. This means that the codec must be available on the machine that runs the OpenCV application.

UPDATE

OpenCV doesn't have a function to get the list of available codecs. But, it's really useful to programmatically To a get this list of available codecs you need to call some system function. Pn Windows OpenCV just calls the function that pup up the OS codec form.

BTW each codec follows some specs (frame size or you just need to know ratio, fps, compression ...) thus if your app provides codec selection you have to manage codec specs too.

You might define a codec is available or to know its fourcc ?vector of supported codecs than test if they are available at start-up with multiple calls to VideoWriter::open and write. Something like this:

vector<int> availableCodecs;
vector<int> supportedCodec({
    CV_FOURCC('M','J','P','G'), 
    CV_FOURCC('M','R','L','E'), 
    others you can support ...
    });

for(int i=0; i<supportedCodec.size(); i++) {
    VideoWriter vw("test.avi", supportedCodec[i], ...);
    if(vw.isOpened()) 
        if (vw.write(testImg))
            availableCodecs.push_back(supportedCodec[i]);
    vw.release();    
}

endUPDATE

after this, some points:

  • Use int codec=CV_FOURCC('M','R','L',E') for Microsoft RLE (see this http://www.fourcc.org/mrle/). This codec is native on Windows.
  • If FFMPEG is enabled in your OpenCV bin, using codec=0; fps=0; you can create an uncompressed (raw) video file. In this case you have to deploy the ffmpeg's DLL with your exe.
  • You can save image sequence using a proper filename (eg. img_%02d.jpg) and fourcc=0 OR fps=0. Use uncompressed image format (eg. img_%02d.BMP) to save raw frames.
  • not compressed... did you mean lossless ? In this case you might install and use some lossless codec like Huffman (HFYU), Lagarith (LAGS). You will have about 30% of compression without quality loss. Even in this case the codec must be available on target system.

I would suggest to install some 3rd party codec pack, (take a look also to ffdshow). This will install on your system a lot of codecs (e.g. MPEG, DIVX, H264, HFYU,...) that you can use with many applications including OpenCV or VirtualDub.

Remember that on Windows, cv::VideoWriter uses VFW (Video For Windows API) thus any available codec that is VFW compliant can be used with VideoWriter.

To check for installed Video Codecs on your system:

  • just run Windows Media Player, enable the menu bar than About > Technical Info
  • OR run MSINFO32.exe than components > Multimedia > Codec video
  • OR use OpenCV with codec = -1. VideoWriter pops up codec selection dialog from the system, the list include all available and compatible codecs.

Finally, get the 4 char code (fourcc) for your selected codec from http://www.fourcc.org/ and create the int code using int codec = CV_FOURCC(...) macro as above.

I hope this helps

1st of all, codecs must be available on your system at runtime and doesn't depends on OpenCV but depends on codec you have installed on your system. This means that the codec must be available on the machine that runs the OpenCV application.

UPDATE

OpenCV doesn't have a function to get the list of available codecs. To a get list of available codecs you need to call some system function. Pn Windows On Windows, OpenCV just calls the function that pup up the OS codec form.

BTW each codec follows some specs (frame size or ratio, fps, compression ...) thus if your app provides codec selection you have to manage codec specs too.

You might define a vector of supported codecs than test if they are available at start-up with multiple calls to VideoWriter::open and write. Something like this:

vector<int> availableCodecs;
vector<int> supportedCodec({
    CV_FOURCC('M','J','P','G'), 
    CV_FOURCC('M','R','L','E'), 
    others you can support ...
    });

for(int i=0; i<supportedCodec.size(); i++) {
    VideoWriter vw("test.avi", supportedCodec[i], ...);
    if(vw.isOpened()) 
        if (vw.write(testImg))
            availableCodecs.push_back(supportedCodec[i]);
    vw.release();    
}

endUPDATE

after this, some points:

  • Use int codec=CV_FOURCC('M','R','L',E') for Microsoft RLE (see this http://www.fourcc.org/mrle/). This codec is native on Windows.
  • If FFMPEG is enabled in your OpenCV bin, using codec=0; fps=0; you can create an uncompressed (raw) video file. In this case you have to deploy the ffmpeg's DLL with your exe.
  • You can save image sequence using a proper filename (eg. img_%02d.jpg) and fourcc=0 OR fps=0. Use uncompressed image format (eg. img_%02d.BMP) to save raw frames.
  • not compressed... did you mean lossless ? In this case you might install and use some lossless codec like Huffman (HFYU), Lagarith (LAGS). You will have about 30% of compression without quality loss. Even in this case the codec must be available on target system.

I would suggest to install some 3rd party codec pack, (take a look also to ffdshow). This will install on your system a lot of codecs (e.g. MPEG, DIVX, H264, HFYU,...) that you can use with many applications including OpenCV or VirtualDub.

Remember that on Windows, cv::VideoWriter uses VFW (Video For Windows API) thus any available codec that is VFW compliant can be used with VideoWriter.

To check for installed Video Codecs on your system:

  • just run Windows Media Player, enable the menu bar than About > Technical Info
  • OR run MSINFO32.exe than components > Multimedia > Codec video
  • OR use OpenCV with codec = -1. VideoWriter pops up codec selection dialog from the system, the list include all available and compatible codecs.

Finally, get the 4 char code (fourcc) for your selected codec from http://www.fourcc.org/ and create the int code using int codec = CV_FOURCC(...) macro as above.

I hope this helps

1st of all, codecs must be available on your system at runtime and doesn't depends on OpenCV but depends on codec you have installed on your system. This means that the codec must be available on the machine that runs the OpenCV application.

UPDATE

OpenCV doesn't have a function to get the list of available codecs. To a get list of available codecs you need to call some system function. On Windows, OpenCV just calls the function that pup up the OS codec form.

The CV_FOURCC('M','J','P','G') codec should be supported natively by OpenCV (no need of external library)

BTW each codec follows some specs (frame size or ratio, fps, compression ...) thus if your app provides codec selection you have to manage codec specs too.

You might define a vector of supported codecs than test if they are available at start-up with multiple calls to VideoWriter::open and write. Something like this:

vector<int> availableCodecs;
vector<int> supportedCodec({
    CV_FOURCC('M','J','P','G'), 
    CV_FOURCC('M','R','L','E'), 
    others you can support ...
    });

for(int i=0; i<supportedCodec.size(); i++) {
    VideoWriter vw("test.avi", supportedCodec[i], ...);
    if(vw.isOpened()) 
        if (vw.write(testImg))
            availableCodecs.push_back(supportedCodec[i]);
    vw.release();    
}

endUPDATE

after this, some points:

  • Use int codec=CV_FOURCC('M','R','L',E')codec=CV_FOURCC('M','R','L','E') for Microsoft RLE (see this http://www.fourcc.org/mrle/). This codec is native on Windows.
  • If FFMPEG is enabled in your OpenCV bin, using codec=0; fps=0; you can create an uncompressed (raw) video file. In this case you have to deploy the ffmpeg's DLL with your exe.
  • You can save image sequence using a proper filename (eg. img_%02d.jpg) and fourcc=0 OR fps=0. Use uncompressed image format (eg. img_%02d.BMP) to save raw frames.
  • not compressed... did you mean lossless ? In this case you might install and use some lossless codec like Huffman (HFYU), Lagarith (LAGS). You will have about 30% of compression without quality loss. Even in this case the codec must be available on target system.

I would suggest to install some 3rd party codec pack, (take a look also to ffdshow). This will install on your system a lot of codecs (e.g. MPEG, DIVX, H264, XVID, X264, HFYU,...) that you can use with many applications including OpenCV or VirtualDub.

Remember that on Windows, cv::VideoWriter uses VFW (Video For Windows API) thus any available codec that is VFW compliant can be used with VideoWriter.

To check for installed Video Codecs on your system:

  • just run Windows Media Player, enable the menu bar than About > Technical Info
  • OR run MSINFO32.exe than components > Multimedia > Codec video
  • OR use OpenCV with codec = -1. VideoWriter pops up codec selection dialog from the system, the list include all available and compatible codecs.

Finally, get the 4 char code (fourcc) for your selected codec from http://www.fourcc.org/ and create the int code using int codec = CV_FOURCC(...) macro as above.

I hope this helps

1st of all, codecs must be available on your system at runtime and doesn't depends on OpenCV but depends on codec you have installed on your system. This means that the codec must be available on the machine that runs the OpenCV application.

UPDATE

OpenCV doesn't have a function to get the list of available codecs. To a get list of available codecs you need to call some system function. On Windows, OpenCV just calls the function that pup up the OS codec form.

The CV_FOURCC('M','J','P','G') codec should be supported natively by OpenCV (no need of external library)

BTW each codec follows some specs (frame size or ratio, fps, compression ...) thus if your app provides codec selection you have to manage codec specs too.

You might define a vector of supported codecs than test if they are available at start-up with multiple calls to VideoWriter::open and write. Something like this:

Size myFrameSize(320,240); //codecs are sensible to frame size
Mat testImg(myFrameSize,CV_8UC3); //and frame depth

vector<int> availableCodecs;
vector<int> supportedCodec({
    CV_FOURCC('M','J','P','G'), 
    CV_FOURCC('M','R','L','E'), 
    others you can support ...
    });

for(int i=0; i<supportedCodec.size(); i++) {
    VideoWriter vw("test.avi", supportedCodec[i], ...);
    if(vw.isOpened()) 
        if (vw.write(testImg))
            availableCodecs.push_back(supportedCodec[i]);
    vw.release();    
}

endUPDATE

after this, some points:

  • Use int codec=CV_FOURCC('M','R','L','E') for Microsoft RLE (see this http://www.fourcc.org/mrle/). This codec is native on Windows.
  • If FFMPEG is enabled in your OpenCV bin, using codec=0; fps=0; you can create an uncompressed (raw) video file. In this case you have to deploy the ffmpeg's DLL with your exe.
  • You can save image sequence using a proper filename (eg. img_%02d.jpg) and fourcc=0 OR fps=0. Use uncompressed image format (eg. img_%02d.BMP) to save raw frames.
  • not compressed... did you mean lossless ? In this case you might install and use some lossless codec like Huffman (HFYU), Lagarith (LAGS). You will have about 30% of compression without quality loss. Even in this case the codec must be available on target system.

I would suggest to install some 3rd party codec pack, (take a look also to ffdshow). This will install on your system a lot of codecs (e.g. XVID, X264, HFYU,...) that you can use with many applications including OpenCV or VirtualDub.

Remember that on Windows, cv::VideoWriter uses VFW (Video For Windows API) thus any available codec that is VFW compliant can be used with VideoWriter.

To check for installed Video Codecs on your system:

  • just run Windows Media Player, enable the menu bar than About > Technical Info
  • OR run MSINFO32.exe than components > Multimedia > Codec video
  • OR use OpenCV with codec = -1. VideoWriter pops up codec selection dialog from the system, the list include all available and compatible codecs.

Finally, get the 4 char code (fourcc) for your selected codec from http://www.fourcc.org/ and create the int code using int codec = CV_FOURCC(...) macro as above.

I hope this helps

1st of all, codecs must be available on your system at runtime and doesn't depends on OpenCV but depends on codec you have installed on your system. This means that the codec must be available on the machine that runs the OpenCV application.

UPDATE

OpenCV doesn't have a function to get the list of available codecs. To a get list of available codecs you need to call some system function. On Windows, OpenCV just calls the function that pup up the OS codec form.

The CV_FOURCC('M','J','P','G') codec should be supported natively by OpenCV (no need of external library)

BTW each codec follows some specs (frame size or ratio, fps, compression ...) thus if your app provides codec selection you have to manage codec specs too.

You might define a vector of supported codecs than test if they are available at start-up with multiple calls to VideoWriter::open and write. Something like this:

Size myFrameSize(320,240); //codecs are sensible to //some codecs have limitations about frame size
Mat testImg(myFrameSize,CV_8UC3); //and frame depth

vector<int> availableCodecs;
vector<int> supportedCodec({
    CV_FOURCC('M','J','P','G'), 
    CV_FOURCC('M','R','L','E'), 
    others you can support ...
    });

for(int i=0; i<supportedCodec.size(); i++) {
    VideoWriter vw("test.avi", supportedCodec[i], ...);
    if(vw.isOpened()) 
        if (vw.write(testImg))
            availableCodecs.push_back(supportedCodec[i]);
    vw.release();    
}

endUPDATE

after this, some points:

  • Use int codec=CV_FOURCC('M','R','L','E') for Microsoft RLE (see this http://www.fourcc.org/mrle/). This codec is native on Windows.
  • If FFMPEG is enabled in your OpenCV bin, using codec=0; fps=0; you can create an uncompressed (raw) video file. In this case you have to deploy the ffmpeg's DLL with your exe.
  • You can save image sequence using a proper filename (eg. img_%02d.jpg) and fourcc=0 OR fps=0. Use uncompressed image format (eg. img_%02d.BMP) to save raw frames.
  • not compressed... did you mean lossless ? In this case you might install and use some lossless codec like Huffman (HFYU), Lagarith (LAGS). You will have about 30% of compression without quality loss. Even in this case the codec must be available on target system.

I would suggest to install some 3rd party codec pack, (take a look also to ffdshow). This will install on your system a lot of codecs (e.g. XVID, X264, HFYU,...) that you can use with many applications including OpenCV or VirtualDub.

Remember that on Windows, cv::VideoWriter uses VFWMJPG or VFW API (Video For Windows API) Windows) thus MJPG codec or any available codec that is VFW compliant can be used with VideoWriter.

To check for installed Video Codecs on your system:

  • just run Windows Media Player, enable the menu bar than About > Technical Info
  • OR run MSINFO32.exe than components > Multimedia > Codec video
  • OR use OpenCV with codec = -1. VideoWriter pops up codec selection dialog from the system, the list include all available and compatible codecs.

Finally, get the 4 char code (fourcc) for your selected codec from http://www.fourcc.org/ and create the int code using int codec = CV_FOURCC(...) macro as above.

I hope this helps

1st of all, codecs must be available on your system at runtime and doesn't depends on OpenCV but depends on codec you have installed on your system. This means that the codec must be available on the machine that runs the OpenCV application.

UPDATE

OpenCV doesn't have a function to get the list of available codecs. To a get list of available codecs you need to call some system function. On Windows, OpenCV just calls the function that pup up the OS codec form.

The CV_FOURCC('M','J','P','G') codec should be supported natively by OpenCV (no need of external library)

BTW each codec follows some specs (frame size or ratio, fps, compression ...) thus if your app provides codec selection you have to manage codec specs too.

You might define a vector of supported codecs than test if they are available at start-up with multiple calls to VideoWriter::open and write. Something like this:

Size myFrameSize(320,240); //some codecs have limitations about frame size
Mat testImg(myFrameSize,CV_8UC3); //and frame depth

vector<int> availableCodecs;
vector<int> supportedCodec({
    CV_FOURCC('M','J','P','G'), 
    CV_FOURCC('M','R','L','E'), 
    others you can support ...
    });

VideoWriter vw;
for(int i=0; i<supportedCodec.size(); i++) {
    VideoWriter vw("test.avi", vw.open("test.avi", supportedCodec[i], ...);
    if(vw.isOpened()) 
        if (vw.write(testImg))
            availableCodecs.push_back(supportedCodec[i]);
    vw.release();    
}

endUPDATE

after this, some points:

  • Use int codec=CV_FOURCC('M','R','L','E') for Microsoft RLE (see this http://www.fourcc.org/mrle/). This codec is native on Windows.
  • If FFMPEG is enabled in your OpenCV bin, using codec=0; fps=0; you can create an uncompressed (raw) video file. In this case you have to deploy the ffmpeg's DLL with your exe.
  • You can save image sequence using a proper filename (eg. img_%02d.jpg) and fourcc=0 OR fps=0. Use uncompressed image format (eg. img_%02d.BMP) to save raw frames.
  • not compressed... did you mean lossless ? In this case you might install and use some lossless codec like Huffman (HFYU), Lagarith (LAGS). You will have about 30% of compression without quality loss. Even in this case the codec must be available on target system.

I would suggest to install some 3rd party codec pack, (take a look also to ffdshow). This will install on your system a lot of codecs (e.g. XVID, X264, HFYU,...) that you can use with many applications including OpenCV or VirtualDub.

Remember that on Windows, cv::VideoWriter uses MJPG or VFW API (Video For Windows) thus MJPG codec or any available codec that is VFW compliant can be used with VideoWriter.

To check for installed Video Codecs on your system:

  • just run Windows Media Player, enable the menu bar than About > Technical Info
  • OR run MSINFO32.exe than components > Multimedia > Codec video
  • OR use OpenCV with codec = -1. VideoWriter pops up codec selection dialog from the system, the list include all available and compatible codecs.

Finally, get the 4 char code (fourcc) for your selected codec from http://www.fourcc.org/ and create the int code using int codec = CV_FOURCC(...) macro as above.

I hope this helps