Skip to content

Commit

Permalink
add negative offset support for layer
Browse files Browse the repository at this point in the history
  • Loading branch information
delthas committed Apr 15, 2018
1 parent 845e25b commit 728ac6c
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Datamosh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.1.0
// Version: 1.1.1
//

using System;
Expand Down Expand Up @@ -202,7 +202,7 @@ public class EntryPoint {
};
var textLabel = new Label {Left = 10, Top = 10, Text = "Frame count"};
var inputBox =
new NumericUpDown {Left = 200, Top = 10, Width = 200, Value = defaultCount, Minimum = 1, Maximum = 1000000000};
new NumericUpDown {Left = 200, Top = 10, Width = 200, Minimum = 1, Maximum = 1000000000, Value = defaultCount};
var textLabel2 = new Label {Left = 10, Top = 40, Text = "Frames repeats"};
var inputBox2 = new NumericUpDown {
Left = 200,
Expand Down
1 change: 1 addition & 0 deletions Datamosh.cs.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<AssemblyReference>Microsoft.WindowsAPICodePack.Shell.dll</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAPICodePack.dll</AssemblyReference>
<CompilerOptions>-debug -D:DEBUG</CompilerOptions>
<IconFile>Datamosh.png</IconFile>
</ScriptSettings>
6 changes: 3 additions & 3 deletions Datamosh14.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.1.0
// Version: 1.1.1
//

using System;
Expand All @@ -16,7 +16,7 @@
using System.Windows.Forms;
using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;
using ScriptPortal.Vegas;
using Sony.Vegas;

namespace VegasDatamosh {
public class EntryPoint {
Expand Down Expand Up @@ -202,7 +202,7 @@ public class EntryPoint {
};
var textLabel = new Label {Left = 10, Top = 10, Text = "Frame count"};
var inputBox =
new NumericUpDown {Left = 200, Top = 10, Width = 200, Value = defaultCount, Minimum = 1, Maximum = 1000000000};
new NumericUpDown {Left = 200, Top = 10, Width = 200, Minimum = 1, Maximum = 1000000000, Value = defaultCount};
var textLabel2 = new Label {Left = 10, Top = 40, Text = "Frames repeats"};
var inputBox2 = new NumericUpDown {
Left = 200,
Expand Down
1 change: 1 addition & 0 deletions Datamosh14.cs.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<AssemblyReference>Microsoft.WindowsAPICodePack.Shell.dll</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAPICodePack.dll</AssemblyReference>
<CompilerOptions>-debug -D:DEBUG</CompilerOptions>
<IconFile>Datamosh.png</IconFile>
</ScriptSettings>
31 changes: 19 additions & 12 deletions Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.1.0
// Version: 1.1.1
//

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;
using Sony.Vegas;
Expand Down Expand Up @@ -197,13 +198,13 @@ public class EntryPoint {
Left = 200,
Top = 10,
Width = 200,
Value = defaultCount,
Minimum = 1,
Maximum = 1000000000
Maximum = 1000000000,
Value = defaultCount
};
var textLabel2 = new Label {Left = 10, Top = 40, Text = "Layering offset"};
var inputBox2 =
new NumericUpDown {Left = 200, Top = 40, Width = 200, Minimum = 1, Text = "", Maximum = 1000000000};
new NumericUpDown {Left = 200, Top = 40, Width = 200, Minimum = -1000000000, Maximum = 1000000000, Text = ""};
var textLabel3 = new Label {Left = 10, Top = 70, Text = "Render"};
var inputBox3 = new CheckBox {
Left = 200,
Expand Down Expand Up @@ -234,8 +235,8 @@ public class EntryPoint {
var offset = (int) inputBox2.Value;
var render = inputBox3.Checked;

if (offset <= 0) {
MessageBox.Show("Layering offset must be > 0!");
if (offset == 0) {
MessageBox.Show("Layering offset must not be 0!");
return;
}

Expand All @@ -258,17 +259,23 @@ public class EntryPoint {
var newTracks = new List<VideoTrack>();
var newEvents = new List<VideoEvent>();
var current = 0;
var baseOffset = offset > 0 ? 0 : -count * offset;

for (var i = videoTrackIndex - 1; i >= 0 && current < count; i--) {
var videoTrack = vegas.Project.Tracks[i] as VideoTrack;
if (videoTrack == null) continue;
newEvents.Add((VideoEvent) videoEvent.Copy(videoTrack, Timecode.FromFrames(videoEvent.Start.FrameCount + (++current) * offset)));
newEvents.Add((VideoEvent) videoEvent.Copy(videoTrack, Timecode.FromFrames(videoEvent.Start.FrameCount + baseOffset + (++current) * offset)));
}

for (; current < count;) {
var videoTrack = vegas.Project.AddVideoTrack();
newTracks.Add(videoTrack);
newEvents.Add((VideoEvent) videoEvent.Copy(videoTrack, Timecode.FromFrames(videoEvent.Start.FrameCount + (++current) * offset)));
newEvents.Add((VideoEvent) videoEvent.Copy(videoTrack, Timecode.FromFrames(videoEvent.Start.FrameCount + baseOffset + (++current) * offset)));
}

var start = videoEvent.Start;
if (offset < 0) {
videoEvent.Start = Timecode.FromFrames(videoEvent.Start.FrameCount + baseOffset);
}

if (!render) return;
Expand Down Expand Up @@ -313,8 +320,8 @@ public class EntryPoint {

var renderArgs = new RenderArgs {
OutputFile = path,
Start = Timecode.FromFrames(videoEvent.Start.FrameCount),
Length = Timecode.FromFrames(videoEvent.Length.FrameCount + count * offset),
Start = Timecode.FromFrames(start.FrameCount),
Length = Timecode.FromFrames(videoEvent.Length.FrameCount + count * Math.Abs(offset)),
RenderTemplate = template
};
var status = vegas.Render(renderArgs);
Expand All @@ -326,8 +333,8 @@ public class EntryPoint {
File.Delete(pathEncoded + ".sfl");

var media = vegas.Project.MediaPool.AddMedia(path);
var newVideoEvent = videoTrackStart.AddVideoEvent(videoEvent.Start,
Timecode.FromFrames(videoEvent.Length.FrameCount + count * offset));
var newVideoEvent = videoTrackStart.AddVideoEvent(start,
Timecode.FromFrames(videoEvent.Length.FrameCount + count * Math.Abs(offset)));
((VideoStream) newVideoEvent.AddTake(media.GetVideoStreamByIndex(0)).MediaStream).AlphaChannel =
VideoAlphaType.Straight;
videoEvent.Track.Events.Remove(videoEvent);
Expand Down
1 change: 1 addition & 0 deletions Layer.cs.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<AssemblyReference>Microsoft.WindowsAPICodePack.Shell.dll</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAPICodePack.dll</AssemblyReference>
<CompilerOptions>-debug -D:DEBUG</CompilerOptions>
<IconFile>Layer.png</IconFile>
</ScriptSettings>
33 changes: 20 additions & 13 deletions Layer14.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.1.0
// Version: 1.1.1
//

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;
using ScriptPortal.Vegas;
using Sony.Vegas;

namespace VegasLayering {
public class EntryPoint {
Expand Down Expand Up @@ -197,13 +198,13 @@ public class EntryPoint {
Left = 200,
Top = 10,
Width = 200,
Value = defaultCount,
Minimum = 1,
Maximum = 1000000000
Maximum = 1000000000,
Value = defaultCount
};
var textLabel2 = new Label {Left = 10, Top = 40, Text = "Layering offset"};
var inputBox2 =
new NumericUpDown {Left = 200, Top = 40, Width = 200, Minimum = 1, Text = "", Maximum = 1000000000};
new NumericUpDown {Left = 200, Top = 40, Width = 200, Minimum = -1000000000, Maximum = 1000000000, Text = ""};
var textLabel3 = new Label {Left = 10, Top = 70, Text = "Render"};
var inputBox3 = new CheckBox {
Left = 200,
Expand Down Expand Up @@ -234,8 +235,8 @@ public class EntryPoint {
var offset = (int) inputBox2.Value;
var render = inputBox3.Checked;

if (offset <= 0) {
MessageBox.Show("Layering offset must be > 0!");
if (offset == 0) {
MessageBox.Show("Layering offset must not be 0!");
return;
}

Expand All @@ -258,17 +259,23 @@ public class EntryPoint {
var newTracks = new List<VideoTrack>();
var newEvents = new List<VideoEvent>();
var current = 0;
var baseOffset = offset > 0 ? 0 : -count * offset;

for (var i = videoTrackIndex - 1; i >= 0 && current < count; i--) {
var videoTrack = vegas.Project.Tracks[i] as VideoTrack;
if (videoTrack == null) continue;
newEvents.Add((VideoEvent) videoEvent.Copy(videoTrack, Timecode.FromFrames(videoEvent.Start.FrameCount + (++current) * offset)));
newEvents.Add((VideoEvent) videoEvent.Copy(videoTrack, Timecode.FromFrames(videoEvent.Start.FrameCount + baseOffset + (++current) * offset)));
}

for (; current < count;) {
var videoTrack = vegas.Project.AddVideoTrack();
newTracks.Add(videoTrack);
newEvents.Add((VideoEvent) videoEvent.Copy(videoTrack, Timecode.FromFrames(videoEvent.Start.FrameCount + (++current) * offset)));
newEvents.Add((VideoEvent) videoEvent.Copy(videoTrack, Timecode.FromFrames(videoEvent.Start.FrameCount + baseOffset + (++current) * offset)));
}

var start = videoEvent.Start;
if (offset < 0) {
videoEvent.Start = Timecode.FromFrames(videoEvent.Start.FrameCount + baseOffset);
}

if (!render) return;
Expand Down Expand Up @@ -313,8 +320,8 @@ public class EntryPoint {

var renderArgs = new RenderArgs {
OutputFile = path,
Start = Timecode.FromFrames(videoEvent.Start.FrameCount),
Length = Timecode.FromFrames(videoEvent.Length.FrameCount + count * offset),
Start = Timecode.FromFrames(start.FrameCount),
Length = Timecode.FromFrames(videoEvent.Length.FrameCount + count * Math.Abs(offset)),
RenderTemplate = template
};
var status = vegas.Render(renderArgs);
Expand All @@ -326,8 +333,8 @@ public class EntryPoint {
File.Delete(pathEncoded + ".sfl");

var media = vegas.Project.MediaPool.AddMedia(path);
var newVideoEvent = videoTrackStart.AddVideoEvent(videoEvent.Start,
Timecode.FromFrames(videoEvent.Length.FrameCount + count * offset));
var newVideoEvent = videoTrackStart.AddVideoEvent(start,
Timecode.FromFrames(videoEvent.Length.FrameCount + count * Math.Abs(offset)));
((VideoStream) newVideoEvent.AddTake(media.GetVideoStreamByIndex(0)).MediaStream).AlphaChannel =
VideoAlphaType.Straight;
videoEvent.Track.Events.Remove(videoEvent);
Expand Down
1 change: 1 addition & 0 deletions Layer14.cs.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<AssemblyReference>Microsoft.WindowsAPICodePack.Shell.dll</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAPICodePack.dll</AssemblyReference>
<CompilerOptions>-debug -D:DEBUG</CompilerOptions>
<IconFile>Layer.png</IconFile>
</ScriptSettings>
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ This does multilayering, by copying the select video clip/event N times, each ti

To use, select a single video clip/event, then it will be multilayered automatically, and rendered transparently if specified.

*You can use a negative offset (eg -2 instead of 2), in which case the newest clips/events will be added at the back, instead of the front of the previous events.*

**If you choose to render automatically, the rendered file will support alpha/transparency, meaning you don't need to add a green screen and remove it after, the alpha is handled automatically.**

### Render
Expand Down
2 changes: 1 addition & 1 deletion Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.1.0
// Version: 1.1.1
//

using System;
Expand Down
1 change: 1 addition & 0 deletions Render.cs.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<AssemblyReference>Microsoft.WindowsAPICodePack.Shell.dll</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAPICodePack.dll</AssemblyReference>
<CompilerOptions>-debug -D:DEBUG</CompilerOptions>
<IconFile>Render.png</IconFile>
</ScriptSettings>
4 changes: 2 additions & 2 deletions Render14.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License: MIT
// Source: https://github.com/delthas/vegas-datamosh
// Documentation: https://github.com/delthas/vegas-datamosh
// Version: 1.1.0
// Version: 1.1.1
//

using System;
Expand All @@ -16,7 +16,7 @@
using System.Windows.Forms;
using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;
using ScriptPortal.Vegas;
using Sony.Vegas;

namespace VegasRender {
public class EntryPoint {
Expand Down
1 change: 1 addition & 0 deletions Render14.cs.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<AssemblyReference>Microsoft.WindowsAPICodePack.Shell.dll</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAPICodePack.dll</AssemblyReference>
<CompilerOptions>-debug -D:DEBUG</CompilerOptions>
<IconFile>Render.png</IconFile>
</ScriptSettings>

0 comments on commit 728ac6c

Please sign in to comment.