Hi,

recently i noticed that all clips i was trying to play with mlt has duration 1 smaller then origin.

this happens because of calculation (or even compiler) of frames count that comes on double and later not rounded to integer.

code part of producer_avformat.c:
[...]
590:    // This isn't going to be accurate for all formats
591: mlt_position frames = ( mlt_position )( ( ( double )format->duration / ( double )AV_TIME_BASE ) * fps );
592:    mlt_properties_set_position( properties, "out", frames - 1 );
[...]

that code part is compiled into something like this:

B+ x0x7ffff0afdb0b <producer_open+2123> cvtsi2sd %rsi,%xmm1 x x0x7ffff0afdb10 <producer_open+2128> lea 0x9dd1(%rip),%rdi # 0x7ffff0b078e8 x x0x7ffff0afdb17 <producer_open+2135> mov $0xf4240,%edx rdx x x0x7ffff0afdb1c <producer_open+2140> mov %rd2,%ea(%rax) x x0x7ffff0afdb21 <producer_open+2145> mulsd 0xa067(%rip),%xmm1 # 0x7ffff0b07b90l_debug_state> x x0x7ffff0afdb29 <producer_open+2153> mulsd %xmm0,%xmm1 ) x x0x7ffff0afdb2d <producer_open+2157> cvttsd2si %xmm1,%ebp x >x0x7ffff0afdb31 <producer_open+2161> mov %ebp,%ecx ) x

in my case clip has 251 frame. before *cvttsd2si* xmm1 register has value 250.99999999999997:

1: x/i $pc
=> 0x7ffff0afdb2d <producer_open+2157>: cvttsd2si %xmm1,%ebp
(gdb) print $xmm1
$5 = {v4_float = {-nan(0x7fffff), 3.74023414, 1.40129846e-45, 0}, v2_double = {250.99999999999997, 4.9406564584124654e-324}, v16_int8 = {-1, -1, -1, -1, -1, 95, 111, 64, 1, 0, 0, 0, 0, 0, 0, 0}, v8_int16 = { -1, -1, 24575, 16495, 1, 0, 0, 0}, v4_int32 = {-1, 1081040895, 1, 0}, v2_int64 = {4643035293958537215, 1},
  uint128 = 0x0000000000000001406f5fffffffffff}

but after storing into *ecx* it becode truncated:

(gdb) step
1: x/i $pc
=> 0x7ffff0afdb31 <producer_open+2161>: mov    %ebp,%ecx
(gdb) print $ebp
$6 = 250

attached patch tries to avoid double type using during calculation and properly return 251 frames length...

--
________________________________________
Maksym Veremeyenko
>From b6c261c1224e27bf877a3647870d0699d1058215 Mon Sep 17 00:00:00 2001
From: Maksym Veremeyenko <ve...@m1stereo.tv>
Date: Thu, 18 Jul 2013 15:03:40 +0300
Subject: [PATCH] use rational fps value to calc frames count

---
 src/modules/avformat/producer_avformat.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c
index 9068f08..1e5341c 100644
--- a/src/modules/avformat/producer_avformat.c
+++ b/src/modules/avformat/producer_avformat.c
@@ -575,10 +575,6 @@ static int get_basic_info( producer_avformat self, mlt_profile profile, const ch
 
 	AVFormatContext *format = self->video_format;
 
-	// We will treat everything with the producer fps.
-	// TODO: make this more flexible.
-	double fps = mlt_profile_fps( profile );
-
 	// Get the duration
 	if ( !mlt_properties_get_int( properties, "_length_computed" ) )
 	{
@@ -587,7 +583,9 @@ static int get_basic_info( producer_avformat self, mlt_profile profile, const ch
 		if ( format->duration != AV_NOPTS_VALUE )
 		{
 			// This isn't going to be accurate for all formats
-			mlt_position frames = ( mlt_position )( ( ( double )format->duration / ( double )AV_TIME_BASE ) * fps );
+			// We will treat everything with the producer fps.
+			mlt_position frames = ( mlt_position )( int )( format->duration *
+				profile->frame_rate_num / profile->frame_rate_den / AV_TIME_BASE);
 			mlt_properties_set_position( properties, "out", frames - 1 );
 			mlt_properties_set_position( properties, "length", frames );
 			mlt_properties_set_int( properties, "_length_computed", 1 );
-- 
1.7.7.6

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Mlt-devel mailing list
Mlt-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlt-devel

Reply via email to