diff --git a/README.md b/README.md index 4f83187..7a95a14 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,6 @@ frames = decoder.decode(h264_data, 1) #### 3. Use VideoEncoder ```python -encoder = VideoEncoder(width, height) +encoder = VideoEncoder(width, height, cliParams) h264_data = encoder.encode(frame) ``` diff --git a/nvcodec-python.cpp b/nvcodec-python.cpp index 52695f4..660f9b0 100644 --- a/nvcodec-python.cpp +++ b/nvcodec-python.cpp @@ -257,11 +257,12 @@ static PyObject* VideoEncoder_Repr(NvCodec* Self) static void VideoEncoder_init(NvCodec* Self, PyObject* pArgs) { unsigned int width,height; - if(!PyArg_ParseTuple(pArgs, "II", &width, &height)){ - PyErr_SetString(PyExc_ValueError, "Parse the argument FAILED! You should pass width and height!"); + char* params; + if(!PyArg_ParseTuple(pArgs, "IIs", &width, &height, ¶ms)){ + PyErr_SetString(PyExc_ValueError, "Parse the argument FAILED! You should pass width, height and framerate!"); return; } - Self->m_handle = (long long)(videoEncoder_init(width, height)); + Self->m_handle = (long long)(videoEncoder_init(width, height, params)); } static PyTypeObject VideoEncoder_ClassInfo = diff --git a/src/encoder.cpp b/src/encoder.cpp index 47587f3..1ae086a 100644 --- a/src/encoder.cpp +++ b/src/encoder.cpp @@ -23,7 +23,7 @@ void _InitializeEncoder(NvEncoder* pEnc, NvEncoderInitParam encodeCLIOptions, NV } -videoEncoderHandle videoEncoder_init(int width, int height){ +videoEncoderHandle videoEncoder_init(int width, int height, char* params){ videoEncoderHandle handle = (videoEncoderHandle)malloc(sizeof(videoEncoder)); ck(cuInit(0)); handle->cuContext = nullptr; @@ -31,7 +31,7 @@ videoEncoderHandle videoEncoder_init(int width, int height){ handle->enc = new NvEncoderCuda(handle->cuContext, width, height, NV_ENC_BUFFER_FORMAT_ARGB); NV_ENC_BUFFER_FORMAT eFormat = NV_ENC_BUFFER_FORMAT_ARGB; - NvEncoderInitParam encodeCLIOptions; + NvEncoderInitParam encodeCLIOptions(params); _InitializeEncoder(ENC(handle), encodeCLIOptions, eFormat); return handle; } diff --git a/src/encoder.h b/src/encoder.h index fec3a3a..6ebf581 100644 --- a/src/encoder.h +++ b/src/encoder.h @@ -30,7 +30,7 @@ typedef struct }videoEncodedBuffer; -videoEncoderHandle videoEncoder_init(int width, int height); +videoEncoderHandle videoEncoder_init(int width, int height, char* params); int videoEncoder_destroy(videoEncoderHandle handle); videoEncodedBuffer* videoEncoder_encode(videoEncoderHandle handle, u_int8_t* in); videoEncodedBuffer* videoEncoder_encode_end(videoEncoderHandle handle);