简体   繁体   中英

how to get the duration from a mp4 media file by C#

As I know a mp4 media file size, how could i calculate the file duration through file size? (C#)

Thanks.

You may look at ID3 Metadata Tags in the file. You should use TagLib Sharp for read ID3 tags from mp3/mp4 files.

I use the NReco.VideoInfo library to achieve this very easily. It's a simple as giving the library a file path and it spits out the metadata:

var ffProbe = new FFProbe();
var videoInfo = ffProbe.GetMediaInfo(blob.Uri.AbsoluteUri);
return videoInfo.Duration.TotalMilliseconds;

Reading this: https://web.archive.org/web/20121130070329/http://neuron2.net/LVG/ratesandsizes.html I think perhaps you can approximately solve the number of seconds from the equation presented in the section Calculating the File Size of a Bitrate-Based Format using the metadata from the file.

Edit: URL changed as a suggestion by @BrentRittenhouse.

使用ffmpeg命令行并让它报告您的文件属性。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM