質問

私はDirectShowでメディアファイルの期間を取得しようとしています。次のコードを使用します(C#):

var seekingParser = filter as IMediaSeeking;
if (seekingParser != null)
{
   long duration;
   if (seekingParser.SetTimeFormat(TimeFormat.MediaTime) == 0
       && seekingParser.GetDuration(out duration) == 0)
       track.Duration = duration / 10000000f;
}
.

メディアファイルの期間を秒単位で取得する。ただし、3~4分のMP3ファイルを開こうとすると、track.durationは11~12分になります。私は複数のファイルを試してみて効果が常に同じです。理由が何であるか?

役に立ちましたか?

解決

You normally use IMediaPosition interface (instead of IMediaSeeking) from the application side. Duration is reported always in seconds. However this is unlikely to make a difference, and what might make it is reading duration from ID3 tags instead, using Windows Media API, ID3 Tag Support.

Are there more reliable ways to get exact duration of media file with DirectShow API?

Windows Media Player plays MP3 files through Media Foundation, a non-DirectShow API, so you don't have an option here to expect or do exactly the same from DirectShow.

他のヒント

From the documentation:

Depending on the source format, the duration might not be exact. For example, if the source contains a variable bit-rate (VBR) stream, the method might return an estimated duration.

Are you using a VBR stream, by any chance?

You can try the same on a clean windows installation. It might be possible you have a codec(pack) installed which is buggy.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top