Skip to content

Instantly share code, notes, and snippets.

@takuma7
Last active April 3, 2024 07:29
Show Gist options
  • Star 74 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save takuma7/44f9ecb028ff00e2132e to your computer and use it in GitHub Desktop.
Save takuma7/44f9ecb028ff00e2132e to your computer and use it in GitHub Desktop.
OpenCV Video Writer on Mac OS X

OpenCV Video Writer on Mac OS X

Fourcc tests:

  • x : not worked
  • o: worked (able to open in quicktime but need conversion)
  • oo: worked well (preview worked but wrong aspect ratio)
  • ooo: worked very well (preview worked, and aspect ratio’s right)

(Codecs are extracted from https://web.archive.org/web/20120722124832/http://opencv.willowgarage.com/wiki/QuickTimeCodecs )

FourCC Result Codec Name Description
‘3IV2' x 3ivx D4 4.5.1 Compresses an image into 3ivx D4 format.
‘8BPS' o Apple Planar RGB Compresses images in the Planar RGB format.
‘SVQ1' o Sorenson Video™ Compressor Compresses video using the Sorenson Video™ V2.30.302 compressor from Sorenson™ Media, Inc.
‘SVQ3' o Sorenson Video 3 Compressor Compresses video using the Sorenson Video® 3 SE V 3.3.302 compressor from Sorenson® Media, Inc.
‘WRLE' o Apple BMP Compresses images in the BMP format.
‘XVID' x XviD Decompresses video stored in XviD format.
‘avc1' ooo H.264 Encoder Compresses video to the H.264 format.
‘cvid' o Apple Cinepak Compresses images using Apple Computer's Cinepak compression algorithm
‘dv5n' oo Apple DVCPRO50 - NTSC Compresses an image to DVCPRO50 NTSC format.
‘dv5p' oo Apple DVCPRO50 - PAL Compresses an image to DVCPRO50 PAL format.
'dvc ‘ oo Apple DV/DVCPRO - NTSC Compresses an image to DV/DVCPRO NTSC format.
‘dvcp' oo Apple DV - PAL Compresses an image to DV PAL format.
‘dvpp' oo Apple DVCPRO - PAL Compresses an image to DVCPRO PAL format.
‘h261’ o (but small) Apple H.261 Compresses images using H.261 compression algorithm
‘h263’ ooo (but small) H.263 Compresses images using H.263 compression algorithm
‘jpeg' ooo Apple Photo - JPEG Compresses images using the ISO standard baseline JPEG algorithm
‘mjp2' o JPEG 2000 Encoder Compresses images to the JPEG 2000 JP2 format.
‘mjpa' o Apple Motion JPEG A Compresses images compressed using Motion JPEG Format A
‘mjpb' o Apple Motion JPEG B Compresses images compressed using Motion JPEG Format B
‘mp4v' ooo Apple MPEG4 Compressor Compresses images using MPEG4 compression algorithm
'png ‘ o Apple PNG Compresses images in the PNG format.
‘pxlt' o Apple Pixlet Video Apple Pixlet Video Info
'raw ‘ ooo (but preview didn’t work) Apple None Stores images without any compression
'rle ‘ o Apple Animation Compresses images using run length encoding
‘rpza' o Apple Video Compresses images using Apple Computer's Video compression algorithm
'smc ‘ x Apple Graphics Compresses images using Sean's secret recipe (optimal for 8-bit dithered images)
'tga ‘ o Apple TGA Compresses images stored into the TGA format.
‘tiff' o Apple TIFF Compresses images in the TIFF format.
‘yuv2' o Apple Component Video - YUV422 Compresses an image into YUV format.

Conclusion

Use 'mp4v' or 'avc1'

@chrisidefix
Copy link

Another codec that worked for me: MJPG and one that I could not get to work: DIVX
I added a list of file size comparisons in my fork to see how much compression each codec offers.

In terms of quality and size avc1 (H.264) is the overall winner - best compression ratio and pretty much no block artefacts, compared to mp4v.

@xujialiang
Copy link

Do I need install any other codec?

@stephanschulz
Copy link

stephanschulz commented Jan 30, 2018

I tried a whole bunch but then opening the recorded files in quicktime the codec mostly ended up being H264.
I was hoping to use the recorded videos to looped them in PALINDROME mode. But playing these videos back in reverse causes a stutter, which I believe is due to the codec.

 //                outputVideo.open(filePath,CV_FOURCC('M','J','P','G'),30, cv::Size(1920,1080),isColor);
//                outputVideo.open(filePath,CV_FOURCC('P','I','M','1'),30, cv::Size(1920,1080),isColor);
//                outputVideo.open(filePath,CV_FOURCC('R','P','Z','A'),30, cv::Size(1920,1080),isColor); //apple video
//                outputVideo.open(filePath,CV_FOURCC('G','P','E','G'),30, cv::Size(1920,1080),isColor); //motion jpeg
//                outputVideo.open(filePath,CV_FOURCC('A','V','C','1'),30, cv::Size(1920,1080),isColor); //Compresses video to the H.264 format.
//                outputVideo.open(filePath,CV_FOURCC('W','R','L','E'),30, cv::Size(1920,1080),isColor); //Compresses images in the BMP format.
//                outputVideo.open(filePath,CV_FOURCC('J','P','E','G'),30, cv::Size(1920,1080),isColor); //Apple Photo - JPEG
//                outputVideo.open(filePath,CV_FOURCC('P','N','G',' '),30, cv::Size(1920,1080),isColor); //png
//                outputVideo.open(filePath,CV_FOURCC('I','Y','U','Y'),30, cv::Size(1920,1080),isColor); //png
//                outputVideo.open(filePath,CV_FOURCC('F','F','V','1'),30, cv::Size(1920,1080),isColor); //
//                outputVideo.open(filePath,CV_FOURCC('H','E','V','C'),30, cv::Size(1920,1080),isColor); //
//                outputVideo.open(filePath,CV_FOURCC('H','D','Y','C'),30, cv::Size(1920,1080),isColor); //
//                outputVideo.open(filePath,-1,30, cv::Size(1920,1080),isColor); // 
//                outputVideo.open(filePath, CV_FOURCC('Y', '4', '2', '2'),30, cv::Size(1920,1080),isColor); //                 
//                outputVideo.open(filePath, CV_FOURCC('r', 'a', 'w', ' '),30, cv::Size(1920,1080),isColor); //        
outputVideo.open(filePath, CV_FOURCC('m', 'p', '4', 'v'),30, cv::Size(1920,1080),isColor); //    

@bwomsm1
Copy link

bwomsm1 commented Feb 22, 2023

@chrisidefix @xujialiang @stephanschulz
Does anyone managed to record on mac os?

@stephanschulz
Copy link

I have not worked on this for a while. But at this point I would use the HAP codec with which I had good results.

@bwomsm1
Copy link

bwomsm1 commented Feb 22, 2023

I have not worked on this for a while. But at this point I would use the HAP codec with which I had good results.

thanks @stephanschulz but what are you referring to by saying HAP, its not showing in the table above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment