[x264-devel] [PATCH 16/29] Add API to set bitdepth at runtime
Vittorio Giovara
vittorio.giovara at gmail.com
Fri Feb 10 22:18:51 CET 2017
Replace the constant symbol where needed.
---
common/frame.c | 16 +---------------
common/param.c | 11 +++++------
common/set.h | 1 +
encoder/encoder.c | 6 +++---
encoder/set.c | 7 ++++---
x264.h | 1 +
6 files changed, 15 insertions(+), 27 deletions(-)
diff --git a/common/frame.c b/common/frame.c
index 424f8de..1ffc51d 100644
--- a/common/frame.c
+++ b/common/frame.c
@@ -370,21 +370,7 @@ int x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )
return -1;
}
-#if HIGH_BIT_DEPTH
- if( !(src->img.i_csp & X264_CSP_HIGH_DEPTH) )
- {
- x264_log( h, X264_LOG_ERROR, "This build of x264 requires high depth input. Rebuild to support 8-bit input.\n" );
- return -1;
- }
-#else
- if( src->img.i_csp & X264_CSP_HIGH_DEPTH )
- {
- x264_log( h, X264_LOG_ERROR, "This build of x264 requires 8-bit input. Rebuild to support high depth input.\n" );
- return -1;
- }
-#endif
-
- if( BIT_DEPTH != 10 && i_csp == X264_CSP_V210 )
+ if( h->param.i_bitdepth != 10 && i_csp == X264_CSP_V210 )
{
x264_log( h, X264_LOG_ERROR, "v210 input is only compatible with bit-depth of 10 bits\n" );
return -1;
diff --git a/common/param.c b/common/param.c
index 1c35d5e..fb536e8 100644
--- a/common/param.c
+++ b/common/param.c
@@ -24,8 +24,6 @@
* For more information, contact us at licensing at x264.com.
*****************************************************************************/
-#include "common.h"
-
#include <ctype.h>
#include "osdep.h"
#include "x264.h"
@@ -449,6 +447,7 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )
if( !profile )
return 0;
+ const int qp_bd_offset = 6 * (param->i_bitdepth-8);
int p = profile_string_to_int( profile );
if( p < 0 )
{
@@ -456,7 +455,7 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )
return -1;
}
if( p < PROFILE_HIGH444_PREDICTIVE && ((param->rc.i_rc_method == X264_RC_CQP && param->rc.i_qp_constant <= 0) ||
- (param->rc.i_rc_method == X264_RC_CRF && (int)(param->rc.f_rf_constant + QP_BD_OFFSET) <= 0)) )
+ (param->rc.i_rc_method == X264_RC_CRF && (int)(param->rc.f_rf_constant + qp_bd_offset) <= 0)) )
{
x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support lossless\n", profile );
return -1;
@@ -471,9 +470,9 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )
x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support 4:2:2\n", profile );
return -1;
}
- if( p < PROFILE_HIGH10 && BIT_DEPTH > 8 )
+ if( p < PROFILE_HIGH10 && param->i_bitdepth > 8 )
{
- x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support a bit depth of %d\n", profile, BIT_DEPTH );
+ x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support a bit depth of %d\n", profile, param->i_bitdepth );
return -1;
}
@@ -1081,7 +1080,7 @@ char *x264_param2string( x264_param_t *p, int b_res )
s += sprintf( s, "%dx%d ", p->i_width, p->i_height );
s += sprintf( s, "fps=%u/%u ", p->i_fps_num, p->i_fps_den );
s += sprintf( s, "timebase=%u/%u ", p->i_timebase_num, p->i_timebase_den );
- s += sprintf( s, "bitdepth=%d ", BIT_DEPTH );
+ s += sprintf( s, "bitdepth=%d ", p->i_bitdepth );
}
if( p->b_opencl )
diff --git a/common/set.h b/common/set.h
index 5760f33..c28b902 100644
--- a/common/set.h
+++ b/common/set.h
@@ -157,6 +157,7 @@ typedef struct
int b_qpprime_y_zero_transform_bypass;
int i_chroma_format_idc;
+ int i_bitdepth;
} x264_sps_t;
diff --git a/encoder/encoder.c b/encoder/encoder.c
index 935f137..cc6217a 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -3795,9 +3795,9 @@ static int encoder_frame_end( x264_t *h, x264_t *thread_current,
pic_out->opaque = h->fenc->opaque;
pic_out->img.i_csp = h->fdec->i_csp;
-#if HIGH_BIT_DEPTH
- pic_out->img.i_csp |= X264_CSP_HIGH_DEPTH;
-#endif
+ if( h->param.i_bitdepth > 8 )
+ pic_out->img.i_csp |= X264_CSP_HIGH_DEPTH;
+
pic_out->img.i_plane = h->fdec->i_plane;
for( int i = 0; i < pic_out->img.i_plane; i++ )
{
diff --git a/encoder/set.c b/encoder/set.c
index 07cb4c4..51b91f8 100644
--- a/encoder/set.c
+++ b/encoder/set.c
@@ -107,13 +107,14 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
sps->i_mb_height= ( param->i_height + 15 ) / 16;
sps->i_chroma_format_idc = csp >= X264_CSP_I444 ? CHROMA_444 :
csp >= X264_CSP_I422 ? CHROMA_422 : CHROMA_420;
+ sps->i_bitdepth = param->i_bitdepth;
sps->b_qpprime_y_zero_transform_bypass = param->rc.i_rc_method == X264_RC_CQP && param->rc.i_qp_constant == 0;
if( sps->b_qpprime_y_zero_transform_bypass || sps->i_chroma_format_idc == CHROMA_444 )
sps->i_profile_idc = PROFILE_HIGH444_PREDICTIVE;
else if( sps->i_chroma_format_idc == CHROMA_422 )
sps->i_profile_idc = PROFILE_HIGH422;
- else if( BIT_DEPTH > 8 )
+ else if( param->i_bitdepth > 8 )
sps->i_profile_idc = PROFILE_HIGH10;
else if( param->analyse.b_transform_8x8 || param->i_cqm_preset != X264_CQM_FLAT )
sps->i_profile_idc = PROFILE_HIGH;
@@ -287,8 +288,8 @@ void x264_sps_write( bs_t *s, x264_sps_t *sps )
bs_write_ue( s, sps->i_chroma_format_idc );
if( sps->i_chroma_format_idc == CHROMA_444 )
bs_write1( s, 0 ); // separate_colour_plane_flag
- bs_write_ue( s, BIT_DEPTH-8 ); // bit_depth_luma_minus8
- bs_write_ue( s, BIT_DEPTH-8 ); // bit_depth_chroma_minus8
+ bs_write_ue( s, sps->i_bitdepth-8 ); // bit_depth_luma_minus8
+ bs_write_ue( s, sps->i_bitdepth-8 ); // bit_depth_chroma_minus8
bs_write1( s, sps->b_qpprime_y_zero_transform_bypass );
bs_write1( s, 0 ); // seq_scaling_matrix_present_flag
}
diff --git a/x264.h b/x264.h
index 5ac4baf..e21b9ef 100644
--- a/x264.h
+++ b/x264.h
@@ -293,6 +293,7 @@ typedef struct x264_param_t
int i_width;
int i_height;
int i_csp; /* CSP of encoded bitstream */
+ int i_bitdepth;
int i_level_idc;
int i_frame_total; /* number of frames to encode if known, else 0 */
--
2.10.0
More information about the x264-devel
mailing list