freeMXF.org
http://freemxf.org/forum/

faster way to extract duration from a track using mxflib?
http://freemxf.org/forum/viewtopic.php?f=2&t=88
Page 1 of 1

Author:  Thomi [ Tue Jul 31, 2007 1:02 pm ]
Post subject:  faster way to extract duration from a track using mxflib?

Hi There,

I'm working on some code that needs to extract the duration from the first track (or indeed, any track) in an MXF file. I'm new to mxflib, and new to the mxf format as well, and I'm hoping that there's a faster / more efficient way to do this.

So far, I have:

Code:
   // open file:
   MXFFilePtr file = new MXFFile;
   if (! file->Open(strFileName, true))
   {
      return -1;   // cannot open file - doesn't exist?
   }

   // get the Random Index Pack (RIP):
   file->GetRIP();

   // iterate through all partitions:
   RIP::iterator it = file->FileRIP.begin();
   while (it != file->FileRIP.end())
   {
      // seek to the partition position in the file:
      file->Seek((*it).second->ByteOffset);
      PartitionPtr ThisPartition = file->ReadPartition();
      if (ThisPartition)
      {
         if (ThisPartition->ReadMetadata() != 0)
         {
            for (MDObjectList::iterator it2 = ThisPartition->AllMetadata.begin();
               it2 != ThisPartition->AllMetadata.end(); it2++)
            {
               if ((*it2)->Name() == "Sequence")
               {
                  Length duration = (*it2)->GetInt64("Duration");
                  return duration;
               }   // are we looking at a sequence node?
               it2++;
            }  // loop through meta data objects
            
         }   // if ReadMetadata() != 0
      }   // scan through RIP
      it++;
   }
   return -1;



Can anyone offer some advice on this?

Cheers,

Author:  Matt Beard [ Tue Jul 31, 2007 3:56 pm ]
Post subject:  Re: faster way to extract duration from a track using mxflib

Thomi wrote:
Hi There,

I'm working on some code that needs to extract the duration from the first track (or indeed, any track) in an MXF file. I'm new to mxflib, and new to the mxf format as well, and I'm hoping that there's a faster / more efficient way to do this.


Try:

Code:
   // open file:
   MXFFilePtr file = new MXFFile;
   if (! file->Open(strFileName, true))
   {
      return -1;   // cannot open file - doesn't exist?
   }

   // get the Random Index Pack (RIP):
   file->GetRIP();

   // Read the master partition:
   PartitionPtr MasterPartition = file->ReadMasterPartition();
   if(!MasterPartition)
   {
      return -1;   // Can't locate or read the master partition
   }

   // Parse the metadata into "high level" objects
   MetadataPtr HMeta = MasterPartition->ParseMetadata();

   // Locate the primary package
   PackagePtr PrimaryPackage = HMeta[PrimaryPackage_UL];

   // Follow the weak reference
   if(PrimaryPackage) PrimaryPackage = PrimaryPackage->GetLink();
   else
   {
      // TODO: Scan for a material package
   }

   // Locate the first track in that package
   // TODO: You may want to pick a particular track
   TrackPtr ThisTrack = PrimaryPackage->Tracks.front();

   // We use a trick to get the duration of the entire track
   // We recalculate all sub-lengths and receive the total
   Length TrackDuration = ThisTrack->UpdateDuration();

   return TrackDuration;


I need to add a GetDuration() call to Track, but UpdateDuration is pretty quick.

Author:  Thomi [ Tue Jul 31, 2007 7:45 pm ]
Post subject:  Re: faster way to extract duration from a track using mxflib

Matt Beard wrote:

Try:

Code:
   ...

   // Locate the primary package
   PackagePtr PrimaryPackage = HMeta[PrimaryPackage_UL];

   // Follow the weak reference
   if(PrimaryPackage) PrimaryPackage = PrimaryPackage->GetLink();
   else
   {
      // TODO: Scan for a material package
   }


I need to add a GetDuration() call to Track, but UpdateDuration is pretty quick.


Thanks for that..

I'm not sure what you mean about scanning for a material package. Sorry if this is elementary stuff, as I said, I'm new to MXF. I Assume that an MXF file can contain multiple different packages, and you're suggesting that I probably only want the duration from a track inside a material package, correct?

Other than that, I'd like to congratulate you on a very impressive piece of work, even if I don't fully understand how to use it yet!


Thanks,

Author:  Matt Beard [ Tue Aug 07, 2007 1:17 pm ]
Post subject: 

You need something like:
Code:
// Locate first Material Package
PackageList::iterator it = HMeta->Packages.begin();
while(it != HMeta.Packages.end())
{
   if((*it)->IsA(MaterialPackage_UL))
   {
      PrimaryPackage = *it;
      break;
   }
   it++;
}

Author:  Thomi [ Wed Oct 03, 2007 9:37 am ]
Post subject: 

I'd like to revice this post for another question...


I have found an additional requirement - I need to be able to extract the duration from a track while the mxf file is still being written (It's being downloaded while I'm acanning for a duration). THis means that i can't use the ReadRIP() method, since the RIP hasn't been written to disk yet.


Seems to me that you can't read anything from the file until you read the RIP - is that the case? Am I able to seek to some constant point in the file and read the first partition / track from there?


Cheers,

Author:  alexxx [ Wed Dec 12, 2007 12:37 pm ]
Post subject: 

Hi Matt, Thomi.

I also want to get the duration of the video, because the metadata value for "Duration" is "unknown".

I tried your code (from this page here), but got a compilation error.

Thomi, did you get this code work?
Or Matt, could you please give me further advice.
(I'm also a very newbie to mxf, sorry)

These are my errors:

mxfsplit.cpp: In function `int main_process(int, char**)':
mxfsplit.cpp:347: error: conversion from `mxflib::MDObjectPtr' to non-scalar
type `mxflib::PackagePtr' requested
mxfsplit.cpp:350: error: no match for 'operator=' in 'PrimaryPackage =
mxflib::ObjectInterface::GetLink() const()'
../mxflib/metadata.h:68: error: candidates are: mxflib::PackagePtr&
mxflib::PackagePtr::operator=(const mxflib::PackagePtr&)
mxfsplit.cpp:356: error: 'class mxflib::MetadataPtr' has no member named '
Packages'

Author:  Thomi [ Thu Jan 17, 2008 3:56 pm ]
Post subject: 

Yeah - the original code works fine, but I still can't work out how to do my second thing - get the duration from a file that's only been partially copied.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/