Ok, thanks Sasha, my mistake was to get the 'Duration' attribute from the video stream instead of taking it from the #0 stream. I do not know why one have to read this attribute from an invalid stream index (I think stream # are 1-based).
"sasha" wrote:
[Quoted Text] > Olivier Antoine wrote: > > Hello, > > > > I have got a stupid question : I am reading wmv files using the > > IWMSyncReader interface of the WM 9 Format SDK, and I am not able to figure > > how to get the wmv file duration (in number of frames, seconds, > > 100-nanoseconds or whatever, I will perform the conversion). > > > > I saw there is an metadata attribute named 'Duration' but not all wmv files > > seem to have this attribute set. > > > > Thank you in advance, > > > > Olivier > > > > > Here is a sample code you can use: > > C_ComPtr <IWMReader> _reader; > C_ComPtr <IWMHeaderInfo> _readerHeaderInfo; > > hr = _reader->QueryInterface( IID_IWMHeaderInfo, (void > **)&_readerHeaderInfo ); > > > WMT_ATTR_DATATYPE enumType; > WORD cbLength = sizeof( duration ); > WORD stream = 0; > QWORD duration; > > HRESULT hr = _readerHeaderInfo->GetAttributeByName( &stream, > g_wszWMDuration, &enumType, > (BYTE *)&duration, &cbLength ); > if ( FAILED( hr ) ) { > LOG_ERR( _T( "Error getting reader attribures %x" ), hr ); > return eSomeError; > } > > > Good luck, > ..a >
|