/*****************************************************************************
- * ffms.c: x264 ffmpegsource input module
+ * ffms.c: ffmpegsource input
*****************************************************************************
- * Copyright (C) 2009 x264 project
+ * Copyright (C) 2009-2011 x264 project
*
* Authors: Mike Gurlitz <mike.gurlitz@gmail.com>
* Steven Walters <kemuri9@gmail.com>
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing@x264.com.
*****************************************************************************/
#include "input.h"
FFMS_Track *track;
int reduce_pts;
int vfr_input;
+ int num_frames;
+ int64_t time;
} ffms_hnd_t;
static int FFMS_CC update_progress( int64_t current, int64_t total, void *private )
{
- if( current % 10 )
+ int64_t *update_time = private;
+ int64_t oldtime = *update_time;
+ int64_t newtime = x264_mdate();
+ if( oldtime && newtime - oldtime < UPDATE_INTERVAL )
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 );
ffms_hnd_t *h = calloc( 1, sizeof(ffms_hnd_t) );
if( !h )
return -1;
- FFMS_Init( 0 );
+ FFMS_Init( 0, 0 );
FFMS_ErrorInfo e;
e.BufferSize = 0;
int seekmode = opt->seek ? FFMS_SEEK_NORMAL : FFMS_SEEK_LINEAR_NO_RW;
}
if( !idx )
{
- idx = FFMS_MakeIndex( psz_filename, 0, 0, NULL, NULL, 0, update_progress, NULL, &e );
- fprintf( stderr, " \r" );
+ if( opt->progress )
+ {
+ idx = FFMS_MakeIndex( psz_filename, 0, 0, NULL, NULL, 0, update_progress, &h->time, &e );
+ fprintf( stderr, " \r" );
+ }
+ else
+ idx = FFMS_MakeIndex( psz_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 ) )
x264_cli_log( "ffms", X264_LOG_WARNING, "could not write index file\n" );
FFMS_DestroyIndex( idx );
const FFMS_VideoProperties *videop = FFMS_GetVideoProperties( h->video_source );
- info->num_frames = videop->NumFrames;
+ info->num_frames = h->num_frames = videop->NumFrames;
info->sar_height = videop->SARDen;
info->sar_width = videop->SARNum;
info->fps_den = videop->FPSDenominator;
static int read_frame( cli_pic_t *pic, hnd_t handle, int i_frame )
{
ffms_hnd_t *h = handle;
+ if( i_frame >= h->num_frames )
+ return -1;
FFMS_ErrorInfo e;
e.BufferSize = 0;
const FFMS_Frame *frame = FFMS_GetFrame( h->video_source, i_frame, &e );
- FAIL_IF_ERROR( !frame, "could not read frame %d\n", i_frame )
+ FAIL_IF_ERROR( !frame, "could not read frame %d \n", i_frame )
memcpy( pic->img.stride, frame->Linesize, sizeof(pic->img.stride) );
memcpy( pic->img.plane, frame->Data, sizeof(pic->img.plane) );