From: Loren Merritt Date: Sun, 18 May 2008 12:23:57 +0000 (-0600) Subject: change DEBUG_DUMP_FRAME to run-time --dump-yuv X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92b3ea8c24f5932a3535cac71e8d9260e5a8e198;p=libx264 change DEBUG_DUMP_FRAME to run-time --dump-yuv --- diff --git a/common/common.c b/common/common.c index f88bf8c4..8a8f6600 100644 --- a/common/common.c +++ b/common/common.c @@ -430,6 +430,8 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value ) OPT("visualize") p->b_visualize = atobool(value); #endif + OPT("dump-yuv") + p->psz_dump_yuv = strdup(value); OPT2("analyse", "partitions") { p->analyse.inter = 0; diff --git a/encoder/encoder.c b/encoder/encoder.c index 35ebad13..807d19d9 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -36,7 +36,6 @@ #endif //#define DEBUG_MB_TYPE -//#define DEBUG_DUMP_FRAME #define NALU_OVERHEAD 5 // startcode + NAL type costs 5 bytes per frame @@ -58,27 +57,19 @@ static float x264_psnr( int64_t i_sqe, int64_t i_size ) return (float)(-10.0 * log( f_mse ) / log( 10.0 )); } -#ifdef DEBUG_DUMP_FRAME -static void x264_frame_dump( x264_t *h, x264_frame_t *fr, char *name ) +static void x264_frame_dump( x264_t *h ) { - FILE *f = fopen( name, "r+b" ); + FILE *f = fopen( h->param.psz_dump_yuv, "r+b" ); int i, y; if( !f ) return; - /* Write the frame in display order */ - fseek( f, fr->i_frame * h->param.i_height * h->param.i_width * 3 / 2, SEEK_SET ); - - for( i = 0; i < fr->i_plane; i++ ) - { - for( y = 0; y < h->param.i_height / ( i == 0 ? 1 : 2 ); y++ ) - { - fwrite( &fr->plane[i][y*fr->i_stride[i]], 1, h->param.i_width / ( i == 0 ? 1 : 2 ), f ); - } - } + fseek( f, h->fdec->i_frame * h->param.i_height * h->param.i_width * 3/2, SEEK_SET ); + for( i = 0; i < h->fdec->i_plane; i++ ) + for( y = 0; y < h->param.i_height >> !!i; y++ ) + fwrite( &h->fdec->plane[i][y*h->fdec->i_stride[i]], 1, h->param.i_width >> !!i, f ); fclose( f ); } -#endif /* Fill "default" values */ @@ -698,10 +689,10 @@ x264_t *x264_encoder_open ( x264_param_t *param ) if( x264_ratecontrol_new( h ) < 0 ) return NULL; -#ifdef DEBUG_DUMP_FRAME + if( h->param.psz_dump_yuv ) { /* create or truncate the reconstructed video file */ - FILE *f = fopen( "fdec.yuv", "w" ); + FILE *f = fopen( h->param.psz_dump_yuv, "w" ); if( f ) fclose( f ); else @@ -711,7 +702,6 @@ x264_t *x264_encoder_open ( x264_param_t *param ) return NULL; } } -#endif return h; } @@ -886,9 +876,7 @@ static void x264_fdec_filter_row( x264_t *h, int mb_y ) int b_deblock = !h->sh.i_disable_deblocking_filter_idc; int b_end = mb_y == h->sps->i_mb_height; int min_y = mb_y - (1 << h->sh.b_mbaff); -#ifndef DEBUG_DUMP_FRAME - b_deblock &= b_hpel; -#endif + b_deblock &= b_hpel || h->param.psz_dump_yuv; if( mb_y & h->sh.b_mbaff ) return; if( min_y < 0 ) @@ -1725,10 +1713,8 @@ static void x264_encoder_frame_end( x264_t *h, x264_t *thread_current, } #endif -#ifdef DEBUG_DUMP_FRAME - /* Dump reconstructed frame */ - x264_frame_dump( h, h->fdec, "fdec.yuv" ); -#endif + if( h->param.psz_dump_yuv ) + x264_frame_dump( h ); } /**************************************************************************** diff --git a/x264.c b/x264.c index 70adb718..8484cadd 100644 --- a/x264.c +++ b/x264.c @@ -319,6 +319,7 @@ static void Help( x264_param_t *defaults, int b_longhelp ) H1( " --asm Override CPU detection\n" ); H1( " --no-asm Disable all CPU optimizations\n" ); H1( " --visualize Show MB types overlayed on the encoded video\n" ); + H1( " --dump-yuv Save reconstructed frames\n" ); H1( " --sps-id Set SPS and PPS id numbers [%d]\n", defaults->i_sps_id ); H1( " --aud Use access unit delimiters\n" ); H0( "\n" ); @@ -447,6 +448,7 @@ static int Parse( int argc, char **argv, { "verbose", no_argument, NULL, 'v' }, { "progress",no_argument, NULL, OPT_PROGRESS }, { "visualize",no_argument, NULL, OPT_VISUALIZE }, + { "dump-yuv",required_argument, NULL, 0 }, { "sps-id", required_argument, NULL, 0 }, { "aud", no_argument, NULL, 0 }, { "nr", required_argument, NULL, 0 }, diff --git a/x264.h b/x264.h index d2c65103..c41d6f08 100644 --- a/x264.h +++ b/x264.h @@ -210,6 +210,7 @@ typedef struct x264_param_t void *p_log_private; int i_log_level; int b_visualize; + char *psz_dump_yuv; /* filename for reconstructed frames */ /* Encoder analyser parameters */ struct