Skip to content

Commit

Permalink
make speed-quality tradeoff configurable
Browse files Browse the repository at this point in the history
- add compression_level configuration option
- 0 for default
- 1 for the highest quality
- 7 for the fastest

The default in my tests is not set to highest quality.

On my 2017 KabyLake with 848x480@30 HEVC Main10 encoding
, the difference between default and highest quality is:
- 15%/25% GPU render busy
- 7-9 ms/10-12 ms per frame

Related to #6
  • Loading branch information
bmegli committed Apr 2, 2020
1 parent 1713af8 commit 98be90d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ There are just 4 functions and 3 user-visible data types:
- `hve_close`

```C
struct hve_config hardware_config = {WIDTH, HEIGHT, FRAMERATE, DEVICE,
ENCODER, PIXEL_FORMAT, PROFILE, BFRAMES, BITRATE, QP, GOP_SIZE};
struct hve_config hardware_config = {WIDTH, HEIGHT, FRAMERATE, DEVICE, ENCODER,
PIXEL_FORMAT, PROFILE, BFRAMES, BITRATE, QP, GOP_SIZE, COMPRESSION_LEVEL};
struct hve *hardware_encoder=hve_init(&hardware_config);
struct hve_frame frame = { 0 };

Expand Down
3 changes: 2 additions & 1 deletion examples/hve_encode_raw_h264.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const int BFRAMES=0; //max_b_frames, set to 0 to minimize latency, non-zero to m
const int BITRATE=0; //average bitrate in VBR mode (bit_rate != 0 and qp == 0)
const int QP=0; //quantization parameter in CQP mode (qp != 0 and bit_rate == 0)
const int GOP_SIZE=0; //group of pictures size, 0 for default (determines keyframe period)
const int COMPRESSION_LEVEL=0; //speed-quality tradeoff, 0 for default, 1 for the highest quality, 7 for the fastest

int encoding_loop(struct hve *hardware_encoder, FILE *output_file);
int process_user_input(int argc, char* argv[]);
Expand All @@ -40,7 +41,7 @@ int main(int argc, char* argv[])

//prepare library data
struct hve_config hardware_config = {WIDTH, HEIGHT, FRAMERATE, DEVICE, ENCODER,
PIXEL_FORMAT, PROFILE, BFRAMES, BITRATE, QP, GOP_SIZE};
PIXEL_FORMAT, PROFILE, BFRAMES, BITRATE, QP, GOP_SIZE, COMPRESSION_LEVEL};
struct hve *hardware_encoder;

//prepare file for raw H.264 output
Expand Down
3 changes: 2 additions & 1 deletion examples/hve_encode_raw_hevc10.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const int BFRAMES=0; //max_b_frames, set to 0 to minimize latency, non-zero to m
const int BITRATE=0; //average bitrate in VBR mode (bit_rate != 0 and qp == 0)
const int QP=0; //quantization parameter in CQP mode (qp != 0 and bit_rate == 0)
const int GOP_SIZE=0; //group of pictures size, 0 for default (determines keyframe period)
const int COMPRESSION_LEVEL=0; //speed-quality tradeoff, 0 for default, 1 for the highest quality, 7 for the fastest

int encoding_loop(struct hve *hardware_encoder, FILE *output_file);
int process_user_input(int argc, char* argv[]);
Expand All @@ -40,7 +41,7 @@ int main(int argc, char* argv[])

//prepare library data
struct hve_config hardware_config = {WIDTH, HEIGHT, FRAMERATE, DEVICE, ENCODER,
PIXEL_FORMAT, PROFILE, BFRAMES, BITRATE, QP, GOP_SIZE};
PIXEL_FORMAT, PROFILE, BFRAMES, BITRATE, QP, GOP_SIZE, COMPRESSION_LEVEL};
struct hve *hardware_encoder;

//prepare file for raw HEVC output
Expand Down
1 change: 1 addition & 0 deletions hve.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct hve *hve_init(const struct hve_config *config)
h->avctx->profile = config->profile;
h->avctx->max_b_frames = config->max_b_frames;
h->avctx->bit_rate = config->bit_rate;
h->avctx->compression_level = config->compression_level;

//try to find software pixel format that user wants to upload data in
if(config->pixel_format == NULL || config->pixel_format[0] == '\0')
Expand Down
6 changes: 6 additions & 0 deletions hve.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ struct hve;
* Setting gop_size equal to framerate results in one keyframe per second.
* Use 0 value for default, -1 for intra only.
*
* The compression_level is speed-quality trade-off. Use 0 for driver default.
* For highest quality use 1, for fastest encoding use 7.
* The default is not highest quality so if you need it, set it explicitly to 1.
* The exact interpretation is hardware dependent.
*
* @see hve_init
*/
struct hve_config
Expand All @@ -138,6 +143,7 @@ struct hve_config
int bit_rate; //!< average bitrate in VBR mode (bit_rate != 0 and qp == 0)
int qp; //!< quantization parameter in CQP mode (qp != 0 and bit_rate == 0)
int gop_size; //!< group of pictures size, 0 for default, -1 for intra only
int compression_level; //!< speed-quality tradeoff, 0 for default, 1 for the highest quality, 7 for the fastest
};

/**
Expand Down

0 comments on commit 98be90d

Please sign in to comment.