0

I am trying to save frames coming from external camera, as an mp4 video. However, getting an error at videoWriter.open(...). I tried many FourCC types like ('m', 'p', '4', 'v'), ('M', 'J', 'P', 'G') but the error doesn't change. The code block:

   const string NAME = filename + "_000001.mp4";
   Size S = Size((int) height,(int) width);
   int ex = CV_FOURCC('X', 'V', 'I', 'D');
   videoWriter.open(NAME, ex, fps, S, false);

The error:

E/cv::error(): OpenCV(4.5.4) Error: Requested object was not found (could not open directory: /data/app/~~3oEemcnUha6ad_KvvVbBFw==/com.package.m_package-4H7_P1OcGVlr0XBiDa45iA==/base.apk!/lib/arm64-v8a) in glob_rec, file /build/master_pack-android/opencv/modules/core/src/glob.cpp, line 279

However, when i change the format as AVI, no error occurs and the program works correctly. The working code block:

    const string NAME = filename + ".avi";
    LOGE("%s: NAME = %s\n", __FUNCTION__, NAME.c_str());
    Size S = Size((int) width,(int) height);
    int ex = CV_FOURCC('M', 'J', 'P', 'G');
    videoWriter.open(NAME, ex, fps, S, true);

I also installed ffmpeg into the testing device via Termux. (I don't know if it is required or not). Cmake version: 3.22.1. OpenCV version: 4.5.4.

Talha Ç
  • 74
  • 1
  • 8

1 Answers1

0

"XVID" is not valid as MPEG fourCC. (also: XVID-encoded video is usually stored inside AVI files)

You can try:

 const string NAME = filename + ".mp4";
 Size S = Size((int) height,(int) width);
 int ex = CV_FOURCC('M', 'P', '4', 'V');
 videoWriter.open(NAME, ex, fps, S, false);
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • I tried this fourCC too as i mentined in the question. The result did not change. I am still getting the same error. – Talha Ç Oct 14 '22 at 06:41
  • **(1)** Did you try the fourCC with this setup `const string NAME = filename + ".mp4";`? Because [your glob error is related to not finding the file name/path](https://www.php.net/manual/en/function.glob.php). You said it works, if you make an AVI **without the underscore** like in name of `_000001.mp4` ... **Possible solution:** Try an MP4 file name without underscore and also with `CV_FOURCC('M', 'P', '4', 'V');` ... **(2)** What happens if you use a direct output (or folder) path like `c:\test\filename.mp4`? – VC.One Oct 23 '22 at 18:55
  • I tried the fourCC ('M', 'P', '4', 'V') with this setup. And also tried with a path without an underscore like your example too. The problem was not solved in any way and I kept getting the same error. The interesting thing is when i change the mp4 with avi, the problem is solving. Finally, I gave up and i solved this problem at java side by javacv library. – Talha Ç Oct 24 '22 at 12:08
  • OK. Let's hope future versions of OpenCV fix that issue. PS: Some say that [MP4 doesn't work with videoWriter](https://stackoverflow.com/a/55519769/2057709) .... but then some say [it works if they use h264 fourCC](https://stackoverflow.com/a/68390841/2057709). – VC.One Oct 24 '22 at 12:25