Home > APIs > AppServer API > Examples > Asset Management > Merging, Replacing, or Adding Ancillary Data
Merging, Replacing, or Adding Ancillary Data
Available in K2 3.2.74 software:
The code below shows how you can take an external data file (*.N0) and:
1) merge all of it to a clip
2) merge part of it to a clip
3) replace a clip's ancillary data track with it, or
4) add it to a clip that does not have an ancillary track
Copy the code below to your application, then uncomment the example section you want to try each different type of merge or replace operation. Also, see the C# Script Samples page for a full sample script that you can download and test.
C# // create a media mgr using ( IMediaMgr mediaMgr = connection.AppServer.CreateMediaMgr(appName) ) { // define clip to modify string volume = "V:"; string bin = "default"; string clipname = "Clip"; string dataFile = "C:\\temp\\anc_data.N0"; string clipURI = String.Format("edl/cmf//{0}/{1}/{2}/{3}", host, volume, bin, clipname); // get an editor for clip using ( ISimpleEditor editor = (ISimpleEditor) mediaMgr.CreateEditor(clipURI) ) { try { // cast it to a track editor ITrackEditor2 trackEditor = (ITrackEditor2) editor; ///////////////////////////////////////////////////// // Example 1: Merge the ENTIRE datafile into the clip ///////////////////////////////////////////////////// // srcFieldIn = -1 == start of file // srcFieldOut = -1 == end of file, // destFieldPos = 0 == field 0 in destination. note: you can use a timecode string too (i.e. "00:00:00.00") // merge = 1 == merge, rather than replace string ancFileName = trackEditor.MergeAncData (dataFile, -1, -1, 0, 1); // commit the change trackEditor.CommitAncData(); /* ////////////////////////////////////////////////////////////////// // Example 2: Merge PART of the datafile (first 300 fields) into the clip ////////////////////////////////////////////////////////////////// // srcFieldIn = 0 == field 0 // srcFieldOut = 300 == up to field 300 // destFieldPos = 0 == field 0 in destination. note: you can use a timecode string too (i.e. "00:00:00.00") // merge = 1 == merge, rather than replace string ancFileName = trackEditor.MergeAncData (dataFile, 0, 300, 0, 1); // commit the change trackEditor.CommitAncData(); */ /* ////////////////////////////////////////////////////////////////// // Example 3: Replace or Add the clip's ancillary data track ////////////////////////////////////////////////////////////////// // srcFieldIn = -1 == start of file // srcFieldOut = -1 == end of file, // destFieldPos = 0 == field 0 in destination. note: you can use a timecode string too (i.e. "00:00:00.00") // merge = 0 == replace, rather than merge // Note: if replacing or adding (i.e. the original clip does not have an ancillary data track) rather than // merging then you first need to copy the local data file over to the K2 Client's V: drive. To do this, you // should copy the local file to a location and name on the K2 Client's V: drive that looks like // "V:\PDR\\\ .N0". Then you can use that file with the TrackEditor's MergeAncData // call to replace the ancillary data track. // first generate unique guid name & path string newDataFile = String.Format("V:\\PDR\\{0}\\{1}.N0", bin, System.Guid.NewGuid().ToString("N")); // if the newDataFile does not exists if ( File.Exists(newDataFile) ) { Console.WriteLine("ERROR: Cannot copy '{0}' to '{1}'. File '{1}' already exists.", dataFile, newDataFile); return -1; } // copy local data file to V: drive File.Copy( dataFile, newDataFile ); // replace the clip's anc data track trackEditor.MergeAncData (newDataFile, -1, -1, 0, 0); // commit the change trackEditor.CommitAncData(); string ancFileName = newDataFile; */ // output new ancillary file info Console.WriteLine("The new ancillary filename is located at '{0}'", ancFileName); } catch (Exception e) { Console.WriteLine(e); } finally { // Very Important: make sure that you detach the editor when you're done. If not, you will // have references to the movie hanging around. This will cause you trouble later when you // try to delete or move the clip, but can't because of outstanding references to the clip. editor.Detach(); } } // when using block goes out of scope the simpleeditor is disposed } // when using block goes out of scope the mediamgr is disposed