Skip to content

Commit

Permalink
allow specyfing width, height and profile
Browse files Browse the repository at this point in the history
- some codecs need width, height, profile info
- those configuration options are optional
- extend example with optional arguments

closes #11
  • Loading branch information
bmegli committed Jan 12, 2020
1 parent 6c6ae56 commit 7687f93
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/hvd_decoding_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int process_user_input(int argc, char **argv, struct hvd_config *config)
{
if(argc < 3)
{
fprintf(stderr, "Usage: %s <hardware> <codec> [device]\n\n", argv[0]);
fprintf(stderr, "Usage: %s <hardware> <codec> [device] [width] [height] [profile]\n\n", argv[0]);
fprintf(stderr, "examples: \n");
fprintf(stderr, "%s vaapi h264 \n", argv[0]);
fprintf(stderr, "%s vdpau h264 \n", argv[0]);
Expand All @@ -110,13 +110,18 @@ int process_user_input(int argc, char **argv, struct hvd_config *config)
fprintf(stderr, "%s dxva2 h264 \n", argv[0]);
fprintf(stderr, "%s d3d11va h264 \n", argv[0]);
fprintf(stderr, "%s videotoolbox h264 \n", argv[0]);
fprintf(stderr, "%s vaapi hevc /dev/dri/renderD128 848 480 1 \n", argv[0]);
return 1;
}

config->hardware = argv[1];
config->codec = argv[2];
config->device = argv[3]; //NULL or device, both are ok

if(argc >= 5) config->width = atoi(argv[4]);
if(argc >= 6) config->height = atoi(argv[5]);
if(argc >= 7) config->profile = atoi(argv[6]);

return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions hvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ struct hvd *hvd_init(const struct hvd_config *config)
return hvd_close_and_return_null(h);
}

h->decoder_ctx->width = config->width;
h->decoder_ctx->height = config->height;

if(config->profile)
h->decoder_ctx->profile = config->profile;

//Set user data carried by AVContext, we need this to determine pixel format
//from within FFmpeg using our supplied function for decoder_ctx->get_format.
//This is MUCH easier in FFmpeg 4.0 with avcodec_get_hw_config but we want
Expand Down
22 changes: 22 additions & 0 deletions hvd.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ struct hvd;
* For pixel format explanation see:
* <a href="https://ffmpeg.org/doxygen/3.4/pixfmt_8h.html#a9a8e335cf3be472042bc9f0cf80cd4c5">FFmpeg pixel formats</a>
*
* You typically don't have to specify width, height and profile (leave as 0) but some codecs need this information.
*
* For width and height the decoder may overwrite your values while parsing the data.
* It is not safe to assume that width/height of decoded frame matches what you supplied.
*
* For possible profiles see:
* <a href="https://ffmpeg.org/doxygen/3.4/avcodec_8h.html#ab424d258655424e4b1690e2ab6fcfc66">FFmpeg profiles</a>
*
* For H.264 profile can typically be:
* - FF_PROFILE_H264_CONSTRAINED_BASELINE
* - FF_PROFILE_H264_MAIN
* - FF_PROFILE_H264_HIGH
* - ...
*
* For HEVC profile can typically be:
* - FF_PROFILE_HEVC_MAIN
* - FF_PROFILE_HEVC_MAIN_10 (10 bit channel precision)
* - ...
*
* @see hvd_init
*/
struct hvd_config
Expand All @@ -88,6 +107,9 @@ struct hvd_config
const char *codec; //!< codec name, e.g. "h264", "vp8"
const char *device; //!< NULL / "" or device, e.g. "/dev/dri/renderD128"
const char *pixel_format; //!< NULL / "" for default or format, e.g. "rgb0", "bgr0", "nv12", "yuv420p"
int width; //!< 0 to not specify, needed by some codecs
int height; //!< 0 to not specify, needed by some codecs
int profile; //!< 0 to leave as FF_PROFILE_UNKNOWN or profile e.g. FF_PROFILE_HEVC_MAIN, ...
};

/**
Expand Down

0 comments on commit 7687f93

Please sign in to comment.