#include <windows.h>
#endif
+#define PROGRESS_LENGTH 36
+
typedef struct
{
FFMS_VideoSource *video_source;
return 0;
*update_time = newtime;
- char buf[200];
- sprintf( buf, "ffms [info]: indexing input file [%.1f%%]", 100.0 * current / total );
- fprintf( stderr, "%s \r", buf+5 );
+ char buf[PROGRESS_LENGTH+5+1];
+ snprintf( buf, sizeof(buf), "ffms [info]: indexing input file [%.1f%%]", 100.0 * current / total );
+ fprintf( stderr, "%-*s\r", PROGRESS_LENGTH, buf+5 );
x264_cli_set_console_title( buf );
fflush( stderr );
return 0;
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;
if( opt->index_file )
{
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( !x264_stat( opt->index_file, &index_s ) && !x264_stat( psz_filename, &input_s ) && input_s.st_mtime < index_s.st_mtime )
+ {
+ idx = FFMS_ReadIndex( opt->index_file, &e );
+ if( idx && FFMS_IndexBelongsToFile( idx, psz_filename, &e ) )
+ {
+ FFMS_DestroyIndex( idx );
+ idx = NULL;
+ }
+ }
}
if( !idx )
{
+ FFMS_Indexer *indexer = FFMS_CreateIndexer( psz_filename, &e );
+ FAIL_IF_ERROR( !indexer, "could not create indexer\n" )
+
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 );
+ FFMS_SetProgressCallback( indexer, update_progress, &h->time );
+
+ idx = FFMS_DoIndexing2( indexer, FFMS_IEH_ABORT, &e );
+ fprintf( stderr, "%*c", PROGRESS_LENGTH+1, '\r' );
FAIL_IF_ERROR( !idx, "could not create index\n" )
- if( opt->index_file && FFMS_WriteIndex( idx_filename, idx, &e ) )
+
+ if( opt->index_file && FFMS_WriteIndex( opt->index_file, 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" )
+ if( trackno >= 0 )
+ h->video_source = FFMS_CreateVideoSource( psz_filename, trackno, idx, 1, seekmode, &e );
+ FFMS_DestroyIndex( idx );
- h->video_source = FFMS_CreateVideoSource( src_filename, trackno, idx, 1, seekmode, &e );
+ FAIL_IF_ERROR( trackno < 0, "could not find video track\n" )
FAIL_IF_ERROR( !h->video_source, "could not create video source\n" )
- h->track = FFMS_GetTrackFromVideo( h->video_source );
-
- FFMS_DestroyIndex( idx );
const FFMS_VideoProperties *videop = FFMS_GetVideoProperties( h->video_source );
info->num_frames = h->num_frames = videop->NumFrames;
info->sar_height = videop->SARDen;
* so we need to reduce large timebases to prevent overflow */
if( h->vfr_input )
{
+ h->track = FFMS_GetTrackFromVideo( h->video_source );
const FFMS_TrackTimeBase *timebase = FFMS_GetTimeBase( h->track );
int64_t timebase_num = timebase->Num;
int64_t timebase_den = timebase->Den * 1000;