tags:

views:

833

answers:

1

i am using JNA to be able to run opencv under java. works pretty fine until i need to write a video to the file system. the same code is running on windows without any problem (video is written using any of the cv_fourcc suggestions). however, the same code does not work under osx. the problem is i do not get any error at all. the video is actually written on the file system (about 50 MB per 20 seconds or so) but i cannot open it using any of the common players including quicktime and vlc. does any of you have the same kind of issues? if not how did you circumvent these issues? is compiling and installing opencv using ffmpeg the solution?

here is an actual code-snippet from my program (the input msg contains the video data from the webcam in a byte[] and the cvFourCC is used to encode the four chars as in the macro provided in opencv):

public int cvFourCC(char c1, char c2, char c3, char c4){

 return (((c1)&255) + (((c2)&255)<<8) + (((c3)&255)<<16) + (((c4)&255)<<24));
}

@Override
public Void handleMessage(WriteVideoToFileInput msg) {
 size.width = msg.width;
 size.height = msg.height;

 if (writer == null) {
  System.out.println(this.name + ": creating CvVideoWriter");
  writer = HighGUI.INSTANCE.cvCreateVideoWriter(filename, 
       fourcc, 
       fps, 
       size, 
       isColor);
  System.out.println(this.name + ": done");
 }

 // generate and allocate image
 if (image == null) {
  System.out.println(this.name + ": creating working image (CvVideoWriter) image");
  image = OpenCVCore.INSTANCE.cvCreateImage(size, msg.depth, msg.nChannels);
  System.out.println(this.name + ": done");
 }

 for (int i = 0; i < msg.imageData.length; i++) {
  image.imageData.getPointer().setByte(i, msg.imageData[i]);
 }

 HighGUI.INSTANCE.cvWriteFrame(writer, image);

 return null;
}

thanks a lot in advance!

kyoto

A: 

I have the same problem using OpenCV in C++ on OS X - it creates a file, but no video program I have (QuickTime, FFMpegX, or VLC) will read it. FFMpeg reports it as an empty MOV container regardless of which codec I tell it to use. This problem has seriously impeded my progress, to the point where I've been trying to recompile OpenCV using FFMpeg so I can actually use it, but to no avail - I keep getting compiler errors.

Anyone have any idea? I'm using g++ 4.0.1 (Apple build 5493), on powerpc-apple-darwin9, if that makes a difference.