-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPromote Media Closed Captioning.cs
123 lines (111 loc) · 4.24 KB
/
Promote Media Closed Captioning.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
This script will "promote" the CC command markers embedded in the
selected events' media to project CC command markers.
Note that more than one command marker can not exist in the same
location. When this type of failure occurs, the script records the
error, contiues promoting the remainder of the command markers,
and informs you of which ones failed upon completion.
This script is only supported by Vegas version 9.0d and above.
Last Modified: February 2010.
*/
using System;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using ScriptPortal.Vegas;
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
Project proj = vegas.Project;
foreach (Track track in proj.Tracks)
{
foreach (TrackEvent trackEvent in track.Events)
{
if (!trackEvent.Selected)
continue;
Take activeTake = trackEvent.ActiveTake;
if (null == activeTake)
continue;
Media media = activeTake.Media;
if (null == media)
continue;
if (IsPairedAudioEvent(trackEvent, media))
continue;
Timecode eventStart = trackEvent.Start;
Timecode eventEnd = eventStart + trackEvent.Length;
Timecode takeOffset = activeTake.Offset;
Timecode position;
foreach (MediaCommandMarker mcm in media.CommandMarkers)
{
position = mcm.Position + eventStart - takeOffset;
if (position < eventStart || position > eventEnd)
continue;
CommandMarker commandmarker = new CommandMarker(position, mcm.CommandType, /*param*/mcm.CommandParameter, /*comment*/mcm.Label);
try
{
proj.CommandMarkers.Add(commandmarker);
}
catch (Exception e)
{
AddError(e, mcm, position);
}
}
}
}
if (0 < myErrors.Count)
{
StringBuilder msg = new StringBuilder();
msg.Append("Some problems occured in promoting the selected media command markers to the project level:\r\n");
foreach (String err in myErrors)
{
msg.Append("\r\n");
msg.Append(err);
}
MessageBox.Show(msg.ToString());
}
}
// skip audio events that are grouped with a selected video event
// that uses the same media because they usually contain the same
// captioning data
private bool IsPairedAudioEvent(TrackEvent trackEvent, Media media)
{
if (trackEvent.IsAudio() && trackEvent.IsGrouped)
{
TrackEventGroup group = trackEvent.Group;
if (null != group)
{
foreach (TrackEvent groupedEvent in group)
{
if (groupedEvent != trackEvent)
{
if (groupedEvent.IsVideo() && groupedEvent.Selected)
{
Take take = groupedEvent.ActiveTake;
if (null != take)
{
Media groupedMedia = take.Media;
if (null != media)
{
if (groupedMedia == media)
{
return true;
}
}
}
}
}
}
}
}
return false;
}
private ArrayList myErrors = new ArrayList();
private void AddError(Exception e, CommandMarker commandmarker, Timecode position)
{
myErrors.Add(String.Format("Failed to add command marker '{0}' at {1}: {2}",
commandmarker.Label,
position.ToString(),
e.Message));
}
}