Skip to content

Instantly share code, notes, and snippets.

@astrataro
Forked from SAPikachu/gist:1131739
Created December 11, 2011 21:12
Show Gist options
  • Save astrataro/1462770 to your computer and use it in GitHub Desktop.
Save astrataro/1462770 to your computer and use it in GitHub Desktop.
x264: skips depth filter when possible
a68cd9bf80f359d376cce02a295299302ed95d02
filters/video/depth.c | 7 +++++++
input/avs.c | 5 +++++
input/raw.c | 9 ++++++++-
x264.h | 1 +
4 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/filters/video/depth.c b/filters/video/depth.c
index 25dde25..b6cf1a5 100644
--- a/filters/video/depth.c
+++ b/filters/video/depth.c
@@ -174,6 +174,13 @@ static void free_filter( hnd_t handle )
static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info,
x264_param_t *param, char *opt_string )
{
+ if( info->csp & X264_CSP_SKIP_DEPTH_FILTER )
+ {
+ x264_cli_log( "depth", X264_LOG_INFO, "skipped depth filter\n" );
+ info->csp = (info->csp & X264_CSP_MASK) | X264_CSP_HIGH_DEPTH;
+ return 0;
+ }
+
int ret = 0;
int change_fmt = (info->csp ^ param->i_csp) & X264_CSP_HIGH_DEPTH;
int csp = ~(~info->csp ^ change_fmt);
diff --git a/input/avs.c b/input/avs.c
index 373fa68..89032ca 100644
--- a/input/avs.c
+++ b/input/avs.c
@@ -273,6 +273,11 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
x264_cli_log( "avs", X264_LOG_INFO, "avisynth 16bit hack enabled\n" );
info->csp |= X264_CSP_HIGH_DEPTH;
info->width >>= 1;
+ if( opt->bit_depth == BIT_DEPTH )
+ {
+ /* HACK: totally skips depth filter to prevent dither error */
+ info->csp |= X264_CSP_SKIP_DEPTH_FILTER;
+ }
}
*p_handle = h;
diff --git a/input/raw.c b/input/raw.c
index 12bddce..57c352b 100644
--- a/input/raw.c
+++ b/input/raw.c
@@ -68,7 +68,14 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
h->bit_depth = opt->bit_depth;
FAIL_IF_ERROR( h->bit_depth < 8 || h->bit_depth > 16, "unsupported bit depth `%d'\n", h->bit_depth );
if( h->bit_depth > 8 )
+ {
info->csp |= X264_CSP_HIGH_DEPTH;
+ if( h->bit_depth == BIT_DEPTH )
+ {
+ /* HACK: totally skips depth filter to prevent dither error */
+ info->csp |= X264_CSP_SKIP_DEPTH_FILTER;
+ }
+ }
if( !strcmp( psz_filename, "-" ) )
h->fh = stdin;
@@ -109,7 +116,7 @@ static int read_frame_internal( cli_pic_t *pic, raw_hnd_t *h )
for( int i = 0; i < pic->img.planes && !error; i++ )
{
error |= fread( pic->img.plane[i], pixel_depth, h->plane_size[i], h->fh ) != h->plane_size[i];
- if( h->bit_depth & 7 )
+ if( h->bit_depth & 7 && h->bit_depth != BIT_DEPTH )
{
/* upconvert non 16bit high depth planes to 16bit using the same
* algorithm as used in the depth filter. */
diff --git a/x264.h b/x264.h
index 965d314..c806f2d 100644
--- a/x264.h
+++ b/x264.h
@@ -188,6 +188,7 @@ static const char * const x264_nal_hrd_names[] = { "none", "vbr", "cbr", 0 };
#define X264_CSP_MAX 0x0009 /* end of list */
#define X264_CSP_VFLIP 0x1000 /* the csp is vertically flipped */
#define X264_CSP_HIGH_DEPTH 0x2000 /* the csp has a depth of 16 bits per pixel component */
+#define X264_CSP_SKIP_DEPTH_FILTER 0x0100 /* HACK: totally skips depth filter to prevent dither error */
/* Slice type */
#define X264_TYPE_AUTO 0x0000 /* Let x264 choose the right type */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment