1

I was trying to find the duration of video files. I was able to get the length for .mov, .mp4, etc. using the shellconcept metioned below.

C# Get video file duration from metadata

I am not getting the duration of mxf files, is it possible to calculate it in C#?

Community
  • 1
  • 1
nks
  • 115
  • 1
  • 10
  • The duration of a stream in a container file can be complex to attain, it depends on if the container was written in a 'indexed' form or not. The information can be represented many ways in a mxf file and sometimes redundantly. The timeline track or timecode components should indicate edit rate and container duration from which you can then calculate duration. If you need File and Track Level Details for Material Exchange, Base Media Files, Advanced Systems Format / Windows Media, Resource Interchange and Matroska containers you can check out https://net7mma.codeplex.com. – Jay Oct 14 '14 at 16:42

2 Answers2

1

I found another easy way to find the mxf file duration..

DownLoad the MediaInfo.dll from the web and put it in your "C:\Windows" folder and include the mediainfoDll.cs in your project.

By using the below code,you will be able to get the duration of .mxf file

MediaInfo aMediaInfoL = new MediaInfo();
aMediaInfoL.Open("C:\Users\\Desktop\\drop\mxf\xdcam-pal-dv25.mxf");
aMediaInfoL.Option("Inform", "General;%Duration%");
string durationL = aMediaInfoL.Inform();
aMediaInfoL.Close();
string  durationminutesL
  = TimeSpan.FromMilliseconds(Convert.ToDouble(durationL)).TotalMinutes;
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
nks
  • 115
  • 1
  • 10
0

if we open the mxf file in binary editor we can see the Duration exist in the xml header..like below

Duration value="89"

In code you can read it by opening the file

FileStream streamL =
 File.Open("C:\\temp\\test.mxf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) 

Then read the bytes in a loop until you find the Duration

int nBytesReadL = streamP.Read(HeaderBufferL, 0, BufferLengthL);
string zTextRepresentationL = 
   System.Text.ASCIIEncoding.Default.GetString(HeaderBufferL, 0, nBytesReadL);

from the above string xml you can get the duration

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
nks
  • 115
  • 1
  • 10
  • Mxf is not xml, furthermore the encoding your specifying is wrong, its BigEndianUnicode. – Jay Oct 14 '14 at 15:41