TJC.Cyclops.VideoKit 2026.4.14.2

dotnet add package TJC.Cyclops.VideoKit --version 2026.4.14.2
                    
NuGet\Install-Package TJC.Cyclops.VideoKit -Version 2026.4.14.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TJC.Cyclops.VideoKit" Version="2026.4.14.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TJC.Cyclops.VideoKit" Version="2026.4.14.2" />
                    
Directory.Packages.props
<PackageReference Include="TJC.Cyclops.VideoKit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TJC.Cyclops.VideoKit --version 2026.4.14.2
                    
#r "nuget: TJC.Cyclops.VideoKit, 2026.4.14.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TJC.Cyclops.VideoKit@2026.4.14.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TJC.Cyclops.VideoKit&version=2026.4.14.2
                    
Install as a Cake Addin
#tool nuget:?package=TJC.Cyclops.VideoKit&version=2026.4.14.2
                    
Install as a Cake Tool

🎬 Cyclops.VideoKit

📝 项目概述

Cyclops.VideoKit 是 Cyclops.Framework 框架中的视频处理专家,为您的应用程序提供全方位的视频处理解决方案! 🚀

我们精心设计的组件简化了复杂的视频处理流程,让您能够轻松实现专业级的视频功能。无论是视频编辑、格式转换、特效添加,还是流媒体处理,Cyclops.VideoKit都能为您提供强大的支持。

✨ 为什么选择 Cyclops.VideoKit?

  • 全面的功能:从基础的格式转换到高级的视频特效,应有尽有
  • 高性能处理:支持硬件加速,处理速度快
  • 易于集成:与.NET依赖注入系统无缝集成
  • 丰富的格式支持:支持多种视频格式和编解码器
  • 专业级效果:提供专业级的视频处理效果和滤镜
  • 流媒体支持:内置HLS和DASH流媒体生成能力

🎯 核心功能模块

📹 视频编码与解码

  • 多格式支持:支持常见视频格式的编码与解码
  • 硬件加速:利用GPU加速,提升处理速度
  • 质量控制:精细平衡视频质量与文件大小
  • 自定义配置:灵活配置编解码器参数,满足特定需求

🎨 视频处理

  • 格式转换:在不同视频格式间无缝转换
  • 分辨率调整:支持各种分辨率的缩放和适配
  • 帧率控制:调整视频帧率,优化播放效果
  • 视频剪辑:精确裁剪和拼接视频片段

✨ 视频特效

  • 滤镜应用:丰富的视频滤镜效果,提升视觉体验
  • 水印添加:支持文字和图片水印,保护版权
  • 转场效果:专业的视频转场效果,增强观赏性
  • 动画效果:添加动态效果,使视频更加生动

📊 媒体分析

  • 元数据提取:获取视频详细信息,如分辨率、时长等
  • 关键帧检测:自动检测视频关键帧,便于快速预览
  • 内容分析:分析视频内容,提供智能处理建议
  • 质量评估:评估视频质量,优化处理参数

📡 流媒体支持

  • HLS流媒体:生成HTTP Live Streaming格式,支持网页播放
  • DASH支持:支持Dynamic Adaptive Streaming over HTTP
  • 服务器集成:与常见流媒体服务器无缝集成
  • 自适应比特率:根据网络状况自动调整视频质量

🚀 高级功能

  • 实时处理:支持实时视频处理和预览
  • 批量处理:高效处理大量视频文件
  • 压缩优化:智能优化视频大小,保持画质
  • 3D视频:支持3D视频处理和转换

🛠️ 技术栈

  • .NET 8.0:利用最新的.NET特性和性能优化
  • FFmpeg:强大的开源视频处理库,提供核心视频处理能力
  • MediaInfo:获取详细的媒体文件信息
  • Cyclops.Common:框架核心公共组件
  • Cyclops.Storage:提供存储服务集成

📦 环境依赖

  • .NET 8.0 SDK 或更高版本
  • FFmpeg:需要单独安装,版本建议4.0+(下载地址
  • 可选:NVIDIA CUDA:用于启用硬件加速,提升处理速度
  • 支持的平台:Windows、Linux、macOS
  • IDE推荐:Visual Studio 2022、Visual Studio Code

🚀 安装配置

🔍 安装方式

NuGet包管理器
Install-Package Cyclops.VideoKit
.NET CLI
dotnet add package Cyclops.VideoKit
PackageReference
<PackageReference Include="Cyclops.VideoKit" Version="1.0.0" />

⚙️ 基本配置

在应用程序启动时进行配置,享受开箱即用的视频处理能力!

// 在Program.cs或Startup.cs中
using Cyclops.VideoKit;

var builder = WebApplication.CreateBuilder(args);

// 添加Cyclops.VideoKit服务
builder.Services.AddCyclopsVideoKit(options => {
    // FFmpeg路径配置 - 请确保FFmpeg已安装
    options.FfmpegPath = @"C:\ffmpeg\bin\ffmpeg.exe";  // Windows示例路径
    options.FfprobePath = @"C:\ffmpeg\bin\ffprobe.exe";  // Windows示例路径
    // Linux示例: options.FfmpegPath = "/usr/bin/ffmpeg";
    
    // 编码配置 - 根据需求调整
    options.EncodingOptions = new VideoEncodingOptions {
        DefaultVideoCodec = "h264",           // 默认视频编码器
        DefaultAudioCodec = "aac",            // 默认音频编码器
        DefaultPreset = "medium",             // 编码预设:ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow
        EnableHardwareAcceleration = true     // 启用硬件加速
    };
    
    // 临时文件配置 - 优化存储空间使用
    options.TempFileOptions = new TempFileOptions {
        TempDirectory = Path.GetTempPath(),     // 临时文件目录
        AutoCleanup = true,                     // 自动清理临时文件
        MaxTempFileAge = TimeSpan.FromHours(24) // 临时文件最大保留时间
    };
});

// ...

🎯 配置建议

  • FFmpeg路径:确保FFmpeg已正确安装,路径配置准确
  • 编码预设:根据需要平衡速度和质量,实时应用建议使用fast或veryfast
  • 硬件加速:如果系统支持,建议启用以提升处理速度
  • 临时文件:确保临时目录有足够的存储空间,特别是处理大型视频时

📝 代码示例

📹 视频转换示例

以下示例展示了如何使用 Cyclops.VideoKit 进行视频格式转换,支持多种编码选项和硬件加速:

using Cyclops.VideoKit.Services;
using Microsoft.Extensions.DependencyInjection;

public class VideoConversionService
{
    private readonly IVideoConverter _videoConverter;
    private readonly IVideoAnalyzer _videoAnalyzer;
    
    public VideoConversionService(IVideoConverter videoConverter, IVideoAnalyzer videoAnalyzer)
    {
        _videoConverter = videoConverter;
        _videoAnalyzer = videoAnalyzer;
    }
    
    public async Task<VideoConversionResult> ConvertVideoAsync(string sourceFilePath, string outputFilePath, VideoConversionOptions options)
    {
        try
        {
            // 分析源视频信息
            var sourceInfo = await _videoAnalyzer.GetVideoInfoAsync(sourceFilePath);
            Console.WriteLine($"源视频信息: {sourceInfo.Format},分辨率: {sourceInfo.Width}x{sourceInfo.Height},时长: {sourceInfo.Duration.TotalSeconds}秒");
            
            // 配置转换选项
            var conversionOptions = new VideoConversionOptions {
                OutputFormat = options.OutputFormat ?? "mp4",
                VideoCodec = options.VideoCodec ?? "h264",
                VideoBitrate = options.VideoBitrate ?? "2M", // 2Mbps
                AudioCodec = options.AudioCodec ?? "aac",
                AudioBitrate = options.AudioBitrate ?? "128k",
                Width = options.Width, // 可选,不指定则保持原始宽度
                Height = options.Height, // 可选,不指定则保持原始高度
                PreserveAspectRatio = options.PreserveAspectRatio ?? true,
                EnableHardwareAcceleration = options.EnableHardwareAcceleration ?? true
            };
            
            // 显示转换配置
            Console.WriteLine($"开始转换视频: {Path.GetFileName(sourceFilePath)} -> {Path.GetFileName(outputFilePath)}");
            Console.WriteLine($"输出格式: {conversionOptions.OutputFormat}");
            Console.WriteLine($"视频编码: {conversionOptions.VideoCodec} @ {conversionOptions.VideoBitrate}");
            Console.WriteLine($"音频编码: {conversionOptions.AudioCodec} @ {conversionOptions.AudioBitrate}");
            
            // 执行转换
            var result = await _videoConverter.ConvertAsync(sourceFilePath, outputFilePath, conversionOptions, 
                progressCallback: (progress) => {
                    Console.WriteLine($"转换进度: {progress.Percentage:P2}, 速度: {progress.Speed}x");
                });
            
            // 分析转换后的视频
            var outputInfo = await _videoAnalyzer.GetVideoInfoAsync(outputFilePath);
            
            Console.WriteLine($"转换完成!");
            Console.WriteLine($"输出视频信息: {outputInfo.Format},分辨率: {outputInfo.Width}x{outputInfo.Height},时长: {outputInfo.Duration.TotalSeconds}秒,文件大小: {new FileInfo(outputFilePath).Length / 1024 / 1024:F2}MB");
            
            return new VideoConversionResult {
                Success = true,
                OutputPath = outputFilePath,
                OutputInfo = outputInfo,
                ProcessingTime = result.ProcessingTime,
                OriginalSize = result.OriginalSize,
                OutputSize = result.OutputSize,
                CompressionRatio = result.CompressionRatio
            };
        }
        catch (Exception ex)
        {
            Console.WriteLine($"转换失败: {ex.Message}");
            throw;
        }
    }
    
    // 批量转换示例
    public async Task<IEnumerable<VideoConversionResult>> BatchConvertVideosAsync(IEnumerable<VideoConversionJob> jobs)
    {
        var results = new List<VideoConversionResult>();
        
        foreach (var job in jobs)
        {
            var result = await ConvertVideoAsync(job.SourceFilePath, job.OutputFilePath, job.Options);
            results.Add(result);
        }
        
        return results;
    }
}

// 视频转换选项
public class VideoConversionOptions
{
    public string OutputFormat { get; set; }
    public string VideoCodec { get; set; }
    public string VideoBitrate { get; set; }
    public string AudioCodec { get; set; }
    public string AudioBitrate { get; set; }
    public int? Width { get; set; }
    public int? Height { get; set; }
    public bool? PreserveAspectRatio { get; set; }
    public bool? EnableHardwareAcceleration { get; set; }
}

public class VideoConversionJob
{
    public string SourceFilePath { get; set; }
    public string OutputFilePath { get; set; }
    public VideoConversionOptions Options { get; set; }
}

public class VideoConversionResult
{
    public bool Success { get; set; }
    public string OutputPath { get; set; }
    public VideoInfo OutputInfo { get; set; }
    public TimeSpan ProcessingTime { get; set; }
    public long OriginalSize { get; set; }
    public long OutputSize { get; set; }
    public double CompressionRatio { get; set; }
}

// 视频信息模型
public class VideoInfo
{
    public string Format { get; set; }
    public int Width { get; set; }
    public int Height { get; set; }
    public TimeSpan Duration { get; set; }
    public double Framerate { get; set; }
    public string VideoCodec { get; set; }
    public string AudioCodec { get; set; }
    public int AudioChannels { get; set; }
    public int SampleRate { get; set; }
}

🎨 视频编辑与特效示例

以下示例展示了如何使用 Cyclops.VideoKit 进行视频编辑和添加特效,包括裁剪、合并、水印和滤镜:

using Cyclops.VideoKit.Editing;
using Microsoft.Extensions.DependencyInjection;

// 视频剪辑服务
public class VideoEditingService
{
    private readonly IVideoEditor _videoEditor;
    
    public VideoEditingService(IVideoEditorFactory videoEditorFactory)
    {
        _videoEditor = videoEditorFactory.Create();
    }
    
    // 视频裁剪
    public async Task<string> TrimVideoAsync(string sourcePath, TimeSpan startTime, TimeSpan endTime, string outputPath)
    {
        Console.WriteLine($"开始裁剪视频: {Path.GetFileName(sourcePath)},从 {startTime} 到 {endTime}");
        
        try
        {
            // 执行裁剪
            await _videoEditor.TrimAsync(sourcePath, startTime, endTime, outputPath);
            Console.WriteLine($"视频裁剪完成: {Path.GetFileName(outputPath)}");
            return outputPath;
        }
        catch (Exception ex)
        {
            Console.WriteLine($"视频裁剪失败: {ex.Message}");
            throw;
        }
    }
    
    // 视频合并
    public async Task<string> MergeVideosAsync(IEnumerable<string> videoPaths, string outputPath)
    {
        Console.WriteLine($"开始合并 {videoPaths.Count()} 个视频片段");
        
        try
        {
            // 创建合并列表文件
            var listFilePath = Path.Combine(Path.GetTempPath(), $"merge_list_{Guid.NewGuid()}.txt");
            
            using (var writer = new StreamWriter(listFilePath))
            {
                foreach (var videoPath in videoPaths)
                {
                    writer.WriteLine($"file '{videoPath}'");
                }
            }
            
            // 执行合并
            await _videoEditor.MergeAsync(listFilePath, outputPath);
            
            // 删除临时列表文件
            File.Delete(listFilePath);
            
            Console.WriteLine($"视频合并完成: {Path.GetFileName(outputPath)}");
            return outputPath;
        }
        catch (Exception ex)
        {
            Console.WriteLine($"视频合并失败: {ex.Message}");
            throw;
        }
    }
    
    // 添加水印
    public async Task<string> AddWatermarkAsync(string videoPath, string watermarkPath, string outputPath, 
        WatermarkPosition position = WatermarkPosition.BottomRight, double opacity = 0.5)
    {
        Console.WriteLine($"开始添加水印到视频: {Path.GetFileName(videoPath)}");
        
        try
        {
            // 配置水印选项
            var watermarkOptions = new WatermarkOptions {
                WatermarkPath = watermarkPath,
                Position = position,
                Opacity = opacity,
                Margin = 20 // 边距,像素
            };
            
            // 添加水印
            await _videoEditor.AddWatermarkAsync(videoPath, watermarkOptions, outputPath);
            
            Console.WriteLine($"水印添加完成: {Path.GetFileName(outputPath)}");
            return outputPath;
        }
        catch (Exception ex)
        {
            Console.WriteLine($"添加水印失败: {ex.Message}");
            throw;
        }
    }
}

// 水印位置枚举
public enum WatermarkPosition
{
    TopLeft,
    TopRight,
    BottomLeft,
    BottomRight,
    Center
}

// 水印选项
public class WatermarkOptions
{
    public string WatermarkPath { get; set; }
    public WatermarkPosition Position { get; set; }
    public double Opacity { get; set; }
    public int Margin { get; set; }
    public int? Width { get; set; } // 可选,指定水印宽度
    public int? Height { get; set; } // 可选,指定水印高度
}

// 视频滤镜示例
public class VideoFilterService
{
    private readonly IVideoFilter _videoFilter;
    
    public VideoFilterService(IVideoFilterFactory filterFactory)
    {
        _videoFilter = filterFactory.Create();
    }
    
    // 应用视频滤镜
    public async Task<string> ApplyFiltersAsync(string sourcePath, string outputPath, params FilterType[] filters)
    {
        Console.WriteLine($"开始应用滤镜到视频: {Path.GetFileName(sourcePath)}");
        
        try
        {
            // 创建滤镜链
            var filterChain = new List<string>();
            
            foreach (var filter in filters)
            {
                switch (filter)
                {
                    case FilterType.Grayscale:
                        filterChain.Add("grayscale=1");
                        Console.WriteLine("添加灰度滤镜");
                        break;
                    case FilterType.Brightness:
                        filterChain.Add("eq=brightness=1.2"); // 增加20%亮度
                        Console.WriteLine("添加亮度滤镜");
                        break;
                    case FilterType.Contrast:
                        filterChain.Add("eq=contrast=1.3"); // 增加30%对比度
                        Console.WriteLine("添加对比度滤镜");
                        break;
                    case FilterType.Sharpen:
                        filterChain.Add("unsharp=5:5:0.5");
                        Console.WriteLine("添加锐化滤镜");
                        break;
                }
            }
            
            // 应用滤镜
            await _videoFilter.ApplyFiltersAsync(sourcePath, outputPath, filterChain, 
                progressCallback: (progress) => {
                    Console.WriteLine($"滤镜应用进度: {progress.Percentage:P2}");
                });
            
            Console.WriteLine($"滤镜应用完成: {Path.GetFileName(outputPath)}");
            return outputPath;
        }
        catch (Exception ex)
        {
            Console.WriteLine($"应用滤镜失败: {ex.Message}");
            throw;
        }
    }
}

// 滤镜类型枚举
public enum FilterType
{
    Grayscale,
    Brightness,
    Contrast,
    Sharpen,
    Blur,
    Saturation
}

🖼️ 缩略图和流媒体示例

以下示例展示了如何使用 Cyclops.VideoKit 生成视频缩略图和创建流媒体内容:

using Cyclops.VideoKit.Thumbnails;
using Cyclops.VideoKit.Streaming;
using Microsoft.Extensions.DependencyInjection;

// 视频缩略图服务
public class VideoThumbnailService
{
    private readonly IVideoThumbnailGenerator _thumbnailGenerator;
    
    public VideoThumbnailService(IVideoThumbnailGeneratorFactory thumbnailFactory)
    {
        _thumbnailGenerator = thumbnailFactory.Create();
    }
    
    // 生成单个缩略图
    public async Task<string> GenerateThumbnailAsync(string videoPath, TimeSpan timestamp, string outputPath, ThumbnailOptions options = null)
    {
        try
        {
            Console.WriteLine($"为视频生成缩略图: {Path.GetFileName(videoPath)},时间点: {timestamp}");
            
            // 生成缩略图
            await _thumbnailGenerator.GenerateSingleAsync(videoPath, timestamp, outputPath, options);
            
            Console.WriteLine($"缩略图生成完成: {Path.GetFileName(outputPath)}");
            return outputPath;
        }
        catch (Exception ex)
        {
            Console.WriteLine($"生成缩略图失败: {ex.Message}");
            throw;
        }
    }
    
    // 生成多个缩略图(时间轴缩略图)
    public async Task<IEnumerable<string>> GenerateThumbnailStripAsync(string videoPath, string outputDirectory, int count = 10)
    {
        var results = new List<string>();
        
        try
        {
            // 分析视频时长
            var analyzer = new VideoAnalyzer();
            var videoInfo = await analyzer.GetVideoInfoAsync(videoPath);
            
            // 计算缩略图时间间隔
            var interval = videoInfo.Duration.TotalSeconds / (count + 1);
            
            Console.WriteLine($"为视频生成时间轴缩略图: {Path.GetFileName(videoPath)},共 {count} 个");
            
            // 生成多个缩略图
            for (int i = 1; i <= count; i++)
            {
                var timestamp = TimeSpan.FromSeconds(interval * i);
                var outputPath = Path.Combine(outputDirectory, $"thumbnail_{i:D3}.jpg");
                
                await _thumbnailGenerator.GenerateSingleAsync(videoPath, timestamp, outputPath, 
                    new ThumbnailOptions {
                        Width = 320, // 缩略图宽度
                        Height = 0, // 高度自动计算以保持比例
                        Quality = 85
                    });
                
                results.Add(outputPath);
            }
            
            return results;
        }
        catch (Exception ex)
        {
            Console.WriteLine($"生成缩略图失败: {ex.Message}");
            throw;
        }
    }
}

// 缩略图选项
public class ThumbnailOptions
{
    public int Width { get; set; } = 320;
    public int Height { get; set; } = 0; // 0表示自动计算
    public int Quality { get; set; } = 80;
    public bool PreserveAspectRatio { get; set; } = true;
    public string Format { get; set; } = "jpg";
}

// 流媒体服务
public class StreamingService
{
    private readonly IHlsGenerator _hlsGenerator;
    
    public StreamingService(IHlsGeneratorFactory hlsFactory)
    {
        _hlsGenerator = hlsFactory.Create();
    }
    
    // 生成HLS流
    public async Task<string> CreateHlsStreamAsync(string videoPath, string outputDirectory, bool generateMultipleQualities = false)
    {
        try
        {
            Console.WriteLine($"开始生成HLS流: {Path.GetFileName(videoPath)}");
            
            // 配置HLS选项
            var hlsOptions = new HlsOptions {
                OutputDirectory = outputDirectory,
                SegmentDuration = TimeSpan.FromSeconds(10), // 每个片段10秒
                SegmentFilenamePattern = "segment_%03d.ts",
                PlaylistFilename = "playlist.m3u8",
                GenerateMultipleQualities = generateMultipleQualities,
                QualityLevels = generateMultipleQualities ? 
                    new[] {
                        new VideoQuality { Width = 640, Height = 360, VideoBitrate = "800k" }, // 360p
                        new VideoQuality { Width = 1280, Height = 720, VideoBitrate = "2M" }, // 720p
                        new VideoQuality { Width = 1920, Height = 1080, VideoBitrate = "5M" } // 1080p
                    } : 
                    null
            };
            
            // 生成HLS流
            await _hlsGenerator.GenerateHlsAsync(videoPath, hlsOptions, 
                progressCallback: (progress) => {
                    Console.WriteLine($"HLS生成进度: {progress.Percentage:P2}");
                });
            
            var masterPlaylistPath = Path.Combine(outputDirectory, hlsOptions.PlaylistFilename);
            Console.WriteLine($"HLS流生成完成: {masterPlaylistPath}");
            
            return masterPlaylistPath;
        }
        catch (Exception ex)
        {
            Console.WriteLine($"HLS流生成失败: {ex.Message}");
            throw;
        }
    }
}

// 视频质量选项
public class VideoQuality
{
    public int Width { get; set; }
    public int Height { get; set; }
    public string VideoBitrate { get; set; }
    public string AudioBitrate { get; set; } = "128k";
}

// HLS选项
public class HlsOptions
{
    public string OutputDirectory { get; set; }
    public TimeSpan SegmentDuration { get; set; }
    public string SegmentFilenamePattern { get; set; }
    public string PlaylistFilename { get; set; }
    public bool GenerateMultipleQualities { get; set; }
    public VideoQuality[] QualityLevels { get; set; }
}

🚀 批量处理与高级功能

以下示例展示了如何使用 Cyclops.VideoKit 进行批量视频处理和视频优化:

using Cyclops.VideoKit.Batch;
using Microsoft.Extensions.DependencyInjection;

// 批量视频处理服务
public class BatchVideoProcessor
{
    private readonly IBatchVideoProcessor _batchProcessor;
    private readonly IProgressTracker _progressTracker;
    
    public BatchVideoProcessor(IBatchVideoProcessorFactory batchProcessorFactory, IProgressTrackerFactory progressFactory)
    {
        _batchProcessor = batchProcessorFactory.Create();
        _progressTracker = progressFactory.Create("BatchVideoProcessing");
    }
    
    // 批量转换视频
    public async Task<BatchProcessingResult> ProcessVideoBatchAsync(IEnumerable<BatchVideoJob> jobs)
    {
        Console.WriteLine($"开始批量处理 {jobs.Count()} 个视频任务");
        
        // 设置进度回调
        _progressTracker.ProgressChanged += (sender, args) => {
            Console.WriteLine($"批处理进度: {args.Percentage:P2}, " +
                           $"已完成: {args.CompletedCount}/{args.TotalCount}, " +
                           $"当前: {args.CurrentItem}");
        };
        
        // 执行批量处理
        var result = await _batchProcessor.ProcessAsync(jobs.ToList(), _progressTracker, 
            maxParallelTasks: Environment.ProcessorCount); // 并行任务数设为CPU核心数
        
        Console.WriteLine($"批处理完成! 成功: {result.SuccessCount}, 失败: {result.FailureCount}");
        
        if (result.FailedJobs.Any())
        {
            Console.WriteLine("失败任务列表:");
            foreach (var failedJob in result.FailedJobs)
            {
                Console.WriteLine($"  - {failedJob.SourcePath}: {failedJob.ErrorMessage}");
            }
        }
        
        return result;
    }
}

// 批量处理作业
public class BatchVideoJob
{
    public string SourcePath { get; set; }
    public string OutputPath { get; set; }
    public VideoConversionOptions Options { get; set; }
}

// 批量处理结果
public class BatchProcessingResult
{
    public int TotalCount { get; set; }
    public int SuccessCount { get; set; }
    public int FailureCount { get; set; }
    public List<BatchVideoJob> SuccessfulJobs { get; set; }
    public List<FailedBatchJob> FailedJobs { get; set; }
}

public class FailedBatchJob
{
    public string SourcePath { get; set; }
    public string ErrorMessage { get; set; }
    public Exception Exception { get; set; }
}

// 视频压缩优化服务
public class VideoOptimizationService
{
    private readonly IVideoOptimizer _videoOptimizer;
    
    public VideoOptimizationService(IVideoOptimizerFactory optimizerFactory)
    {
        _videoOptimizer = optimizerFactory.Create();
    }
    
    public async Task<OptimizationResult> OptimizeVideoAsync(string videoPath, string outputPath, VideoOptimizationLevel level)
    {
        Console.WriteLine($"开始优化视频: {Path.GetFileName(videoPath)}, 优化级别: {level}");
        
        try
        {
            // 根据优化级别设置参数
            var optimizationOptions = new VideoOptimizationOptions {
                OptimizationLevel = level,
                TargetFileSize = level switch {
                    VideoOptimizationLevel.Low => 0, // 不指定目标大小,使用默认设置
                    VideoOptimizationLevel.Medium => 0,
                    VideoOptimizationLevel.High => 0,
                    VideoOptimizationLevel.Custom => 10 * 1024 * 1024, // 10MB
                    _ => 0
                },
                PreserveQuality = level != VideoOptimizationLevel.High,
                EnableTwoPassEncoding = true,
                RemoveAudio = false,
                MaxWidth = level == VideoOptimizationLevel.High ? 1280 : 0, // 高清优化限制宽度
            };
            
            // 执行优化
            var result = await _videoOptimizer.OptimizeAsync(videoPath, outputPath, optimizationOptions, 
                progressCallback: (progress) => {
                    Console.WriteLine($"优化进度: {progress.Percentage:P2}, 估计文件大小: {(progress.EstimatedOutputSize / 1024 / 1024):F2}MB");
                });
            
            Console.WriteLine($"视频优化完成: {Path.GetFileName(outputPath)}");
            Console.WriteLine($"原始大小: {(result.OriginalSize / 1024 / 1024):F2}MB");
            Console.WriteLine($"优化后大小: {(result.OptimizedSize / 1024 / 1024):F2}MB");
            Console.WriteLine($"压缩率: {result.CompressionRatio:P2}");
            
            return result;
        }
        catch (Exception ex)
        {
            Console.WriteLine($"视频优化失败: {ex.Message}");
            throw;
        }
    }
}

// 优化级别
public enum VideoOptimizationLevel
{
    Low,    // 轻度优化,保持高质量
    Medium, // 平衡优化,中等质量
    High,   // 高度优化,压缩率优先
    Custom  // 自定义设置
}

// 优化结果
public class OptimizationResult
{
    public long OriginalSize { get; set; }
    public long OptimizedSize { get; set; }
    public double CompressionRatio { get; set; }
    public TimeSpan ProcessingTime { get; set; }
    public int OriginalBitrate { get; set; }
    public int OptimizedBitrate { get; set; }
}

// 优化选项
public class VideoOptimizationOptions
{
    public VideoOptimizationLevel OptimizationLevel { get; set; }
    public long TargetFileSize { get; set; } // 字节
    public bool PreserveQuality { get; set; }
    public bool EnableTwoPassEncoding { get; set; }
    public bool RemoveAudio { get; set; }
    public int MaxWidth { get; set; }
    public int MaxHeight { get; set; }
}

🤝 贡献者

我们欢迎社区贡献!如果您有任何改进建议或功能需求,欢迎提交PR或Issue。

  • yswenli:核心开发者

📋 版本信息

  • 当前版本NuGet version (Cyclops.Framework)
  • 作者:yswenli
  • 描述:企服版框架中视频处理组件
  • 更新频率:定期更新,持续改进

📄 许可证

保留所有权利

🎉 结语

Cyclops.VideoKit 致力于为您的应用程序提供最强大、最易用的视频处理工具。我们相信,通过简化视频处理的复杂性,您可以更专注于业务逻辑的实现,构建出更具吸引力的视频应用。

如果您有任何问题或建议,欢迎与我们联系!让我们一起构建更好的视频处理解决方案! 🚀

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TJC.Cyclops.VideoKit:

Package Downloads
TJC.Cyclops.CloudStorage

企服版框架中云存储SDK,目前支持阿里云、微软Azure、MiniIO的无缝集成

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.4.14.2 79 4/14/2026
2026.4.14.1 81 4/14/2026
2026.4.13.1 81 4/13/2026
2026.3.30.1 146 3/30/2026
2026.3.26.1 141 3/26/2026
2026.3.24.1 135 3/24/2026
2026.3.12.2 145 3/12/2026
2026.3.12.1 145 3/12/2026
2026.2.26.1 144 2/26/2026
2026.2.4.1 167 2/4/2026
2026.1.15.1 170 1/15/2026
2026.1.14.2 162 1/14/2026
2026.1.14.1 156 1/14/2026
2026.1.13.2 170 1/13/2026
2026.1.13.1 178 1/13/2026
2026.1.7.1 186 1/7/2026
2025.12.23.1 278 12/23/2025
2025.12.16.1 381 12/16/2025
2025.12.15.2 310 12/15/2025
2025.12.15.1 337 12/15/2025
Loading failed

企服版视频处理工具元件