title: OpenCV android VideoWriter issue
body: <p>I have a problem using VideoWriter opencv class with JNI in android.</p>
  
  <p>My aim is to simply capture camera frames and write them to file using VideoWriter.</p>
  
  <p>Here is the code:</p>
  
  <p><strong>Native part</strong> - 3 functions to init writer, write a frame and release the writer.</p>
  
  <pre><code>JNIEXPORT void JNICALL Java_com_driveassist_drivingassistant_WorkActivity_InitWriter(JNIEnv *env, jobject, jstring path)
  {
      char const * new_path;
      new_path = env-&gt;GetStringUTFChars(path , NULL ) ;
  
      writer = VideoWriter();
  
      stringstream ss;
      ss &lt;&lt; new_path;
      ss &lt;&lt; "//1.mp4";
  
      string p;
      ss &gt;&gt; p;
  
      writer.open(p, CV_FOURCC('P', 'I', 'M', '1'), 24, Size(1024, 768));
  }
  
  JNIEXPORT void JNICALL Java_com_driveassist_drivingassistant_WorkActivity_WriteFrame(JNIEnv *, jobject, jlong frame)
  {
      Mat* im=(Mat*)frame;
      Mat im_p = (*im).clone();
  
      if(writer.isOpened())
      {
          resize(im_p, im_p, Size(1024, 768), 0, 0, INTER_AREA);
  
          writer.write(im_p);
      }
  
  }
  
  JNIEXPORT void JNICALL Java_com_driveassist_drivingassistant_WorkActivity_ReleaseWriter(JNIEnv *, jobject)
  {
      if(writer.isOpened())
      {
          writer.release();
      }
  }
  </code></pre>
  
  <p><strong>Java part:</strong> </p>
  
  <p>I use an activity with opencv CameraBridgeViewBase:</p>
  
  <pre><code>public class WorkActivity extends Activity implements CvCameraViewListener {
  
      private CameraBridgeViewBase   mOpenCvCameraView;
  
      private Mat mRgba;
  
      private File mediaStorageDir;
  
      private BaseLoaderCallback     mLoaderCallback = new BaseLoaderCallback(this) {
          @Override
          public void onManagerConnected(int status) {
              switch (status) {
                  case LoaderCallbackInterface.SUCCESS:
                  {
                      System.loadLibrary("driving_assistant");
  
                      mOpenCvCameraView.enableView();
  
                      InitWriter(mediaStorageDir.getPath());
                  } break;
                  default:
                  {
                      super.onManagerConnected(status);
                  } break;
              }
          }
      };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  
          setContentView(R.layout.activity_work);
  
          mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "DriveAssistantCam");
  
          if (! mediaStorageDir.exists()){
              if (! mediaStorageDir.mkdirs()){
                  Log.d("DrivingAssistant", "failed to create directory");
              }
          }
  
          mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.work_camera_surface_view);
  
          mOpenCvCameraView.setCvCameraViewListener(this);
      }
  
      @Override
      public void onPause()
      {
          if (mOpenCvCameraView != null)
              mOpenCvCameraView.disableView();
  
          super.onPause();
  
          // ReleaseWriter();
      }
  
      @Override
      public void onResume()
      {
          super.onResume();
  
          OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
  
          // OpenCVLoader.initDebug();
      }
  
      public void onDestroy() {
          super.onDestroy();
  
          if (mOpenCvCameraView != null)
              mOpenCvCameraView.disableView();
  
          ReleaseWriter();
      }
  
      public void onCameraViewStarted(int width, int height) {
          mRgba = new Mat(height, width, CvType.CV_8UC4);
      }
  
      public void onCameraViewStopped() {
          mRgba.release();
  
          ReleaseWriter();
      }
  
      public Mat onCameraFrame(Mat inputFrame) {
          inputFrame.copyTo(mRgba);
  
          WriteFrame(mRgba.getNativeObjAddr());
  
          return mRgba;
      }
  </code></pre>
  
  <p>The code runs with no exceptions, but the video file doesn't appear. The native library loads normally, and application has access to the directory (I've tried creating a file there with java.io.File).</p>
  
  <p>My system is Ubuntu 12.10, Eclipse Indigo. I've tried this code on emulator and galaxy tab 2.</p>
  
  <p>Many thanks!</p>