# Revision history [back]

As Berak said, it's not a good idea to combine these images into a single 3 channel image. You make unnecessary memory operations and disk writing.

For vodeo files (avi or similar) there are no 16 bit codecs. You can save a series of 8 and 16 bit TIF files, but I think it's quite slow, so it won't work at 25+ fps.

The best way to do this (especially if the image size is known) would be to dump directly the data to the disk. Something like (c++ code):

ofstream myfile; myfile.open ("video.dat",ios::binary); uchar frame1=new uchar[wh]; ushort frame2=new ushort[wh]; Mat i1(w,h,frame1,CV_8UC1); Mat i2(w,h,frame2,CV_16UC1); .... myfile.write(frame1,wh); myfile.write(frame2,wh*2); ...//repeat for every frame myfile.close();

When reading the data, just do the opposite operations:

while(!myfile.eof()){
}


As Berak said, it's not a good idea to combine these images into a single 3 channel image. You make unnecessary memory operations and disk writing.

For vodeo files (avi or similar) there are no 16 bit codecs. You can save a series of 8 and 16 bit TIF files, but I think it's quite slow, so it won't work at 25+ fps.

The best way to do this (especially if the image size is known) would be to dump directly the data to the disk. Something like (c++ code):

code, only with two frames to keep things simple):

ofstream myfile;
myfile.open ("video.dat",ios::binary);
uchar frame1=new uchar[wh];
*frame1=new uchar[w*h];
ushort frame2=new ushort[wh];
*frame2=new ushort[w*h];
Mat i1(w,h,frame1,CV_8UC1);
Mat i2(w,h,frame2,CV_16UC1);
....
myfile.write(frame1,wh);
myfile.write(frame2,wh*2);
myfile.write(frame1,w*h);
myfile.write(frame2,w*h*2);
...//repeat for every frame
myfile.close();myfile.close();


When reading the data, just do the opposite operations:

while(!myfile.eof()){

By knowing the size of a data chunk (sizeof(frame1)+sizeof(frame2)+...), you can jump directly to a given frame, too.