@@ -32,9 +32,9 @@ public static void SetConfiguration(OnnxStackConfig configuration)
32
32
/// <param name="onnxVideo">The onnx video.</param>
33
33
/// <param name="filename">The filename.</param>
34
34
/// <param name="cancellationToken">The cancellation token.</param>
35
- public static async Task WriteVideoFramesAsync ( OnnxVideo onnxVideo , string filename , CancellationToken cancellationToken = default )
35
+ public static async Task WriteVideoFramesAsync ( OnnxVideo onnxVideo , string filename , bool preserveTransparency = false , CancellationToken cancellationToken = default )
36
36
{
37
- await WriteVideoFramesAsync ( onnxVideo . Frames , filename , onnxVideo . FrameRate , onnxVideo . AspectRatio , cancellationToken ) ;
37
+ await WriteVideoFramesAsync ( onnxVideo . Frames , filename , onnxVideo . FrameRate , onnxVideo . AspectRatio , preserveTransparency , cancellationToken ) ;
38
38
}
39
39
40
40
@@ -45,11 +45,11 @@ public static async Task WriteVideoFramesAsync(OnnxVideo onnxVideo, string filen
45
45
/// <param name="filename">The filename.</param>
46
46
/// <param name="frameRate">The frame rate.</param>
47
47
/// <param name="cancellationToken">The cancellation token.</param>
48
- public static async Task WriteVideoFramesAsync ( IEnumerable < OnnxImage > onnxImages , string filename , float frameRate = 15 , CancellationToken cancellationToken = default )
48
+ public static async Task WriteVideoFramesAsync ( IEnumerable < OnnxImage > onnxImages , string filename , float frameRate = 15 , bool preserveTransparency = false , CancellationToken cancellationToken = default )
49
49
{
50
50
var firstImage = onnxImages . First ( ) ;
51
51
var aspectRatio = ( double ) firstImage . Width / firstImage . Height ;
52
- await WriteVideoFramesAsync ( onnxImages , filename , frameRate , aspectRatio , cancellationToken ) ;
52
+ await WriteVideoFramesAsync ( onnxImages , filename , frameRate , aspectRatio , preserveTransparency , cancellationToken ) ;
53
53
}
54
54
55
55
@@ -61,12 +61,12 @@ public static async Task WriteVideoFramesAsync(IEnumerable<OnnxImage> onnxImages
61
61
/// <param name="frameRate">The frame rate.</param>
62
62
/// <param name="aspectRatio">The aspect ratio.</param>
63
63
/// <param name="cancellationToken">The cancellation token.</param>
64
- private static async Task WriteVideoFramesAsync ( IEnumerable < OnnxImage > onnxImages , string filename , float frameRate , double aspectRatio , CancellationToken cancellationToken = default )
64
+ private static async Task WriteVideoFramesAsync ( IEnumerable < OnnxImage > onnxImages , string filename , float frameRate , double aspectRatio , bool preserveTransparency , CancellationToken cancellationToken = default )
65
65
{
66
66
if ( File . Exists ( filename ) )
67
67
File . Delete ( filename ) ;
68
68
69
- using ( var videoWriter = CreateWriter ( filename , frameRate , aspectRatio ) )
69
+ using ( var videoWriter = CreateWriter ( filename , frameRate , aspectRatio , preserveTransparency ) )
70
70
{
71
71
// Start FFMPEG
72
72
videoWriter . Start ( ) ;
@@ -91,12 +91,12 @@ private static async Task WriteVideoFramesAsync(IEnumerable<OnnxImage> onnxImage
91
91
/// <param name="frameRate">The frame rate.</param>
92
92
/// <param name="aspectRatio">The aspect ratio.</param>
93
93
/// <param name="cancellationToken">The cancellation token.</param>
94
- public static async Task WriteVideoStreamAsync ( VideoInfo videoInfo , IAsyncEnumerable < OnnxImage > videoStream , string filename , CancellationToken cancellationToken = default )
94
+ public static async Task WriteVideoStreamAsync ( VideoInfo videoInfo , IAsyncEnumerable < OnnxImage > videoStream , string filename , bool preserveTransparency = false , CancellationToken cancellationToken = default )
95
95
{
96
96
if ( File . Exists ( filename ) )
97
97
File . Delete ( filename ) ;
98
98
99
- using ( var videoWriter = CreateWriter ( filename , videoInfo . FrameRate , videoInfo . AspectRatio ) )
99
+ using ( var videoWriter = CreateWriter ( filename , videoInfo . FrameRate , videoInfo . AspectRatio , preserveTransparency ) )
100
100
{
101
101
// Start FFMPEG
102
102
videoWriter . Start ( ) ;
@@ -323,11 +323,13 @@ private static Process CreateReader(string inputFile, float fps)
323
323
/// <param name="fps">The FPS.</param>
324
324
/// <param name="aspectRatio">The aspect ratio.</param>
325
325
/// <returns></returns>
326
- private static Process CreateWriter ( string outputFile , float fps , double aspectRatio )
326
+ private static Process CreateWriter ( string outputFile , float fps , double aspectRatio , bool preserveTransparency )
327
327
{
328
328
var ffmpegProcess = new Process ( ) ;
329
+ var codec = preserveTransparency ? "png" : "libx264" ;
330
+ var format = preserveTransparency ? "yuva420p" : "yuv420p" ;
329
331
ffmpegProcess . StartInfo . FileName = _configuration . FFmpegPath ;
330
- ffmpegProcess . StartInfo . Arguments = $ "-hide_banner -loglevel error -framerate { fps : F4} -i - -c:v libx264 -movflags +faststart -vf format=yuv420p -aspect { aspectRatio } { outputFile } ";
332
+ ffmpegProcess . StartInfo . Arguments = $ "-hide_banner -loglevel error -framerate { fps : F4} -i - -c:v { codec } -movflags +faststart -vf format={ format } -aspect { aspectRatio } { outputFile } ";
331
333
ffmpegProcess . StartInfo . RedirectStandardInput = true ;
332
334
ffmpegProcess . StartInfo . UseShellExecute = false ;
333
335
ffmpegProcess . StartInfo . CreateNoWindow = true ;
0 commit comments