4

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

Thanks.

hui
  • 243
  • 1
  • 8
  • 15
  • 1
    Are you using [LAME](http://lame.sourceforge.net/) or which library you're implementing to work with the media file? – Nano Taboada Oct 14 '11 at 13:41
  • Depends on things such as the quality of the mp4 and how it is encoded – Rubber Duck Oct 14 '11 at 13:45
  • 1
    you have to know some media metadata look here: http://stackoverflow.com/questions/9091/accessing-audio-video-metadata-with-net – fixagon Oct 14 '11 at 13:51
  • possible duplicate of [Getting MP4 File Duration with DirectShow](http://stackoverflow.com/questions/11346136/getting-mp4-file-duration-with-directshow) – Roman R. Aug 09 '12 at 22:22

4 Answers4

0

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

Gustavo Gondim
  • 1,635
  • 2
  • 18
  • 39
0

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;
James Mundy
  • 4,180
  • 6
  • 35
  • 58
0

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.

Diego
  • 1,531
  • 1
  • 15
  • 27
  • 1
    Hey Diego, that url no longer works. I don't know if editing your answer will make it look like _I_ did so I'm replying so you don't lose credit =) Here is an archive.org version of it that I found that looks lke the latest version that is the most complete. http://web.archive.org/web/20121130070329/http://neuron2.net/LVG/ratesandsizes.html – Brent Rittenhouse Feb 05 '19 at 11:24
0

Use ffmpeg command line and have it report your file properties.

Daniel Mošmondor
  • 19,718
  • 12
  • 58
  • 99