CvVideoWriter get current fourcc

asked 2016-08-28 10:48:18 -0600

mvidelgauz gravatar image

Using class cv::VideoWriter I can specify CV_FOURCC_PROMPT (which is -1) as fourcc parameter in constructor or its open function, in which case "Open Codec Selection Dialog" will be opened and user will select one of installed codecs. My application will perform video recording several times and I want to avoid asking user the same question more than once.

Is there a way to retrieve user selected codec from already opened cv::VideoWriter instance and re-use it as fourcc parameter for other instances?

edit retag flag offensive close merge delete

Comments

take a look at this

sturkmen gravatar imagesturkmen ( 2016-08-28 15:11:17 -0600 )edit

@sturkmen Thank you, but that code uses VideoCapture object, which I don't have in my software, as well as any other opencv input object. My images are generated by another part of software not made with opencv. Are you saying that I need to open first generated avi file for input just to read its codec? What if I need to create second output in another thread while first one is not closed yet?

mvidelgauz gravatar imagemvidelgauz ( 2016-08-28 15:30:40 -0600 )edit

so, you're using opencv only for saving video ? that might be a bad idea. still:

  • if you know the codec before, you can pass it to the VideoWriter via VideoWriter::fourcc() (in other words, you don't have to use the prompt, if you don't want to.)

  • unfortunately, codecs are installed per machine, so you can never rely on any special codec available on an unknown box.

  • opencv3 comes with a self-contained MJPEG codec (which is guaranteed to work w/o any dependancies, use 'M','J','P','G' for codec, and .avi for container.
berak gravatar imageberak ( 2016-08-29 01:08:12 -0600 )edit

@berak thank you for your answer. No I am using opencv also for other purposes (creating mat objects and processing them) but I get my buffers not from any opencv input object. Writing with VideoWriter is quick and temp solution, in future versions ffmpeg will be used directly. Still it is not clear from your answer how to obtain codec selected by user when I passed -1 initially - and that is what my question. I know that I don't have to use prompt and can specify a codec by self, but I want to use prompt - but only first time and for next recording I want to re-use codec that a user has once selected

mvidelgauz gravatar imagemvidelgauz ( 2016-08-29 02:58:06 -0600 )edit

unfortunately, there is no way retrieving the codec from VideoWriter.

berak gravatar imageberak ( 2016-08-29 03:27:23 -0600 )edit

also note, that the choice box is a builtin part of VFW, and only available on windows.

berak gravatar imageberak ( 2016-08-29 03:48:49 -0600 )edit

@berak Thank you, I know that, that's why this question is tagged with windows

mvidelgauz gravatar imagemvidelgauz ( 2016-08-30 08:12:49 -0600 )edit