diff --git a/common/osdep.h b/common/osdep.h index b1b357c..b3a8cd6 100644 --- a/common/osdep.h +++ b/common/osdep.h @@ -290,7 +290,15 @@ static inline uint8_t x264_is_regular_file( FILE *filehandle ) { struct stat file_stat; if( fstat( fileno( filehandle ), &file_stat ) ) - return 0; + return -1; + return S_ISREG( file_stat.st_mode ); +} + +static inline uint8_t x264_is_regular_file_path( const char *filename ) +{ + struct stat file_stat; + if( stat( filename, &file_stat ) ) + return -1; return S_ISREG( file_stat.st_mode ); } diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 2c05ad7..03f1297 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -1059,7 +1059,7 @@ void x264_ratecontrol_delete( x264_t *h ) if( rc->p_stat_file_out ) { - b_regular_file = x264_is_regular_file( rc->p_stat_file_out ); + b_regular_file = (x264_is_regular_file( rc->p_stat_file_out ) == 1); fclose( rc->p_stat_file_out ); if( h->i_frame >= rc->num_entries && b_regular_file ) if( rename( rc->psz_stat_file_tmpname, h->param.rc.psz_stat_out ) != 0 ) @@ -1071,7 +1071,7 @@ void x264_ratecontrol_delete( x264_t *h ) } if( rc->p_mbtree_stat_file_out ) { - b_regular_file = x264_is_regular_file( rc->p_mbtree_stat_file_out ); + b_regular_file = (x264_is_regular_file( rc->p_mbtree_stat_file_out ) == 1); fclose( rc->p_mbtree_stat_file_out ); if( h->i_frame >= rc->num_entries && b_regular_file ) if( rename( rc->psz_mbtree_stat_file_tmpname, rc->psz_mbtree_stat_file_name ) != 0 ) diff --git a/input/y4m.c b/input/y4m.c index fd42140..9ea0cf2 100644 --- a/input/y4m.c +++ b/input/y4m.c @@ -178,7 +178,7 @@ static int get_frame_total( hnd_t handle ) y4m_hnd_t *h = handle; int i_frame_total = 0; - if( x264_is_regular_file( h->fh ) ) + if( x264_is_regular_file( h->fh ) == 1 ) { uint64_t init_pos = ftell( h->fh ); fseek( h->fh, 0, SEEK_END ); @@ -233,7 +233,7 @@ static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame ) if( i_frame > h->next_frame ) { - if( x264_is_regular_file( h->fh ) ) + if( x264_is_regular_file( h->fh ) == 1 ) fseek( h->fh, (uint64_t)i_frame*(3*(h->width*h->height)/2+h->frame_header_len) + h->seq_header_len, SEEK_SET ); else diff --git a/input/yuv.c b/input/yuv.c index cbed7fc..2571cfe 100644 --- a/input/yuv.c +++ b/input/yuv.c @@ -72,7 +72,7 @@ static int get_frame_total( hnd_t handle ) yuv_hnd_t *h = handle; int i_frame_total = 0; - if( x264_is_regular_file( h->fh ) ) + if( x264_is_regular_file( h->fh ) == 1 ) { fseek( h->fh, 0, SEEK_END ); uint64_t i_size = ftell( h->fh ); @@ -96,7 +96,7 @@ static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame ) if( i_frame > h->next_frame ) { - if( x264_is_regular_file( h->fh ) ) + if( x264_is_regular_file( h->fh ) == 1 ) fseek( h->fh, (uint64_t)i_frame * h->width * h->height * 3 / 2, SEEK_SET ); else while( i_frame > h->next_frame ) diff --git a/output/flv.c b/output/flv.c index e441b6d..cf3648f 100644 --- a/output/flv.c +++ b/output/flv.c @@ -282,7 +282,7 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest double total_duration = (double)(2 * largest_pts - second_largest_pts) * p_flv->i_timebase_num / p_flv->i_timebase_den; - if( x264_is_regular_file( c->fp ) ) + if( x264_is_regular_file( c->fp ) == 1 ) { double framerate; uint64_t filesize = ftell( c->fp ); diff --git a/output/matroska_ebml.c b/output/matroska_ebml.c index 31b62f8..3a4f83e 100644 --- a/output/matroska_ebml.c +++ b/output/matroska_ebml.c @@ -492,7 +492,7 @@ int mk_close( mk_writer *w, int64_t last_delta ) int ret = 0; if( mk_flush_frame( w ) < 0 || mk_close_cluster( w ) < 0 ) ret = -1; - if( w->wrote_header && x264_is_regular_file( w->fp ) ) + if( w->wrote_header && (x264_is_regular_file( w->fp ) == 1) ) { fseek( w->fp, w->duration_ptr, SEEK_SET ); int64_t last_frametime = w->def_duration ? w->def_duration : last_delta; diff --git a/x264.c b/x264.c index a124083..09bad61 100644 --- a/x264.c +++ b/x264.c @@ -806,6 +806,7 @@ static int select_input( const char *demuxer, char *used_demuxer, char *filename int b_auto = !strcasecmp( demuxer, "auto" ); if( !b_regular && b_auto ) ext = "yuv"; + b_regular = b_regular && x264_is_regular_file_path( filename ); if( b_regular ) { FILE *f = fopen( filename, "r" );