if ( context->duration != AV_NOPTS_VALUE )
{
// This isn't going to be accurate for all formats
- mlt_position frames = ( mlt_position )( ( ( double )context->duration / ( double )AV_TIME_BASE ) * fps );
- mlt_properties_set_position( properties, "out", frames - 2 );
- mlt_properties_set_position( properties, "length", frames - 1 );
+ mlt_position frames = ( mlt_position )( ( ( double )context->duration / ( double )AV_TIME_BASE ) * fps + 0.5 );
+ mlt_properties_set_position( properties, "out", frames - 1 );
+ mlt_properties_set_position( properties, "length", frames - 0 );
}
// Find default audio and video streams
double fps = mlt_properties_get_double( properties, "fps" );
// This is the physical frame position in the source
- int req_position = ( int )( position / fps * source_fps );
+ int req_position = ( int )( position / fps * source_fps + 0.5 );
// Get the seekable status
int seekable = mlt_properties_get_int( properties, "seekable" );
else if ( seekable && ( position < expected || position - expected >= 12 ) )
{
// Calculate the timestamp for the requested frame
- int64_t timestamp = ( int64_t )( ( double )req_position / source_fps * AV_TIME_BASE );
+ int64_t timestamp = ( int64_t )( ( double )req_position / source_fps * AV_TIME_BASE + 0.5 );
if ( ( uint64_t )context->start_time != AV_NOPTS_VALUE )
timestamp += context->start_time;
if ( must_decode )
if ( ret >= 0 && pkt.stream_index == index && pkt.size > 0 )
{
// Determine time code of the packet
- int_position = ( int )( av_q2d( stream->time_base ) * pkt.dts * source_fps );
+ int_position = ( int )( av_q2d( stream->time_base ) * pkt.dts * source_fps + 0.5 );
if ( context->start_time != AV_NOPTS_VALUE )
- int_position -= ( int )( context->start_time * source_fps / AV_TIME_BASE );
-
+ int_position -= ( int )( context->start_time * source_fps / AV_TIME_BASE + 0.5 );
int last_position = mlt_properties_get_int( properties, "_last_position" );
if ( int_position == last_position )
int_position = last_position + 1;