@@ -209,37 +209,36 @@ void File_Ttml::Streams_Finish()
209209{
210210 if (Time_End.IsSet () && Time_Begin.IsSet ())
211211 {
212- int64s Duration=(Time_End-Time_Begin).ToMilliseconds ();
213- Fill (Stream_General, 0 , General_Duration, Duration);
214- Fill (Stream_Text, 0 , Text_Duration, Duration);
215- if (!Time_Begin.IsTimed ())
216- Fill (Stream_Text, 0 , Text_TimeCode_FirstFrame, Time_Begin.ToString ());
217- if (!Time_End.IsTimed () && Time_End>Time_Begin)
218- {
219- TimeCode LastFrame=Time_End;
220- --LastFrame;
221- Fill (Stream_Text, 0 , Text_TimeCode_LastFrame, LastFrame.ToString ());
222- }
223- auto MediaTimeToMilliseconds=[&](TimeCode TC)
212+ auto AdaptMediaTime=[&](TimeCode &TC)
224213 {
225- auto Is1001fps=TC.Is1001fps ();
226- if (TimeBase!=timeBase_media || (!Is1001fps && !TC.DropFrame ())) // https://www.w3.org/TR/2018/REC-ttml2-20181108/#semantics-media-timing
227- return TC.ToMilliseconds ();
214+ if (Time_Begin.IsTimed () || TimeBase!=timeBase_media || (!TC.Is1001fps () && !TC.DropFrame ())) // https://www.w3.org/TR/2018/REC-ttml2-20181108/#semantics-media-timing
215+ return ;
228216 auto Frames=TC.GetFrames ();
229217 auto MS=((float )Frames)*1000 /TC.GetFrameRate ();
230- TC.Set1001fps (false );
231- TC.SetDropFrame (false );
232- TC.SetFrames (0 );
233- auto Value=TC.ToMilliseconds ();
218+ auto Temp (TC);
219+ Temp.Set1001fps (false );
220+ Temp.SetDropFrame (false );
221+ Temp.SetFrames (0 );
222+ auto Value=Temp.ToMilliseconds ();
234223 Value+=float32_int64s (MS);
235- return Value;
224+ TC. FromSeconds ( Value / 1000.0 ) ;
236225 };
237- auto Time_Begin_ms = (int64s)MediaTimeToMilliseconds (Time_Begin);
238- auto Time_End_ms = (int64s)MediaTimeToMilliseconds (Time_End);
226+ AdaptMediaTime (Time_Begin);
227+ AdaptMediaTime (Time_End);
228+ auto Duration = Time_End - Time_Begin;
229+ auto Time_Begin_ms = (int64u)Time_Begin.ToMilliseconds ();
230+ auto Time_End_ms = (int64u)Time_End.ToMilliseconds ();
231+ auto Duration_ms = (int64u)(Time_End - Time_Begin).ToMilliseconds ();
232+ Fill (Stream_General, 0 , General_Duration, Duration_ms);
233+ Fill (Stream_Text, 0 , Text_Duration, Duration_ms);
239234 Fill (Stream_Text, 0 , Text_Duration_Start_Command, Time_Begin_ms);
240235 Fill (Stream_Text, 0 , Text_Duration_Start, Time_Begin_ms);
241236 Fill (Stream_Text, 0 , Text_Duration_End, Time_End_ms);
242237 Fill (Stream_Text, 0 , Text_Duration_End_Command, Time_End_ms);
238+ if (!Time_Begin.IsTimed ())
239+ Fill (Stream_Text, 0 , Text_TimeCode_FirstFrame, Time_Begin.ToString ());
240+ if (!Time_End.IsTimed () && Time_End > Time_Begin)
241+ Fill (Stream_Text, 0 , Text_TimeCode_LastFrame, (Time_End - 1 ).ToString ());
243242 }
244243 Fill (Stream_Text, 0 , Text_FrameRate_Mode, " CFR" );
245244 Fill (Stream_Text, 0 , Text_Events_Total, FrameCount-EmptyCount);
0 commit comments