X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=input%2Fffms.c;h=6a3eb6c7663aba9a0d2901ce17e1a31d840de164;hb=59683a97b50b34c6282457a959bb6b3e9e7f8c0d;hp=8e76e5a142b65ea3e164998dd3f61ef33e730e45;hpb=24caade52252a0a41c4869525dde8e5a47c55063;p=x264 diff --git a/input/ffms.c b/input/ffms.c index 8e76e5a1..6a3eb6c7 100644 --- a/input/ffms.c +++ b/input/ffms.c @@ -1,10 +1,11 @@ /***************************************************************************** * ffms.c: ffmpegsource input ***************************************************************************** - * Copyright (C) 2009-2011 x264 project + * Copyright (C) 2009-2015 x264 project * * Authors: Mike Gurlitz * Steven Walters + * Henrik Gramner * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,8 +35,6 @@ #ifdef _WIN32 #include -#else -#define SetConsoleTitle(t) #endif typedef struct @@ -60,17 +59,43 @@ static int FFMS_CC update_progress( int64_t current, int64_t total, void *privat char buf[200]; sprintf( buf, "ffms [info]: indexing input file [%.1f%%]", 100.0 * current / total ); fprintf( stderr, "%s \r", buf+5 ); - SetConsoleTitle( buf ); + x264_cli_set_console_title( buf ); fflush( stderr ); return 0; } +/* handle the deprecated jpeg pixel formats */ +static int handle_jpeg( int csp, int *fullrange ) +{ + switch( csp ) + { + case AV_PIX_FMT_YUVJ420P: *fullrange = 1; return AV_PIX_FMT_YUV420P; + case AV_PIX_FMT_YUVJ422P: *fullrange = 1; return AV_PIX_FMT_YUV422P; + case AV_PIX_FMT_YUVJ444P: *fullrange = 1; return AV_PIX_FMT_YUV444P; + default: return csp; + } +} + static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt ) { ffms_hnd_t *h = calloc( 1, sizeof(ffms_hnd_t) ); if( !h ) return -1; + +#ifdef __MINGW32__ + /* FFMS supports UTF-8 filenames, but it uses std::fstream internally which is broken with Unicode in MinGW. */ FFMS_Init( 0, 0 ); + char src_filename[MAX_PATH]; + char idx_filename[MAX_PATH]; + FAIL_IF_ERROR( !x264_ansi_filename( psz_filename, src_filename, MAX_PATH, 0 ), "invalid ansi filename\n" ); + if( opt->index_file ) + FAIL_IF_ERROR( !x264_ansi_filename( opt->index_file, idx_filename, MAX_PATH, 1 ), "invalid ansi filename\n" ); +#else + FFMS_Init( 0, 1 ); + char *src_filename = psz_filename; + char *idx_filename = opt->index_file; +#endif + FFMS_ErrorInfo e; e.BufferSize = 0; int seekmode = opt->seek ? FFMS_SEEK_NORMAL : FFMS_SEEK_LINEAR_NO_RW; @@ -78,24 +103,29 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c FFMS_Index *idx = NULL; if( opt->index_file ) { - struct stat index_s, input_s; - if( !stat( opt->index_file, &index_s ) && !stat( psz_filename, &input_s ) && - input_s.st_mtime < index_s.st_mtime ) - idx = FFMS_ReadIndex( opt->index_file, &e ); + x264_struct_stat index_s, input_s; + if( !x264_stat( opt->index_file, &index_s ) && !x264_stat( psz_filename, &input_s ) && + input_s.st_mtime < index_s.st_mtime && index_s.st_size ) + idx = FFMS_ReadIndex( idx_filename, &e ); } if( !idx ) { - idx = FFMS_MakeIndex( psz_filename, 0, 0, NULL, NULL, 0, update_progress, &h->time, &e ); - fprintf( stderr, " \r" ); + if( opt->progress ) + { + idx = FFMS_MakeIndex( src_filename, 0, 0, NULL, NULL, 0, update_progress, &h->time, &e ); + fprintf( stderr, " \r" ); + } + else + idx = FFMS_MakeIndex( src_filename, 0, 0, NULL, NULL, 0, NULL, NULL, &e ); FAIL_IF_ERROR( !idx, "could not create index\n" ) - if( opt->index_file && FFMS_WriteIndex( opt->index_file, idx, &e ) ) + if( opt->index_file && FFMS_WriteIndex( idx_filename, idx, &e ) ) x264_cli_log( "ffms", X264_LOG_WARNING, "could not write index file\n" ); } int trackno = FFMS_GetFirstTrackOfType( idx, FFMS_TYPE_VIDEO, &e ); FAIL_IF_ERROR( trackno < 0, "could not find video track\n" ) - h->video_source = FFMS_CreateVideoSource( psz_filename, trackno, idx, 1, seekmode, &e ); + h->video_source = FFMS_CreateVideoSource( src_filename, trackno, idx, 1, seekmode, &e ); FAIL_IF_ERROR( !h->video_source, "could not create video source\n" ) h->track = FFMS_GetTrackFromVideo( h->video_source ); @@ -114,11 +144,13 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c const FFMS_Frame *frame = FFMS_GetFrame( h->video_source, 0, &e ); FAIL_IF_ERROR( !frame, "could not read frame 0\n" ) + info->fullrange = 0; info->width = frame->EncodedWidth; info->height = frame->EncodedHeight; - info->csp = frame->EncodedPixelFormat | X264_CSP_OTHER; + info->csp = handle_jpeg( frame->EncodedPixelFormat, &info->fullrange ) | X264_CSP_OTHER; info->interlaced = frame->InterlacedFrame; info->tff = frame->TopFieldFirst; + info->fullrange |= frame->ColorRange == FFMS_CR_JPEG; /* ffms timestamps are in milliseconds. ffms also uses int64_ts for timebase, * so we need to reduce large timebases to prevent overflow */ @@ -145,8 +177,9 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c static int picture_alloc( cli_pic_t *pic, int csp, int width, int height ) { - if( x264_cli_pic_alloc( pic, csp, width, height ) ) + if( x264_cli_pic_alloc( pic, X264_CSP_NONE, width, height ) ) return -1; + pic->img.csp = csp; pic->img.planes = 4; return 0; }