diff --git a/README.md b/README.md index 6474477..91d80f5 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ cd hardware-video-encoder mkdir build cd build cmake .. +# alternatively specify FFMPEG_MODULE_PATH pointing to LGPL FFMPEG +# cmake .. -DFFMPEG_MODULE_PATH=[directory_with_FindFFMPEG.cmake] make ``` @@ -124,7 +126,8 @@ There are just 4 functions and 3 user-visible data types: DEVICE, ENCODER, PIXEL_FORMAT, PROFILE, BFRAMES, BITRATE, QP, GOP_SIZE, COMPRESSION_LEVEL, VAAPI_LOW_POWER - NVENC_PRESET, NVENC_DELAY, NVENC_ZEROLATENCY}; + NVENC_PRESET, NVENC_DELAY, NVENC_ZEROLATENCY, + NVMPI_NUM_CAPTURE_BUFFERS}; struct hve *hardware_encoder=hve_init(&hardware_config); struct hve_frame frame = { 0 }; diff --git a/examples/hve_encode_raw_h264.c b/examples/hve_encode_raw_h264.c index d358ca9..9f8853f 100644 --- a/examples/hve_encode_raw_h264.c +++ b/examples/hve_encode_raw_h264.c @@ -33,6 +33,7 @@ const int VAAPI_LOW_POWER=0; //alternative VAAPI limited low-power encoding path const char *NVENC_PRESET=NULL; //NVENC and codec specific, NULL / "" or like "default", "slow", "medium", "fast", "hp", "hq", "bd", "ll", "llhq", "llhp", "lossless", "losslesshp" const int NVENC_DELAY=0; //NVENC specific delay of frame output, 0 for default, -1 for 0 or positive value, set -1 to minimize latency const int NVENC_ZEROLATENCY=0; //NVENC specific no reordering delay if non-zero, enable to minimize latency +const int NVMPI_NUM_CAPTURE_BUFFERS=0; //NVMPI specific number of buffers in the capture context if non-zero, smaller values may improve latency int encoding_loop(struct hve *hardware_encoder, FILE *output_file); int process_user_input(int argc, char* argv[]); @@ -50,7 +51,8 @@ int main(int argc, char* argv[]) DEVICE, ENCODER, PIXEL_FORMAT, PROFILE, BFRAMES, BITRATE, QP, GOP_SIZE, COMPRESSION_LEVEL, VAAPI_LOW_POWER, - NVENC_PRESET, NVENC_DELAY, NVENC_ZEROLATENCY}; + NVENC_PRESET, NVENC_DELAY, NVENC_ZEROLATENCY, + NVMPI_NUM_CAPTURE_BUFFERS}; struct hve *hardware_encoder; diff --git a/examples/hve_encode_raw_hevc10.c b/examples/hve_encode_raw_hevc10.c index 5a30c67..41a935e 100644 --- a/examples/hve_encode_raw_hevc10.c +++ b/examples/hve_encode_raw_hevc10.c @@ -33,6 +33,7 @@ const int VAAPI_LOW_POWER=0; //alternative VAAPI limited low-power encoding path const char *NVENC_PRESET=NULL; //NVENC and codec specific, NULL / "" or like "default", "slow", "medium", "fast", "hp", "hq", "bd", "ll", "llhq", "llhp", "lossless", "losslesshp" const int NVENC_DELAY=0; //NVENC specific delay of frame output, 0 for default, -1 for 0 or positive value, set -1 to minimize latency const int NVENC_ZEROLATENCY=0; //NVENC specific no reordering delay if non-zero, enable to minimize latency +const int NVMPI_NUM_CAPTURE_BUFFERS=0; //NVMPI specific number of buffers in the capture context if non-zero, smaller values may improve latency int encoding_loop(struct hve *hardware_encoder, FILE *output_file); int process_user_input(int argc, char* argv[]); @@ -50,7 +51,9 @@ int main(int argc, char* argv[]) DEVICE, ENCODER, PIXEL_FORMAT, PROFILE, BFRAMES, BITRATE, QP, GOP_SIZE, COMPRESSION_LEVEL, VAAPI_LOW_POWER, - NVENC_PRESET, NVENC_DELAY, NVENC_ZEROLATENCY}; + NVENC_PRESET, NVENC_DELAY, NVENC_ZEROLATENCY, + NVMPI_NUM_CAPTURE_BUFFERS}; + struct hve *hardware_encoder; //prepare file for raw HEVC output diff --git a/hve.c b/hve.c index 4a108f9..18859be 100644 --- a/hve.c +++ b/hve.c @@ -137,6 +137,9 @@ struct hve *hve_init(const struct hve_config *config) if(config->nvenc_zerolatency && (av_dict_set_int(&opts, "zerolatency", config->nvenc_zerolatency != 0 , 0) < 0)) return hve_close_and_return_null(h, "failed to initialize option dictionary (NVENC zerolatency)"); + if(config->nvmpi_num_capture_buffers && (av_dict_set_int(&opts, "num_capture_buffers", config->nvmpi_num_capture_buffers, 0) < 0)) + return hve_close_and_return_null(h, "failed to initialize option dictionary (NVMPI num_capture_buffers)"); + if((err = avcodec_open2(h->avctx, codec, &opts)) < 0) { av_dict_free(&opts); diff --git a/hve.h b/hve.h index d0b1065..3e927ac 100644 --- a/hve.h +++ b/hve.h @@ -202,6 +202,7 @@ struct hve_config const char *nvenc_preset; //!< NVENC and codec specific, NULL / "" or like "default", "slow", "medium", "fast", "hp", "hq", "bd", "ll", "llhq", "llhp", "lossless", "losslesshp" int nvenc_delay; //NVENC specific delay of frame output, 0 for default, -1 for 0 or positive value, set -1 to minimize latency int nvenc_zerolatency; //NVENC specific no reordering delay if non-zero, enable to minimize latency + int nvmpi_num_capture_buffers; //NVMPI specific number of buffers in the capture context if non-zero, smaller values may improve latency }; /**