OpenCV + FFMPEG encoding bitrate

asked 2016-02-07 12:47:05 -0600

Davide Dec gravatar image

updated 2016-02-08 07:48:38 -0600

Hi to all. I'm in stuck since 3 days on the following problem. I have a small project in Visual Studio using OpenCV with FFMPEG and I'm encoding a video coming from a capture device. I can encode it with various codecs using the VideoWriter class without problem, including H263 and so on. My problem is that the resulting file have a bitrate of more than 1 Mbps that is not acceptable in my application. I need to reduce it but I couldn't find any way to set the bitrate of the encoder. Also googling for this results only in unanswered questions.

Thanks

EDIT: After LBerger comment I did some tests and research about libopenh264. It's clear that it can handle easily the maximum bitrate (I did some test using directly ffmpeg.exe interface and it works) but when you create a VideoWriter from opencv you will obtain a writer with some defaults parameter that I can't figure out how to change. Also console logging, just after the writer instance is created says that bitrate can't be controlled:

[OpenH264] this = 0x046E2F90, Warning:bEnableFrameSkip = 0,bitrate can't be controlled for RC_QUALITY_MODE,RC_BITRATE_MODE and RC_TIMESTAMP_MODE without enablin g skip frame.

bEnableFrameSkip should be 1 but is initialized from a structure with default as zero.

The video writer is created by a proxy class named CvVideoWriter_FFMPEG_proxy that calls cvCreateVideoWriter_FFMPEG from the opencv_ffmpeg.dll Unfortunately it looks there is noway to compile the opencv_ffmpeg.dll by myself because it cames prebuilt. There is not any exported function from that dll that helps to change this.

edit retag flag offensive close merge delete

Comments

have you try property VIDEOWRITER_PROP_QUALITY ?

LBerger gravatar imageLBerger ( 2016-02-07 14:02:07 -0600 )edit

Thanks for your comment. Yes I tried and it doesn't influence the bitrare/quality. Looking deeper into the property setter it's clear that it will work only on MJPEG codec and not with any others. This because the setter is done on a pointer of an interface that is actually used only if the mjpeg cc is initialized.

Davide Dec gravatar imageDavide Dec ( 2016-02-07 14:30:02 -0600 )edit

Sorry I have tested like you and same conclusion but it should be possible

LBerger gravatar imageLBerger ( 2016-02-07 14:43:42 -0600 )edit

H264 can be a solution as I can see. Thanks for the suggestion. Tomorrow I will try and I will return here with the results.

Davide Dec gravatar imageDavide Dec ( 2016-02-07 14:46:54 -0600 )edit

I changed my question including my last results

Davide Dec gravatar imageDavide Dec ( 2016-02-08 07:49:23 -0600 )edit