"Could not demultiplex stream" in loading Video recorded by Opencv's VideoWriter
<p>My program is</p>

<pre><code>int main(){
    cout &lt;&lt; "Start the process" &lt;&lt; endl;
    cv::VideoCapture vcap("rtsp://root:pass@192.168.0.90/axis-media/media.amp?camera=1");
    cout &lt;&lt; "Camera connection done!" &lt;&lt; endl;
    cv::Mat image, small;
    //Output video
    cv::Size S = cv::Size((int) vcap.get(CV_CAP_PROP_FRAME_WIDTH), (int) vcap.get(CV_CAP_PROP_FRAME_HEIGHT));
    int ex = static_cast&lt;int&gt;(vcap.get(CV_CAP_PROP_FOURCC));
    int fps = vcap.get(CV_CAP_PROP_FPS);
    cout &lt;&lt; "fps " &lt;&lt; fps &lt;&lt; " ex " &lt;&lt; ex &lt;&lt; endl;
    cv::VideoWriter outputVideo;
    outputVideo.open("TEST.avi", ex/*CV_FOURCC('X', '2', '6', '4')*/, vcap.get(CV_CAP_PROP_FPS), S, true);
    if(!outputVideo.isOpened()){
        cout &lt;&lt; "Could not open the output video for write" &lt;&lt; endl;
        return -1;
    }

    for(;;){
        if(!vcap.read(image)){
            std::cout &lt;&lt; "No frame" &lt;&lt; std::endl;
            cv::waitKey(0);
        }

        cv::resize(image, small, image.size()/2, 0, 0 , cv::INTER_LINEAR);
        cv::imshow("Display", small);
        cv::waitKey(1);
        outputVideo.write(small);
        if(getkey() == '\n')
            break;
    }
    cout &lt;&lt; "Camera release" &lt;&lt; endl;
    outputVideo.release();
    vcap.release();
    image.release();
    small.release();
    return 0;
}
</code></pre>

<p><code>int ex = static_cast&lt;int&gt;(vcap.get(CV_CAP_PROP_FOURCC));</code> ex is 0 here.</p>

<p>I can record the TEST.avi, but can't be read by cv::VideoCapture vcap("TEST.avi"); or VLC player or Videos in Ubuntu.
The error is <code>"Could not demultiplex stream"</code>.</p>

<p>If I changed to </p>

<pre><code>outputVideo.open("TEST.avi", CV_FOURCC('X', '2', '6', '4'), vcap.get(CV_CAP_PROP_FPS), S, true);
outputVideo.open("TEST.avi", CV_FOURCC('P','I','M','1'), vcap.get(CV_CAP_PROP_FPS), S, true);
outputVideo.open("TEST.avi", CV_FOURCC('M', 'P', '4', '2'), vcap.get(CV_CAP_PROP_FPS), S, true);
etc.
</code></pre>

<p>all have same problem.</p>

<p>If I set </p>

<pre><code>outputVideo.open("TEST.avi", CV_FOURCC('i', 'Y', 'U', 'V'), vcap.get(CV_CAP_PROP_FPS), S, true);
</code></pre>

<p>I have error as <code>Opencv: FFMPEG iYUV is not supported with codec id 14</code></p>

<p>For</p>

<pre><code>outputVideo.open("TEST.avi", CV_FOURCC('M', 'J', 'P', 'G'), vcap.get(CV_CAP_PROP_FPS), S, true);


OpenCV Error: Assertion failed (img.cols == width &amp;&amp; img.rows == height &amp;&amp; chann
els == 3) in write, file /home/Softwares/opencv/opencv/modules/videoio/src/
cap_mjpeg_encoder.cpp, line 829
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/Softwares/opencv/opencv/modules/videoio/src/cap_mjpeg_enco
der.cpp:829: error: (-215) img.cols == width &amp;&amp; img.rows == height &amp;&amp; channels =
= 3 in function write
</code></pre>

<p>What could be wrong? Is that my FFMPEG has problem?</p>