|
|
|
@ -10,6 +10,18 @@ |
|
|
|
|
using namespace std; |
|
|
|
|
using namespace cv; |
|
|
|
|
|
|
|
|
|
static size_t getBitrateDivisor() |
|
|
|
|
{ |
|
|
|
|
static const size_t res = utils::getConfigurationParameterSizeT("OPENCV_VIDEOIO_MFX_BITRATE_DIVISOR", 300); |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static mfxU32 getWriterTimeoutMS() |
|
|
|
|
{ |
|
|
|
|
static const size_t res = utils::getConfigurationParameterSizeT("OPENCV_VIDEOIO_MFX_WRITER_TIMEOUT", 1); |
|
|
|
|
return saturate_cast<mfxU32>(res * 1000); // convert from seconds
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline mfxU32 codecIdByFourCC(int fourcc) |
|
|
|
|
{ |
|
|
|
|
const int CC_MPG2 = FourCC('M', 'P', 'G', '2').vali32; |
|
|
|
@ -77,7 +89,7 @@ VideoWriter_IntelMFX::VideoWriter_IntelMFX(const String &filename, int _fourcc, |
|
|
|
|
memset(¶ms, 0, sizeof(params)); |
|
|
|
|
params.mfx.CodecId = codecId; |
|
|
|
|
params.mfx.TargetUsage = MFX_TARGETUSAGE_BALANCED; |
|
|
|
|
params.mfx.TargetKbps = (mfxU16)cvRound(frameSize.area() * fps / 500); // TODO: set in options
|
|
|
|
|
params.mfx.TargetKbps = saturate_cast<mfxU16>((frameSize.area() * fps) / (42.6666 * getBitrateDivisor())); // TODO: set in options
|
|
|
|
|
params.mfx.RateControlMethod = MFX_RATECONTROL_VBR; |
|
|
|
|
params.mfx.FrameInfo.FrameRateExtN = cvRound(fps * 1000); |
|
|
|
|
params.mfx.FrameInfo.FrameRateExtD = 1000; |
|
|
|
@ -210,7 +222,7 @@ bool VideoWriter_IntelMFX::write_one(cv::InputArray bgr) |
|
|
|
|
res = encoder->EncodeFrameAsync(NULL, workSurface, &bs->stream, &sync); |
|
|
|
|
if (res == MFX_ERR_NONE) |
|
|
|
|
{ |
|
|
|
|
res = session->SyncOperation(sync, 1000); // 1 sec, TODO: provide interface to modify timeout
|
|
|
|
|
res = session->SyncOperation(sync, getWriterTimeoutMS()); // TODO: provide interface to modify timeout
|
|
|
|
|
if (res == MFX_ERR_NONE) |
|
|
|
|
{ |
|
|
|
|
// ready to write
|
|
|
|
@ -239,7 +251,7 @@ bool VideoWriter_IntelMFX::write_one(cv::InputArray bgr) |
|
|
|
|
else if (res == MFX_WRN_DEVICE_BUSY) |
|
|
|
|
{ |
|
|
|
|
DBG(cout << "Waiting for device" << endl); |
|
|
|
|
sleep(1); |
|
|
|
|
sleep_ms(1000); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|