Skip to content

Commit

Permalink
x265: add support for 10, 12, and 16 bit x265 libs
Browse files Browse the repository at this point in the history
automatically pull in shared versions of these libs or allow statically
building against any one of them.
  • Loading branch information
jstebbins committed Nov 12, 2015
1 parent 02585c6 commit 2c9d144
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 42 deletions.
5 changes: 4 additions & 1 deletion gtk/src/hb-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,10 @@ ghb_vquality_default(signal_user_data_t *ud)

switch (vcodec)
{
case HB_VCODEC_X265:
case HB_VCODEC_X265_8BIT:
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_X265_12BIT:
case HB_VCODEC_X265_16BIT:
case HB_VCODEC_X264_8BIT:
case HB_VCODEC_X264_10BIT:
return 20;
Expand Down
4 changes: 2 additions & 2 deletions gtk/src/makedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
DepEntry("VideoEncoder", "x264FastDecode", "x264|x264_10bit", False, True),
DepEntry("VideoEncoder", "x264UseAdvancedOptions", "x264|x264_10bit", False, True),
DepEntry("HideAdvancedVideoSettings", "x264UseAdvancedOptions", "1", True, True),
DepEntry("VideoEncoder", "VideoOptionExtraWindow", "x264|x264_10bit|x265|mpeg4|mpeg2|VP8", False, True),
DepEntry("VideoEncoder", "VideoOptionExtraLabel", "x264|x264_10bit|x265|mpeg4|mpeg2|VP8", False, True),
DepEntry("VideoEncoder", "VideoOptionExtraWindow", "x264|x264_10bit|x265|x265_10bit|x265_12bit|x265_16bit|mpeg4|mpeg2|VP8", False, True),
DepEntry("VideoEncoder", "VideoOptionExtraLabel", "x264|x264_10bit|x265|x265_10bit|x265_12bit|x265_16bit|mpeg4|mpeg2|VP8", False, True),
DepEntry("x264UseAdvancedOptions", "VideoSettingsTable", "1", True, False),
DepEntry("VideoEncoder", "x264_box", "x264|x264_10bit", False, True),
DepEntry("x264UseAdvancedOptions", "x264_box", "0", True, False),
Expand Down
53 changes: 44 additions & 9 deletions libhb/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ hb_encoder_internal_t hb_video_encoders[] =
{ { "H.264 (x264)", "x264", "H.264 (libx264)", HB_VCODEC_X264_8BIT, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 1, HB_GID_VCODEC_H264, },
{ { "H.264 10-bit (x264)", "x264_10bit", "H.264 10-bit (libx264)", HB_VCODEC_X264_10BIT, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 1, HB_GID_VCODEC_H264, },
{ { "H.264 (Intel QSV)", "qsv_h264", "H.264 (Intel Media SDK)", HB_VCODEC_QSV_H264, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 1, HB_GID_VCODEC_H264, },
{ { "H.265 (x265)", "x265", "H.265 (libx265)", HB_VCODEC_X265, HB_MUX_AV_MP4|HB_MUX_AV_MKV, }, NULL, 1, HB_GID_VCODEC_H265, },
{ { "H.265 (x265)", "x265", "H.265 (libx265)", HB_VCODEC_X265_8BIT, HB_MUX_AV_MP4|HB_MUX_AV_MKV, }, NULL, 1, HB_GID_VCODEC_H265, },
{ { "H.265 10-bit (x265)", "x265_10bit", "H.265 10-bit (libx265)", HB_VCODEC_X265_10BIT, HB_MUX_AV_MP4|HB_MUX_AV_MKV, }, NULL, 1, HB_GID_VCODEC_H265, },
{ { "H.265 12-bit (x265)", "x265_12bit", "H.265 12-bit (libx265)", HB_VCODEC_X265_12BIT, HB_MUX_AV_MP4|HB_MUX_AV_MKV, }, NULL, 1, HB_GID_VCODEC_H265, },
{ { "H.265 16-bit (x265)", "x265_16bit", "H.265 16-bit (libx265)", HB_VCODEC_X265_16BIT, HB_MUX_AV_MP4|HB_MUX_AV_MKV, }, NULL, 1, HB_GID_VCODEC_H265, },
{ { "H.265 (Intel QSV)", "qsv_h265", "H.265 (Intel Media SDK)", HB_VCODEC_QSV_H265, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 1, HB_GID_VCODEC_H265, },
{ { "MPEG-4", "mpeg4", "MPEG-4 (libavcodec)", HB_VCODEC_FFMPEG_MPEG4, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 1, HB_GID_VCODEC_MPEG4, },
{ { "MPEG-2", "mpeg2", "MPEG-2 (libavcodec)", HB_VCODEC_FFMPEG_MPEG2, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 1, HB_GID_VCODEC_MPEG2, },
Expand All @@ -250,10 +253,19 @@ static int hb_video_encoder_is_enabled(int encoder)
case HB_VCODEC_FFMPEG_MPEG4:
case HB_VCODEC_FFMPEG_MPEG2:
case HB_VCODEC_FFMPEG_VP8:
return 1;

#ifdef USE_X265
case HB_VCODEC_X265:
case HB_VCODEC_X265_8BIT:
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_X265_12BIT:
case HB_VCODEC_X265_16BIT:
{
const x265_api *api;
api = x265_api_get(hb_video_encoder_get_depth(encoder));
return (api != NULL);
};
#endif
return 1;

case HB_VCODEC_X264_8BIT:
case HB_VCODEC_X264_10BIT:
Expand Down Expand Up @@ -1202,7 +1214,10 @@ void hb_video_quality_get_limits(uint32_t codec, float *low, float *high,
case HB_VCODEC_X264_8BIT:
case HB_VCODEC_X264_10BIT:
#ifdef USE_X265
case HB_VCODEC_X265:
case HB_VCODEC_X265_8BIT:
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_X265_12BIT:
case HB_VCODEC_X265_16BIT:
#endif
*direction = 1;
*granularity = 0.1;
Expand Down Expand Up @@ -1249,7 +1264,10 @@ const char* hb_video_quality_get_name(uint32_t codec)
case HB_VCODEC_X264_8BIT:
case HB_VCODEC_X264_10BIT:
#ifdef USE_X265
case HB_VCODEC_X265:
case HB_VCODEC_X265_8BIT:
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_X265_12BIT:
case HB_VCODEC_X265_16BIT:
#endif
return "RF";

Expand All @@ -1266,7 +1284,12 @@ int hb_video_encoder_get_depth(int encoder)
switch (encoder)
{
case HB_VCODEC_X264_10BIT:
case HB_VCODEC_X265_10BIT:
return 10;
case HB_VCODEC_X265_12BIT:
return 12;
case HB_VCODEC_X265_16BIT:
return 16;
default:
return 8;
}
Expand All @@ -1288,7 +1311,10 @@ const char* const* hb_video_encoder_get_presets(int encoder)
return x264_preset_names;

#ifdef USE_X265
case HB_VCODEC_X265:
case HB_VCODEC_X265_8BIT:
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_X265_12BIT:
case HB_VCODEC_X265_16BIT:
return x265_preset_names;
#endif
default:
Expand All @@ -1305,7 +1331,10 @@ const char* const* hb_video_encoder_get_tunes(int encoder)
return x264_tune_names;

#ifdef USE_X265
case HB_VCODEC_X265:
case HB_VCODEC_X265_8BIT:
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_X265_12BIT:
case HB_VCODEC_X265_16BIT:
return x265_tune_names;
#endif
default:
Expand All @@ -1329,8 +1358,14 @@ const char* const* hb_video_encoder_get_profiles(int encoder)
case HB_VCODEC_X264_10BIT:
return hb_h264_profile_names_10bit;

case HB_VCODEC_X265:
return hb_h265_profile_names;
case HB_VCODEC_X265_8BIT:
return hb_h265_profile_names_8bit;
case HB_VCODEC_X265_10BIT:
return hb_h265_profile_names_10bit;
case HB_VCODEC_X265_12BIT:
return hb_h265_profile_names_12bit;
case HB_VCODEC_X265_16BIT:
return hb_h265_profile_names_16bit;

default:
return NULL;
Expand Down
9 changes: 7 additions & 2 deletions libhb/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ struct hb_job_s
#define HB_VCODEC_MASK 0x00FFFFF
#define HB_VCODEC_INVALID 0x0000000
#define HB_VCODEC_THEORA 0x0000002
#define HB_VCODEC_X265 0x0000004
#define HB_VCODEC_FFMPEG_MPEG4 0x0000010
#define HB_VCODEC_FFMPEG_MPEG2 0x0000020
#define HB_VCODEC_FFMPEG_VP8 0x0000040
Expand All @@ -536,7 +535,13 @@ struct hb_job_s
#define HB_VCODEC_X264_10BIT 0x0020000
#define HB_VCODEC_X264_MASK 0x0030000
#define HB_VCODEC_H264_MASK (HB_VCODEC_X264_MASK|HB_VCODEC_QSV_H264)
#define HB_VCODEC_H265_MASK (HB_VCODEC_X265|HB_VCODEC_QSV_H265)
#define HB_VCODEC_X265_8BIT 0x0001000
#define HB_VCODEC_X265 HB_VCODEC_X265_8BIT
#define HB_VCODEC_X265_10BIT 0x0002000
#define HB_VCODEC_X265_12BIT 0x0004000
#define HB_VCODEC_X265_16BIT 0x0008000
#define HB_VCODEC_X265_MASK 0x000F000
#define HB_VCODEC_H265_MASK (HB_VCODEC_X265_MASK|HB_VCODEC_QSV_H265)

int vcodec;
double vquality;
Expand Down
42 changes: 22 additions & 20 deletions libhb/encx265.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ struct hb_work_private_s

struct
{
int64_t duration;
int64_t duration;
}
frame_info[FRAME_INFO_SIZE];

char csvfn[1024];

// Multiple bit-depth
int depth;
const x265_api *api;
};

Expand Down Expand Up @@ -95,22 +94,25 @@ static int param_parse(hb_work_private_t *pv, x265_param *param,
**********************************************************************/
int encx265Init(hb_work_object_t *w, hb_job_t *job)
{
hb_work_private_t *pv = calloc(1, sizeof(hb_work_private_t));
pv->next_chapter_pts = AV_NOPTS_VALUE;
pv->delayed_chapters = hb_list_init();
pv->job = job;
w->private_data = pv;
int ret;
hb_rational_t vrate;
x265_nal *nal;
uint32_t nnal;
hb_work_private_t *pv = calloc(1, sizeof(hb_work_private_t));
int ret, depth;
hb_rational_t vrate;
x265_nal *nal;
uint32_t nnal;
const char * const *profile_names;

pv->next_chapter_pts = AV_NOPTS_VALUE;
pv->delayed_chapters = hb_list_init();
pv->job = job;
w->private_data = pv;

depth = hb_video_encoder_get_depth(job->vcodec);
profile_names = hb_video_encoder_get_profiles(job->vcodec);
pv->api = x265_api_get(depth);

// TODO: add support for other bit depths
pv->depth = 8;
pv->api = x265_api_get(pv->depth);
if (pv->api == NULL)
{
hb_error("encx265: x265_api_get failed, bit depth %d.", pv->depth);
hb_error("encx265: x265_api_get failed, bit depth %d.", depth);
goto fail;
}

Expand Down Expand Up @@ -292,9 +294,9 @@ int encx265Init(hb_work_object_t *w, hb_job_t *job)
}

/* Apply profile and level settings last. */
if (job->encoder_profile != NULL &&
strcasecmp(job->encoder_profile, hb_h265_profile_names[0]) != 0 &&
pv->api->param_apply_profile(param, job->encoder_profile) < 0)
if (job->encoder_profile != NULL &&
strcasecmp(job->encoder_profile, profile_names[0]) != 0 &&
pv->api->param_apply_profile(param, job->encoder_profile) < 0)
{
goto fail;
}
Expand Down Expand Up @@ -558,8 +560,8 @@ int encx265Work(hb_work_object_t *w, hb_buffer_t **buf_in, hb_buffer_t **buf_out
hb_buffer_list_clear(&list);

// flush delayed frames
while (
pv->api->encoder_encode(pv->x265, &nal, &nnal, NULL, &pic_out) > 0)
while (pv->api->encoder_encode(pv->x265, &nal,
&nnal, NULL, &pic_out) > 0)
{
hb_buffer_t *buf = nal_encode(w, &pic_out, nal, nnal);
hb_buffer_list_append(&list, buf);
Expand Down
5 changes: 4 additions & 1 deletion libhb/h265_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#define HB_H265_COMMON_H

static const char * const hb_h265_tier_names[] = { "auto", "main", "high", NULL, };
static const char * const hb_h265_profile_names[] = { "auto", "main", "mainstillpicture", NULL, };
static const char * const hb_h265_profile_names_8bit[] = { "auto", "main", "mainstillpicture", NULL, };
static const char * const hb_h265_profile_names_10bit[] = { "auto", "main10", "main10-intra", NULL, };
static const char * const hb_h265_profile_names_12bit[] = { "auto", "main12", "main12-intra", NULL, };
static const char * const hb_h265_profile_names_16bit[] = { "auto", "main16", "main16-intra", NULL, };
static const char * const hb_h265_level_names[] = { "auto", "1.0", "2.0", "2.1", "3.0", "3.1", "4.0", "4.1", "5.0", "5.1", "5.2", "6.0", "6.1", "6.2", NULL, };
static const int const hb_h265_level_values[] = { -1, 30, 60, 63, 90, 93, 120, 123, 150, 153, 156, 180, 183, 186, 0, };

Expand Down
2 changes: 1 addition & 1 deletion libhb/hb_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ hb_dict_t * hb_encopts_to_dict(const char * encopts, int encoder)
name = hb_x264_encopt_name(name);
#ifdef USE_X265
// x265 has multiple names for some options
if (encoder == HB_VCODEC_X265)
if (encoder & HB_VCODEC_X265_MASK)
name = hb_x265_encopt_name(name);
#endif
if (name != NULL)
Expand Down
5 changes: 4 additions & 1 deletion libhb/muxavformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ static int avformatInit( hb_mux_object_t * m )
}
} break;

case HB_VCODEC_X265:
case HB_VCODEC_X265_8BIT:
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_X265_12BIT:
case HB_VCODEC_X265_16BIT:
case HB_VCODEC_QSV_H265:
track->st->codec->codec_id = AV_CODEC_ID_HEVC;

Expand Down
23 changes: 18 additions & 5 deletions libhb/work.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ hb_work_object_t* hb_video_encoder(hb_handle_t *h, int vcodec)
w = hb_get_work(h, WORK_ENCTHEORA);
break;
#ifdef USE_X265
case HB_VCODEC_X265:
case HB_VCODEC_X265_8BIT:
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_X265_12BIT:
case HB_VCODEC_X265_16BIT:
w = hb_get_work(h, WORK_ENCX265);
break;
#endif
Expand Down Expand Up @@ -415,7 +418,10 @@ void hb_display_job_info(hb_job_t *job)
{
case HB_VCODEC_X264_8BIT:
case HB_VCODEC_X264_10BIT:
case HB_VCODEC_X265:
case HB_VCODEC_X265_8BIT:
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_X265_12BIT:
case HB_VCODEC_X265_16BIT:
case HB_VCODEC_QSV_H264:
case HB_VCODEC_QSV_H265:
hb_log(" + preset: %s", job->encoder_preset);
Expand All @@ -429,7 +435,10 @@ void hb_display_job_info(hb_job_t *job)
{
case HB_VCODEC_X264_8BIT:
case HB_VCODEC_X264_10BIT:
case HB_VCODEC_X265:
case HB_VCODEC_X265_8BIT:
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_X265_12BIT:
case HB_VCODEC_X265_16BIT:
hb_log(" + tune: %s", job->encoder_tune);
default:
break;
Expand All @@ -446,7 +455,10 @@ void hb_display_job_info(hb_job_t *job)
{
case HB_VCODEC_X264_8BIT:
case HB_VCODEC_X264_10BIT:
case HB_VCODEC_X265:
case HB_VCODEC_X265_8BIT:
case HB_VCODEC_X265_10BIT:
case HB_VCODEC_X265_12BIT:
case HB_VCODEC_X265_16BIT:
case HB_VCODEC_QSV_H264:
case HB_VCODEC_QSV_H265:
hb_log(" + profile: %s", job->encoder_profile);
Expand Down Expand Up @@ -477,7 +489,8 @@ void hb_display_job_info(hb_job_t *job)
{
hb_log( " + bitrate: %d kbps, pass: %d", job->vbitrate, job->pass_id );
if(job->pass_id == HB_PASS_ENCODE_1ST && job->fastfirstpass == 1 &&
((job->vcodec & HB_VCODEC_X264_MASK) || job->vcodec == HB_VCODEC_X265))
((job->vcodec & HB_VCODEC_X264_MASK) ||
(job->vcodec & HB_VCODEC_X265_MASK)))
{
hb_log( " + fast first pass" );
if (job->vcodec & HB_VCODEC_X264_MASK)
Expand Down

0 comments on commit 2c9d144

Please sign in to comment.