mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Merge pull request #148 from rosenbjerg/master
3.3.0
Former-commit-id: 9604127f7a
This commit is contained in:
commit
c82333bd12
4 changed files with 46 additions and 7 deletions
|
@ -7,6 +7,7 @@
|
|||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FFMpegCore.Arguments;
|
||||
using FFMpegCore.Exceptions;
|
||||
|
@ -550,6 +551,27 @@ public void Video_UpdatesProgress()
|
|||
Assert.AreNotEqual(TimeSpan.Zero, timeDone);
|
||||
}
|
||||
|
||||
[TestMethod, Timeout(10000)]
|
||||
public void Video_OutputsData()
|
||||
{
|
||||
var outputFile = new TemporaryFile("out.mp4");
|
||||
var dataReceived = false;
|
||||
|
||||
FFMpegOptions.Configure(opt => opt.Encoding = Encoding.UTF8);
|
||||
var success = FFMpegArguments
|
||||
.FromFileInput(TestResources.Mp4Video)
|
||||
.WithGlobalOptions(options => options
|
||||
.WithVerbosityLevel(VerbosityLevel.Info))
|
||||
.OutputToFile(outputFile, false, opt => opt
|
||||
.WithDuration(TimeSpan.FromSeconds(2)))
|
||||
.NotifyOnOutput((_, _) => dataReceived = true)
|
||||
.ProcessSynchronously();
|
||||
|
||||
Assert.IsTrue(dataReceived);
|
||||
Assert.IsTrue(success);
|
||||
Assert.IsTrue(File.Exists(outputFile));
|
||||
}
|
||||
|
||||
[TestMethod, Timeout(10000)]
|
||||
public void Video_TranscodeInMemory()
|
||||
{
|
||||
|
|
|
@ -17,6 +17,7 @@ public class FFMpegArgumentProcessor
|
|||
private readonly FFMpegArguments _ffMpegArguments;
|
||||
private Action<double>? _onPercentageProgress;
|
||||
private Action<TimeSpan>? _onTimeProgress;
|
||||
private Action<string, DataType>? _onOutput;
|
||||
private TimeSpan? _totalTimespan;
|
||||
|
||||
internal FFMpegArgumentProcessor(FFMpegArguments ffMpegArguments)
|
||||
|
@ -39,6 +40,11 @@ public FFMpegArgumentProcessor NotifyOnProgress(Action<TimeSpan> onTimeProgress)
|
|||
_onTimeProgress = onTimeProgress;
|
||||
return this;
|
||||
}
|
||||
public FFMpegArgumentProcessor NotifyOnOutput(Action<string, DataType> onOutput)
|
||||
{
|
||||
_onOutput = onOutput;
|
||||
return this;
|
||||
}
|
||||
public FFMpegArgumentProcessor CancellableThrough(out Action cancel)
|
||||
{
|
||||
cancel = () => CancelEvent?.Invoke(this, EventArgs.Empty);
|
||||
|
@ -130,10 +136,17 @@ private Instance PrepareInstance(out CancellationTokenSource cancellationTokenSo
|
|||
{
|
||||
FFMpegHelper.RootExceptionCheck();
|
||||
FFMpegHelper.VerifyFFMpegExists();
|
||||
var instance = new Instance(FFMpegOptions.Options.FFmpegBinary(), _ffMpegArguments.Text);
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = FFMpegOptions.Options.FFmpegBinary(),
|
||||
Arguments = _ffMpegArguments.Text,
|
||||
StandardOutputEncoding = FFMpegOptions.Options.Encoding,
|
||||
StandardErrorEncoding = FFMpegOptions.Options.Encoding,
|
||||
};
|
||||
var instance = new Instance(startInfo);
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
if (_onTimeProgress != null || (_onPercentageProgress != null && _totalTimespan != null))
|
||||
if (_onOutput != null || _onTimeProgress != null || (_onPercentageProgress != null && _totalTimespan != null))
|
||||
instance.DataReceived += OutputData;
|
||||
|
||||
return instance;
|
||||
|
@ -150,8 +163,10 @@ private static bool HandleException(bool throwOnError, Exception e, IReadOnlyLis
|
|||
|
||||
private void OutputData(object sender, (DataType Type, string Data) msg)
|
||||
{
|
||||
var match = ProgressRegex.Match(msg.Data);
|
||||
Debug.WriteLine(msg.Data);
|
||||
_onOutput?.Invoke(msg.Data, msg.Type);
|
||||
|
||||
var match = ProgressRegex.Match(msg.Data);
|
||||
if (!match.Success) return;
|
||||
|
||||
var processed = TimeSpan.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace FFMpegCore
|
||||
|
@ -40,6 +41,8 @@ static FFMpegOptions()
|
|||
|
||||
public string RootDirectory { get; set; } = DefaultRoot;
|
||||
public string TempDirectory { get; set; } = DefaultTemp;
|
||||
public bool UseCache { get; set; } = true;
|
||||
public Encoding Encoding { get; set; } = Encoding.Default;
|
||||
|
||||
public string FFmpegBinary() => FFBinary("FFMpeg");
|
||||
|
||||
|
@ -47,8 +50,6 @@ static FFMpegOptions()
|
|||
|
||||
public Dictionary<string, string> ExtensionOverrides { get; private set; } = new Dictionary<string, string>();
|
||||
|
||||
public bool UseCache { get; set; } = true;
|
||||
|
||||
private static string FFBinary(string name)
|
||||
{
|
||||
var ffName = name.ToLowerInvariant();
|
||||
|
|
|
@ -9,9 +9,10 @@
|
|||
<Version>3.0.0.0</Version>
|
||||
<AssemblyVersion>3.0.0.0</AssemblyVersion>
|
||||
<FileVersion>3.0.0.0</FileVersion>
|
||||
<PackageReleaseNotes>- Also include ffmpeg output data on non-zero exit code</PackageReleaseNotes>
|
||||
<PackageReleaseNotes>- Support for changing encoding used for parsing ffmpeg/ffprobe output
|
||||
- Support for registrering action to invoke on ffmpeg output</PackageReleaseNotes>
|
||||
<LangVersion>8</LangVersion>
|
||||
<PackageVersion>3.2.4</PackageVersion>
|
||||
<PackageVersion>3.3.0</PackageVersion>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<Authors>Malte Rosenbjerg, Vlad Jerca</Authors>
|
||||
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
|
||||
|
|
Loading…
Reference in a new issue