bool ProcessPlay(PlaylistPlayElement element)
{
Time lastTS;
TimelineEvent play;
MediaFile file;
IEnumerable<FrameDrawing> drawings;
int cameraIndex;
Area roi;
play = element.Play;
Log.Debug (String.Format ("Adding segment {0}", element));
lastTS = play.Start;
if (element.CamerasConfig.Count == 0) {
cameraIndex = 0;
roi = new Area ();
} else {
cameraIndex = element.CamerasConfig [0].Index;
roi = element.CamerasConfig [0].RegionOfInterest;
}
if (cameraIndex >= element.FileSet.Count) {
Log.Error (string.Format ("Camera index={0} not matching for current fileset count={1}",
cameraIndex, element.FileSet.Count));
file = element.FileSet [0];
} else {
file = element.FileSet [cameraIndex];
}
drawings = play.Drawings.Where (d => d.CameraConfig.Index == cameraIndex);
if (file == null || drawings == null) {
return false;
}
if (!file.Exists ()) {
return false;
}
foreach (FrameDrawing fd in drawings) {
if (fd.Render < play.Start || fd.Render > play.Stop) {
Log.Warning ("Drawing is not in the segments boundaries " +
fd.Render.ToMSecondsString ());
continue;
}
string image_path = CreateStillImage (file.FilePath, fd);
if (image_path == null) {
continue;
}
videoEditor.AddSegment (file.FilePath, lastTS.MSeconds,
fd.Render.MSeconds - lastTS.MSeconds,
element.Rate, play.Name, file.HasAudio, roi);
// Drawings have already been cropped to ROI by the canvas, we pass an empty area
videoEditor.AddImageSegment (image_path, 0, fd.Pause.MSeconds, play.Name, new Area ());
lastTS = fd.Render;
}
videoEditor.AddSegment (file.FilePath, lastTS.MSeconds,
play.Stop.MSeconds - lastTS.MSeconds,
element.Rate, play.Name, file.HasAudio, roi);
return true;
}