freeMXF.org

Open discussion about freeMXF.org tools and MXF in general
It is currently Sun Dec 22, 2024 3:24 am
Board index » MXF Categories » freeMXF.org Tools



Post new topic Reply to topic  [ 7 posts ] 
Author
Search for:
Message

Offline
Board User

Joined: Mon Jul 30, 2007 3:50 pm
Posts: 5

Post Posted: Tue Jul 31, 2007 1:02 pm 
Top  
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,

 Profile  

Offline
Insider

Joined: Thu Apr 15, 2004 10:39 am
Posts: 198
Location: Scotland

Post Posted: Tue Jul 31, 2007 3:56 pm 
Top  
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.

 Profile WWW  

Offline
Board User

Joined: Mon Jul 30, 2007 3:50 pm
Posts: 5

Post Posted: Tue Jul 31, 2007 7:45 pm 
Top  
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,

 Profile  

Offline
Insider

Joined: Thu Apr 15, 2004 10:39 am
Posts: 198
Location: Scotland

Post Posted: Tue Aug 07, 2007 1:17 pm 
Top  
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++;
}

 Profile WWW  

Offline
Board User

Joined: Mon Jul 30, 2007 3:50 pm
Posts: 5

Post Posted: Wed Oct 03, 2007 9:37 am 
Top  
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,

 Profile  

Offline
Board User

Joined: Wed May 30, 2007 8:02 am
Posts: 11
Location: Austria

Post Posted: Wed Dec 12, 2007 12:37 pm 
Top  
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'

 Profile  

Offline
Board User

Joined: Mon Jul 30, 2007 3:50 pm
Posts: 5

Post Posted: Thu Jan 17, 2008 3:56 pm 
Top  
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.

 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

Jump to:  


Who is online

Users browsing this forum: No registered users and 7 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group :: Style based on FI Subice by phpBBservice.nl :: All times are UTC