@@ -163,6 +163,44 @@ size_t AudioProperties::getNbSamples() const
163
163
return _formatContext->streams [_streamId]->nb_frames ;
164
164
}
165
165
166
+ size_t AudioProperties::getTicksPerFrame () const
167
+ {
168
+ if ( ! _codecContext )
169
+ throw std::runtime_error ( " unknown codec context" );
170
+ return _codecContext->ticks_per_frame ;
171
+ }
172
+
173
+ Rational AudioProperties::getTimeBase () const
174
+ {
175
+ if ( ! _codecContext )
176
+ throw std::runtime_error ( " unknown codec context" );
177
+
178
+ Rational timeBase = {
179
+ _formatContext->streams [_streamId]->time_base .num ,
180
+ _formatContext->streams [_streamId]->time_base .den ,
181
+ };
182
+ return timeBase;
183
+ }
184
+
185
+ double AudioProperties::getFps () const
186
+ {
187
+ Rational timeBase = getTimeBase ();
188
+ double fps = 1.0 * timeBase.den / ( timeBase.num * getTicksPerFrame () );
189
+ if ( isinf ( fps ) )
190
+ fps = 0.0 ;
191
+ return fps;
192
+ }
193
+
194
+ double AudioProperties::getDuration () const
195
+ {
196
+ if ( ! _formatContext )
197
+ throw std::runtime_error ( " unknown format context" );
198
+
199
+ Rational timeBase = getTimeBase ();
200
+ double duration = ( timeBase.num / (double ) timeBase.den ) * _formatContext->streams [_streamId]->duration ;
201
+ return duration;
202
+ }
203
+
166
204
PropertiesMap AudioProperties::getPropertiesAsMap () const
167
205
{
168
206
PropertiesMap dataMap;
@@ -180,6 +218,10 @@ PropertiesMap AudioProperties::getPropertiesAsMap() const
180
218
detail::add ( dataMap, " channelLayout" , getChannelLayout () );
181
219
detail::add ( dataMap, " channelName" , getChannelName () );
182
220
detail::add ( dataMap, " channelDescription" , getChannelDescription () );
221
+ detail::add ( dataMap, " ticksPerFrame" , getTicksPerFrame () );
222
+ detail::add ( dataMap, " timeBase" , getTimeBase () );
223
+ detail::add ( dataMap, " fps" , getFps () );
224
+ detail::add ( dataMap, " duration" , getDuration () );
183
225
184
226
for ( size_t metadataIndex = 0 ; metadataIndex < _metadatas.size (); ++metadataIndex )
185
227
{
0 commit comments