[x264-devel] ffms: Various improvements

Henrik Gramner git at videolan.org
Tue Apr 12 20:36:14 CEST 2016


x264 | branch: master | Henrik Gramner <henrik at gramner.com> | Sun Jan 31 21:50:52 2016 +0100| [dfe394cadc8a39752de5b3f4a0be222c1b9290f2] | committer: Henrik Gramner

ffms: Various improvements

 * Drop the MinGW Unicode workarounds. Those were required at the time
   Windows Unicode support was added to x264 but the underlying problem
   has since been fixed in FFMS.

 * Use FFMS_IndexBelongsToFile() as an additional sanity check when reading
   an index file to ensure that it belongs to the current source video.

 * Upgrade to the new API to prevent deprecation warnings when compiling.

 * Fix a resource leak that would occur if FFMS_GetFirstTrackOfType() or
   FFMS_CreateVideoSource() failed.

 * Minor string handling adjustments related to progress reporting.

This increases the FFMS version requirement from 2.16.2 to 2.21.0.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=dfe394cadc8a39752de5b3f4a0be222c1b9290f2
---

 configure    |    2 +-
 input/ffms.c |   59 ++++++++++++++++++++++++++++------------------------------
 2 files changed, 29 insertions(+), 32 deletions(-)

diff --git a/configure b/configure
index 361a7ef..5b9f8af 100755
--- a/configure
+++ b/configure
@@ -1046,7 +1046,7 @@ if [ "$lavf" = "auto" ] ; then
 fi
 
 if [ "$ffms" = "auto" ] ; then
-    ffms_major="2"; ffms_minor="16"; ffms_micro="2"; ffms_bump="0"
+    ffms_major="2"; ffms_minor="21"; ffms_micro="0"; ffms_bump="0"
     ffms="no"
 
     if ${cross_prefix}pkg-config --exists ffms2 2>/dev/null; then
diff --git a/input/ffms.c b/input/ffms.c
index 62b06e9..35dc7ca 100644
--- a/input/ffms.c
+++ b/input/ffms.c
@@ -37,6 +37,8 @@
 #include <windows.h>
 #endif
 
+#define PROGRESS_LENGTH 36
+
 typedef struct
 {
     FFMS_VideoSource *video_source;
@@ -56,9 +58,9 @@ static int FFMS_CC update_progress( int64_t current, int64_t total, void *privat
         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;
@@ -82,20 +84,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     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;
@@ -104,33 +93,40 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     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;
@@ -156,6 +152,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
      * 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;



More information about the x264-devel mailing list