-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncodeAssetWithCustomPreset.cs
More file actions
120 lines (105 loc) · 4.97 KB
/
EncodeAssetWithCustomPreset.cs
File metadata and controls
120 lines (105 loc) · 4.97 KB
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
namespace ProcessMyMedia.Samples
{
using System;
using System.Linq;
using System.IO;
using Microsoft.Extensions.Configuration;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using ProcessMyMedia.Model;
public class EncodeAssetWithCustomPreset : WofkflowSampleBase<EncodeAssetWithCustomPreset.EncodeAssetWithCustomPresetWorkflow, EncodeAssetWithCustomPreset.EncodeAssetWithCustomPresetWorkflowData>
{
public EncodeAssetWithCustomPreset(IConfigurationRoot configuration) : base(configuration)
{
}
protected override EncodeAssetWithCustomPresetWorkflowData WorflowDatas => new EncodeAssetWithCustomPresetWorkflowData()
{
InputAssetName = Guid.NewGuid().ToString(),
IntputFilePath = Path.Combine(Directory.GetCurrentDirectory(), @"Assets\Asset2\ignite.mp4"),
DirectoryToDownload = Path.Combine(Directory.GetCurrentDirectory(), "output/", Guid.NewGuid().ToString()),
EncodingOutput = new CustomPresetEncodingOutput()
{
PresetName = "EncodeAssetWithCustomPreset",
Codecs =
{
new H264VideoCodec()
{
FilenamePattern = "Video-{Basename}-{Label}-{Bitrate}{Extension}",
KeyFrameInterval = "00:00:02",
SceneChangeDetection = false,
Layers =
{
new H264VideoLayer()
{
Label = "SD",
Bitrate = 600000,
Height = "640",
Width = "360"
},
new H264VideoLayer()
{
Label = "HD",
Bitrate = 1000000,
Height = "1280",
Width = "720"
},
}
},
new AacAudioCodec()
{
Bitrate = 128000,
Channels = 2,
Profile = "AACLC",
SamplingRate = 48000
}
},
ThumbnailsOptions = new ThumbnailsOptions()
{
FilenamePattern = "Thumbnail-{Basename}-{Index}{Extension}",
GeneratePng = true,
GenerateJpg = true,
Height = "50%",
Width = "50%",
Start = "10%",
Step = "10%",
Range = "90%"
}
}
};
public class EncodeAssetWithCustomPresetWorkflow : IWorkflow<EncodeAssetWithCustomPresetWorkflowData>
{
public string Id => SampleBase.WORKFLOW_NAME;
public int Version => 1;
public void Build(IWorkflowBuilder<EncodeAssetWithCustomPresetWorkflowData> builder)
{
builder
.UseDefaultErrorBehavior(WorkflowErrorHandling.Terminate)
.StartWith(context => ExecutionResult.Next())
.Saga(saga => saga
.StartWith<Tasks.IngestFileTask>()
.Input(task => task.AssetFilePath, data => data.IntputFilePath)
.Input(task => task.AssetName, data => data.InputAssetName)
.Then<Tasks.EncodeAssetTask>()
.Input(task => task.Priority, data => JobPriority.High)
.Input(task => task.Input, data => new JobInputEntity() { Name = data.InputAssetName })
.Input(task => task.EncodingOutput, data => data.EncodingOutput)
.Output(data => data.OutputAssetName, task => task.Output.Job.Outputs.First().Name)
.Then<Tasks.DownloadAssetTask>()
.Input(task => task.AssetName, data => data.OutputAssetName)
.Input(task => task.DirectoryToDownload, data => data.DirectoryToDownload)
.Then<Tasks.DeleteAssetTask>()
.Input(task => task.AssetName, data => data.OutputAssetName))
.CompensateWith<Tasks.DeleteAssetTask>(compensate => compensate
.Input(task => task.AssetName, data => data.InputAssetName));
}
}
public class EncodeAssetWithCustomPresetWorkflowData
{
public string InputAssetName { get; set; }
public string IntputFilePath { get; set; }
public CustomPresetEncodingOutput EncodingOutput { get; set; }
public string DirectoryToDownload { get; set; }
public string OutputAssetName { get; set; }
}
}
}