mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Base file extension on video container info from ffmpeg
Former-commit-id: 442e69ce1d
This commit is contained in:
parent
4456fa7b5e
commit
ef8edf2a6e
4 changed files with 37 additions and 21 deletions
|
@ -332,6 +332,20 @@ public void Video_ToMP4_Args_StreamOutputPipe_Async()
|
||||||
.WaitForResult();
|
.WaitForResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task TestDuplicateRun()
|
||||||
|
{
|
||||||
|
FFMpegArguments.FromInputFiles(VideoLibrary.LocalVideo)
|
||||||
|
.OutputToFile("temporary.mp4", true)
|
||||||
|
.ProcessSynchronously();
|
||||||
|
|
||||||
|
await FFMpegArguments.FromInputFiles(VideoLibrary.LocalVideo)
|
||||||
|
.OutputToFile("temporary.mp4", true)
|
||||||
|
.ProcessAsynchronously();
|
||||||
|
|
||||||
|
File.Delete("temporary.mp4");
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Video_ToMP4_Args_StreamOutputPipe()
|
public void Video_ToMP4_Args_StreamOutputPipe()
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,11 +16,11 @@ public static string Extension(this Codec type)
|
||||||
_ => throw new Exception("The extension for this video type is not defined.")
|
_ => throw new Exception("The extension for this video type is not defined.")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static readonly string Mp4 = ".mp4";
|
public static readonly string Mp4 = VideoType.Mp4.Extension;
|
||||||
public static readonly string Mp3 = ".mp3";
|
public static readonly string Ts = VideoType.MpegTs.Extension;
|
||||||
public static readonly string Ts = ".ts";
|
public static readonly string Ogv = VideoType.Ogv.Extension;
|
||||||
public static readonly string Ogv = ".ogv";
|
public static readonly string WebM = VideoType.WebM.Extension;
|
||||||
public static readonly string Png = ".png";
|
public static readonly string Png = ".png";
|
||||||
public static readonly string WebM = ".webm";
|
public static readonly string Mp3 = ".mp3";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -50,7 +52,8 @@ public FFMpegArgumentProcessor CancellableThrough(out Action cancel)
|
||||||
}
|
}
|
||||||
public bool ProcessSynchronously(bool throwOnError = true)
|
public bool ProcessSynchronously(bool throwOnError = true)
|
||||||
{
|
{
|
||||||
var instance = PrepareInstance(out var cancellationTokenSource, out var errorCode);
|
var instance = PrepareInstance(out var cancellationTokenSource);
|
||||||
|
var errorCode = -1;
|
||||||
|
|
||||||
void OnCancelEvent(object sender, EventArgs args)
|
void OnCancelEvent(object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
|
@ -70,7 +73,7 @@ void OnCancelEvent(object sender, EventArgs args)
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
if (!HandleException(throwOnError, e, instance)) return false;
|
if (!HandleException(throwOnError, e, instance.ErrorData)) return false;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -78,13 +81,13 @@ void OnCancelEvent(object sender, EventArgs args)
|
||||||
_ffMpegArguments.Post();
|
_ffMpegArguments.Post();
|
||||||
}
|
}
|
||||||
|
|
||||||
return HandleCompletion(throwOnError, errorCode, instance);
|
return HandleCompletion(throwOnError, errorCode, instance.ErrorData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool HandleCompletion(bool throwOnError, int errorCode, Instance instance)
|
private bool HandleCompletion(bool throwOnError, int errorCode, IReadOnlyList<string> errorData)
|
||||||
{
|
{
|
||||||
if (throwOnError && errorCode != 0)
|
if (throwOnError && errorCode != 0)
|
||||||
throw new FFMpegException(FFMpegExceptionType.Conversion, string.Join("\n", instance.ErrorData));
|
throw new FFMpegException(FFMpegExceptionType.Conversion, string.Join("\n", errorData));
|
||||||
|
|
||||||
_onPercentageProgress?.Invoke(100.0);
|
_onPercentageProgress?.Invoke(100.0);
|
||||||
if (_totalTimespan.HasValue) _onTimeProgress?.Invoke(_totalTimespan.Value);
|
if (_totalTimespan.HasValue) _onTimeProgress?.Invoke(_totalTimespan.Value);
|
||||||
|
@ -94,7 +97,8 @@ private bool HandleCompletion(bool throwOnError, int errorCode, Instance instanc
|
||||||
|
|
||||||
public async Task<bool> ProcessAsynchronously(bool throwOnError = true)
|
public async Task<bool> ProcessAsynchronously(bool throwOnError = true)
|
||||||
{
|
{
|
||||||
using var instance = PrepareInstance(out var cancellationTokenSource, out var errorCode);
|
using var instance = PrepareInstance(out var cancellationTokenSource);
|
||||||
|
var errorCode = -1;
|
||||||
|
|
||||||
void OnCancelEvent(object sender, EventArgs args)
|
void OnCancelEvent(object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
|
@ -114,18 +118,18 @@ await Task.WhenAll(instance.FinishedRunning().ContinueWith(t =>
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
if (!HandleException(throwOnError, e, instance)) return false;
|
if (!HandleException(throwOnError, e, instance.ErrorData)) return false;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
CancelEvent -= OnCancelEvent;
|
CancelEvent -= OnCancelEvent;
|
||||||
_ffMpegArguments.Post();
|
_ffMpegArguments.Post();
|
||||||
}
|
}
|
||||||
|
|
||||||
return HandleCompletion(throwOnError, errorCode, instance);
|
return HandleCompletion(throwOnError, errorCode, instance.ErrorData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Instance PrepareInstance(out CancellationTokenSource cancellationTokenSource, out int errorCode)
|
private Instance PrepareInstance(out CancellationTokenSource cancellationTokenSource)
|
||||||
{
|
{
|
||||||
FFMpegHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
FFMpegHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
||||||
var instance = new Instance(FFMpegOptions.Options.FFmpegBinary(), _ffMpegArguments.Text);
|
var instance = new Instance(FFMpegOptions.Options.FFmpegBinary(), _ffMpegArguments.Text);
|
||||||
|
@ -135,18 +139,16 @@ private Instance PrepareInstance(out CancellationTokenSource cancellationTokenSo
|
||||||
if (_onTimeProgress != null || (_onPercentageProgress != null && _totalTimespan != null))
|
if (_onTimeProgress != null || (_onPercentageProgress != null && _totalTimespan != null))
|
||||||
instance.DataReceived += OutputData;
|
instance.DataReceived += OutputData;
|
||||||
|
|
||||||
errorCode = -1;
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool HandleException(bool throwOnError, Exception e, Instance instance)
|
private static bool HandleException(bool throwOnError, Exception e, IReadOnlyList<string> errorData)
|
||||||
{
|
{
|
||||||
if (!throwOnError)
|
if (!throwOnError)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
throw new FFMpegException(FFMpegExceptionType.Process, "Exception thrown during processing", e,
|
throw new FFMpegException(FFMpegExceptionType.Process, "Exception thrown during processing", e,
|
||||||
string.Join("\n", instance.ErrorData));
|
string.Join("\n", errorData));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OutputData(object sender, (DataType Type, string Data) msg)
|
private void OutputData(object sender, (DataType Type, string Data) msg)
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
<Version>1.0.12</Version>
|
<Version>1.0.12</Version>
|
||||||
<AssemblyVersion>1.1.0.0</AssemblyVersion>
|
<AssemblyVersion>1.1.0.0</AssemblyVersion>
|
||||||
<FileVersion>1.1.0.0</FileVersion>
|
<FileVersion>1.1.0.0</FileVersion>
|
||||||
<PackageReleaseNotes>- Fix NullReferenceException from parsing Format property on MediaAnalysis with information from show_format</PackageReleaseNotes>
|
<PackageReleaseNotes>- Fix for TS file extension difference between ffmpeg builds </PackageReleaseNotes>
|
||||||
<LangVersion>8</LangVersion>
|
<LangVersion>8</LangVersion>
|
||||||
<PackageVersion>2.2.1</PackageVersion>
|
<PackageVersion>2.2.2</PackageVersion>
|
||||||
<Authors>Vlad Jerca, Malte Rosenbjerg</Authors>
|
<Authors>Vlad Jerca, Malte Rosenbjerg</Authors>
|
||||||
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
|
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
|
||||||
<RepositoryType>GitHub</RepositoryType>
|
<RepositoryType>GitHub</RepositoryType>
|
||||||
|
|
Loading…
Reference in a new issue