Skip to content

Commit

Permalink
expose NVMPI num_capture_buffers (Jetson specific)
Browse files Browse the repository at this point in the history
- expose through configuration
- minimal documentation
  • Loading branch information
bmegli committed Mar 17, 2023
1 parent 957a848 commit e934d2f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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 };
Expand Down
4 changes: 3 additions & 1 deletion examples/hve_encode_raw_h264.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);
Expand All @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion examples/hve_encode_raw_hevc10.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions hve.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions hve.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand Down

0 comments on commit e934d2f

Please sign in to comment.