cmxl / FFmpeg.NET

.NET wrapper for common ffmpeg tasks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example code not working in .NET 6.0 for Windows 10.

zydjohnHotmail opened this issue · comments

Hello:
I am now using Visual Studio 2022, and I want to test the sample code for WinFrom project using the latest version (7.0.1)
PM> Install-Package xFFmpeg.NET -Version 7.0.1

var inputFile = new MediaFile (@"C:\Path\To_Video.flv");
var outputFile = new MediaFile (@"C:\Path\To_Save_ExtractedVideo.flv");

var ffmpeg = new Engine("C:\ffmpeg\ffmpeg.exe");
var options = new ConversionOptions();

// This example will create a 25 second video, starting from the
// 30th second of the original video.
//// First parameter requests the starting frame to cut the media from.
//// Second parameter requests how long to cut the video.
options.CutMedia(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(25));
await ffmpeg.ConvertAsync(inputFile, outputFile, options);

But I got compiler error:
Error CS1503 Argument 1: cannot convert from 'FFmpeg.NET.MediaFile' to 'FFmpeg.NET.InputFile'
Error CS1503 Argument 2: cannot convert from 'FFmpeg.NET.MediaFile' to 'FFmpeg.NET.OutputFile'
Error CS1503 Argument 3: cannot convert from 'FFmpeg.NET.ConversionOptions' to 'System.Threading.CancellationToken'
It seems the new version 7.0.1 is rather different from previous version, at least for the code examples.
Please advise on how to fix it!
Thanks,

Use InputFile and OutputFile instead of MediaFile. MediaFile will now actually become an abstract class and does not implement IInputArguments which is used by ConvertAsync.

var inputFile = new InputFile(@"C:\Path\To_Video.flv");
var outputFile = new OutputFile(@"C:\Path\To_Save_ExtractedVideo.flv");
var ffmpeg = new Engine("C:\ffmpeg\ffmpeg.exe");
var options = new ConversionOptions();
options.CutMedia(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(25));
await ffmpeg.ConvertAsync(inputFile, outputFile, options, default);