+static int init_vid_filters( char *sequence, hnd_t *handle, video_info_t *info, x264_param_t *param )
+{
+ x264_register_vid_filters();
+
+ /* intialize baseline filters */
+ if( x264_init_vid_filter( "source", handle, &filter, info, param, NULL ) ) /* wrap demuxer into a filter */
+ return -1;
+ if( x264_init_vid_filter( "resize", handle, &filter, info, param, "normcsp" ) ) /* normalize csps to be of a known/supported format */
+ return -1;
+ if( x264_init_vid_filter( "fix_vfr_pts", handle, &filter, info, param, NULL ) ) /* fix vfr pts */
+ return -1;
+
+ /* parse filter chain */
+ for( char *p = sequence; p && *p; )
+ {
+ int tok_len = strcspn( p, "/" );
+ int p_len = strlen( p );
+ p[tok_len] = 0;
+ int name_len = strcspn( p, ":" );
+ p[name_len] = 0;
+ name_len += name_len != tok_len;
+ if( x264_init_vid_filter( p, handle, &filter, info, param, p + name_len ) )
+ return -1;
+ p += X264_MIN( tok_len+1, p_len );
+ }
+
+ /* force end result resolution */
+ if( !param->i_width && !param->i_height )
+ {
+ param->i_height = info->height;
+ param->i_width = info->width;
+ }
+ /* if the current csp is supported by libx264, have libx264 use this csp.
+ * otherwise change the csp to I420 and have libx264 use this.
+ * when more colorspaces are supported, this decision will need to be updated. */
+ int csp = info->csp & X264_CSP_MASK;
+ if( csp > X264_CSP_NONE && csp < X264_CSP_MAX )
+ param->i_csp = info->csp;
+ else
+ param->i_csp = X264_CSP_I420 | ( info->csp & X264_CSP_HIGH_DEPTH );
+ if( x264_init_vid_filter( "resize", handle, &filter, info, param, NULL ) )
+ return -1;
+
+ char args[20];
+ sprintf( args, "bit_depth=%d", x264_bit_depth );
+
+ if( x264_init_vid_filter( "depth", handle, &filter, info, param, args ) )
+ return -1;
+
+ return 0;
+}
+