title: How to write the Mat/Image to the RTMP stream in OpenCV
body: <p>I can open RTSP video stream by using the <code>VideoCapture</code> and read the frames.</p>
  <p>It is the URL of RTSP stream:</p>
  <pre><code>rtsp://username:password@xxx.xxx.xxx.xxx:554/Streaming/Channels/102
  </code></pre>
  <p>Now I want to send/write the image/mat back to the output stream (RTMP stream over LAN network)</p>
  <p>I have already set up the RTMP server which is NGINX, and for a test, I downloaded the <a href="http://ffmpeg.org/download.html#build-windows" rel="noreferrer">FFMPEG</a>, and when running the following command (in CMD) then it works well, and successfully read and write the stream to NGINX server.</p>
  <pre><code>ffmpeg -i rtsp://username:password@xxx.xxx.xxx.xxx:554/Streaming/Channels/102 -vcodec copy -acodec copy -f flv rtmp://xxx.xxx.xxx.xxx:1395/mylive/test
  </code></pre>
  <p>And now if I put this <code>rtmp://xxx.xxx.xxx.xxx:1395/mylive/test</code> URL to the <code>video</code> tag of <code>HTML</code>, then the video can be opened.</p>
  <p><strong>So</strong> the question is how I can push the image through RTMP (NGINX) from my code after processing?</p>
  <p>Any suggestion. Thanks in advance!!</p>
  <p><strong>Edit:</strong></p>
  <p>I used <code>VideoWriter</code> class as the following ways, but no one was working:</p>
  <pre><code>VideoWriter writer = new VideoWriter();
  writer.open(&quot;rtmp://xxx.xxx.xxx.xxx:1395/mylive/test&quot;, CAP_FFMPEG, 0, 25, 
  new Size(640, 480));
  //writer.open(&quot;ffmpeg -vcodec copy -acodec copy -f flv 
  //rtmp://xxx.xxx.xxx.xxx:1395/mylive/test&quot;, CAP_FFMPEG, 0, 25, new Size(640, 
  //480));
  // or without CAP_FFMPEG
  if (!writer.isOpened()) {
      System.out.println(&quot;open error&quot;);
  }
  </code></pre>