Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit e2c31c2

Browse files
committed
Video service for creating and dissecting video
1 parent 3323565 commit e2c31c2

File tree

8 files changed

+619
-0
lines changed

8 files changed

+619
-0
lines changed

OnnxStack.Core/Config/OnnxStackConfig.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ namespace OnnxStack.Core.Config
44
{
55
public class OnnxStackConfig : IConfigSection
66
{
7+
public string TempPath { get; set; } = ".temp";
8+
public string FFmpegPath { get; set; } = "ffmpeg.exe";
9+
public string FFprobePath { get; set; } = "ffprobe.exe";
10+
711
public void Initialize()
812
{
913
}

OnnxStack.Core/OnnxStack.Core.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
</ItemGroup>
3636

3737
<ItemGroup>
38+
<PackageReference Include="FFMpegCore" Version="5.1.0" />
3839
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
3940
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
4041
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
4142
<PackageReference Include="Microsoft.ML" Version="3.0.0" />
4243
<PackageReference Include="Microsoft.ML.OnnxRuntime.Extensions" Version="0.9.0" />
4344
<PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.16.3" />
4445
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.1" />
46+
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
4547
</ItemGroup>
4648

4749
<ItemGroup>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using OnnxStack.Core.Video;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
namespace OnnxStack.Core.Services
8+
{
9+
/// <summary>
10+
/// Service with basic handling of video for use in OnnxStack, Frame->Video and Video->Frames
11+
/// </summary>
12+
public interface IVideoService
13+
{
14+
/// <summary>
15+
/// Gets the video information asynchronous.
16+
/// </summary>
17+
/// <param name="videoBytes">The video bytes.</param>
18+
/// <param name="cancellationToken">The cancellation token.</param>
19+
/// <returns></returns>
20+
Task<VideoInfo> GetVideoInfoAsync(byte[] videoBytes, CancellationToken cancellationToken = default);
21+
22+
/// <summary>
23+
/// Gets the video information asynchronous.
24+
/// </summary>
25+
/// <param name="videoStream">The video stream.</param>
26+
/// <param name="cancellationToken">The cancellation token.</param>
27+
/// <returns></returns>
28+
Task<VideoInfo> GetVideoInfoAsync(Stream videoStream, CancellationToken cancellationToken = default);
29+
30+
/// <summary>
31+
/// Gets the video information, Size, FPS, Duration etc.
32+
/// </summary>
33+
/// <param name="videoInput">The video input.</param>
34+
/// <param name="cancellationToken">The cancellation token.</param>
35+
/// <returns></returns>
36+
/// <exception cref="ArgumentException">No video data found</exception>
37+
Task<VideoInfo> GetVideoInfoAsync(VideoInput videoInput, CancellationToken cancellationToken = default);
38+
39+
40+
/// <summary>
41+
/// Creates a collection of PNG frames from a video source
42+
/// </summary>
43+
/// <param name="videoBytes">The video bytes.</param>
44+
/// <param name="videoFPS">The video FPS.</param>
45+
/// <param name="cancellationToken">The cancellation token.</param>
46+
/// <returns></returns>
47+
Task<VideoFrames> CreateFramesAsync(byte[] videoBytes, float videoFPS, CancellationToken cancellationToken = default);
48+
49+
50+
/// <summary>
51+
/// Creates a collection of PNG frames from a video source
52+
/// </summary>
53+
/// <param name="videoStream">The video stream.</param>
54+
/// <param name="videoFPS">The video FPS.</param>
55+
/// <param name="cancellationToken">The cancellation token.</param>
56+
/// <returns></returns>
57+
Task<VideoFrames> CreateFramesAsync(Stream videoStream, float videoFPS, CancellationToken cancellationToken = default);
58+
59+
60+
/// <summary>
61+
/// Creates a collection of PNG frames from a video source
62+
/// </summary>
63+
/// <param name="videoInput">The video input.</param>
64+
/// <param name="videoFPS">The video FPS.</param>
65+
/// <param name="cancellationToken">The cancellation token.</param>
66+
/// <returns></returns>
67+
/// <exception cref="NotSupportedException">VideoTensor not supported</exception>
68+
/// <exception cref="ArgumentException">No video data found</exception>
69+
Task<VideoFrames> CreateFramesAsync(VideoInput videoInput, float videoFPS, CancellationToken cancellationToken = default);
70+
71+
72+
/// <summary>
73+
/// Creates and MP4 video from a collection of PNG images.
74+
/// </summary>
75+
/// <param name="videoFrames">The video frames.</param>
76+
/// <param name="videoFPS">The video FPS.</param>
77+
/// <param name="cancellationToken">The cancellation token.</param>
78+
/// <returns></returns>
79+
Task<VideoResult> CreateVideoAsync(IEnumerable<byte[]> videoFrames, float videoFPS, CancellationToken cancellationToken = default);
80+
81+
82+
/// <summary>
83+
/// Creates and MP4 video from a collection of PNG images.
84+
/// </summary>
85+
/// <param name="videoFrames">The video frames.</param>
86+
/// <param name="cancellationToken">The cancellation token.</param>
87+
/// <returns></returns>
88+
Task<VideoResult> CreateVideoAsync(VideoFrames videoFrames, CancellationToken cancellationToken = default);
89+
90+
91+
/// <summary>
92+
/// Streams frames as PNG as they are processed from a video source
93+
/// </summary>
94+
/// <param name="videoBytes">The video bytes.</param>
95+
/// <param name="targetFPS">The target FPS.</param>
96+
/// <param name="cancellationToken">The cancellation token.</param>
97+
/// <returns></returns>
98+
IAsyncEnumerable<byte[]> StreamFramesAsync(byte[] videoBytes, float targetFPS, CancellationToken cancellationToken = default);
99+
}
100+
}

0 commit comments

Comments
 (0)