@@ -104,7 +104,10 @@ public async Task<VideoOutput> CreateVideoAsync(VideoFrames videoFrames, Cancell
104104 /// <returns></returns>
105105 public async Task < VideoOutput > CreateVideoAsync ( DenseTensor < float > videoTensor , float videoFPS , CancellationToken cancellationToken = default )
106106 {
107- var videoFrames = await videoTensor . ToVideoFramesAsBytesAsync ( ) . ToListAsync ( cancellationToken ) ;
107+ var videoFrames = await videoTensor
108+ . ToVideoFramesAsBytesAsync ( )
109+ . Select ( x => new VideoFrame ( x ) )
110+ . ToListAsync ( cancellationToken ) ;
108111 return await CreateVideoInternalAsync ( videoFrames , videoFPS , cancellationToken ) ;
109112 }
110113
@@ -118,7 +121,8 @@ public async Task<VideoOutput> CreateVideoAsync(DenseTensor<float> videoTensor,
118121 /// <returns></returns>
119122 public async Task < VideoOutput > CreateVideoAsync ( IEnumerable < byte [ ] > videoFrames , float videoFPS , CancellationToken cancellationToken = default )
120123 {
121- return await CreateVideoInternalAsync ( videoFrames , videoFPS , cancellationToken ) ;
124+ var frames = videoFrames . Select ( x => new VideoFrame ( x ) ) ;
125+ return await CreateVideoInternalAsync ( frames , videoFPS , cancellationToken ) ;
122126 }
123127
124128
@@ -190,7 +194,7 @@ public async Task<VideoFrames> CreateFramesAsync(Stream videoStream, float video
190194 /// <param name="targetFPS">The target FPS.</param>
191195 /// <param name="cancellationToken">The cancellation token.</param>
192196 /// <returns></returns>
193- public IAsyncEnumerable < byte [ ] > StreamFramesAsync ( byte [ ] videoBytes , float targetFPS , CancellationToken cancellationToken = default )
197+ public IAsyncEnumerable < VideoFrame > StreamFramesAsync ( byte [ ] videoBytes , float targetFPS , CancellationToken cancellationToken = default )
194198 {
195199 return CreateFramesInternalAsync ( videoBytes , targetFPS , cancellationToken ) ;
196200 }
@@ -220,13 +224,13 @@ private async Task<VideoInfo> GetVideoInfoInternalAsync(MemoryStream videoStream
220224 /// <param name="fps">The FPS.</param>
221225 /// <param name="cancellationToken">The cancellation token.</param>
222226 /// <returns></returns>
223- private async Task < VideoOutput > CreateVideoInternalAsync ( IEnumerable < byte [ ] > imageData , float fps = 15 , CancellationToken cancellationToken = default )
227+ private async Task < VideoOutput > CreateVideoInternalAsync ( IEnumerable < VideoFrame > imageData , float fps = 15 , CancellationToken cancellationToken = default )
224228 {
225229 string tempVideoPath = GetTempFilename ( ) ;
226230 try
227231 {
228232 // Analyze first fram to get some details
229- var frameInfo = await GetVideoInfoAsync ( imageData . First ( ) ) ;
233+ var frameInfo = await GetVideoInfoAsync ( imageData . First ( ) . Frame ) ;
230234 var aspectRatio = ( double ) frameInfo . Width / frameInfo . Height ;
231235 using ( var videoWriter = CreateWriter ( tempVideoPath , fps , aspectRatio ) )
232236 {
@@ -235,7 +239,7 @@ private async Task<VideoOutput> CreateVideoInternalAsync(IEnumerable<byte[]> ima
235239 foreach ( var image in imageData )
236240 {
237241 // Write each frame to the input stream of FFMPEG
238- await videoWriter . StandardInput . BaseStream . WriteAsync ( image , cancellationToken ) ;
242+ await videoWriter . StandardInput . BaseStream . WriteAsync ( image . Frame , cancellationToken ) ;
239243 }
240244
241245 // Done close stream and wait for app to process
@@ -265,7 +269,7 @@ private async Task<VideoOutput> CreateVideoInternalAsync(IEnumerable<byte[]> ima
265269 /// <param name="cancellationToken">The cancellation token.</param>
266270 /// <returns></returns>
267271 /// <exception cref="Exception">Invalid PNG header</exception>
268- private async IAsyncEnumerable < byte [ ] > CreateFramesInternalAsync ( byte [ ] videoData , float fps = 15 , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
272+ private async IAsyncEnumerable < VideoFrame > CreateFramesInternalAsync ( byte [ ] videoData , float fps = 15 , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
269273 {
270274 string tempVideoPath = GetTempFilename ( ) ;
271275 try
@@ -325,7 +329,7 @@ private async IAsyncEnumerable<byte[]> CreateFramesInternalAsync(byte[] videoDat
325329 break ;
326330 }
327331
328- yield return buffer [ ..currentIndex ] ;
332+ yield return new VideoFrame ( buffer [ ..currentIndex ] ) ;
329333 }
330334
331335 if ( cancellationToken . IsCancellationRequested )
0 commit comments