Merge remote-tracking branch 'fork/master' into feature/piping

Former-commit-id: 9431f865e3
This commit is contained in:
Максим Багрянцев 2020-04-27 19:42:56 +03:00
commit f93566e749
3 changed files with 36 additions and 18 deletions

View file

@ -0,0 +1,18 @@
namespace FFMpegCore.FFMPEG.Argument
{
/// <summary>
/// Audio sampling rate argument. Defaults to 48000 (Hz)
/// </summary>
public class AudioSamplingRateArgument : Argument<int>
{
public AudioSamplingRateArgument() : base(48000) { }
public AudioSamplingRateArgument(int samplingRate) : base(samplingRate) { }
/// <inheritdoc/>
public override string GetStringValue()
{
return $"-ar {Value}";
}
}
}

View file

@ -88,7 +88,7 @@ public Bitmap Snapshot(VideoInfo source, FileInfo output, Size? size = null, Tim
new OutputArgument(output) new OutputArgument(output)
); );
if (!RunProcess(container, output)) if (!RunProcess(container, output, false))
{ {
throw new OperationCanceledException("Could not take snapshot!"); throw new OperationCanceledException("Could not take snapshot!");
} }
@ -198,7 +198,7 @@ public VideoInfo PosterWithAudio(FileInfo image, FileInfo audio, FileInfo output
new ShortestArgument(true), new ShortestArgument(true),
new OutputArgument(output) new OutputArgument(output)
); );
if (!RunProcess(container, output)) if (!RunProcess(container, output, false))
{ {
throw new FFMpegException(FFMpegExceptionType.Operation, throw new FFMpegException(FFMpegExceptionType.Operation,
"An error occured while adding the audio file to the image."); "An error occured while adding the audio file to the image.");
@ -274,7 +274,7 @@ public VideoInfo JoinImageSequence(FileInfo output, double frameRate = 30, param
try try
{ {
if (!RunProcess(container, output)) if (!RunProcess(container, output, false))
{ {
throw new FFMpegException(FFMpegExceptionType.Operation, throw new FFMpegException(FFMpegExceptionType.Operation,
"Could not join the provided image sequence."); "Could not join the provided image sequence.");
@ -346,7 +346,7 @@ public FileInfo ExtractAudio(VideoInfo source, FileInfo output)
new OutputArgument(output) new OutputArgument(output)
); );
if (!RunProcess(container, output)) if (!RunProcess(container, output, false))
{ {
throw new FFMpegException(FFMpegExceptionType.Operation, throw new FFMpegException(FFMpegExceptionType.Operation,
"Could not extract the audio from the requested video."); "Could not extract the audio from the requested video.");
@ -381,26 +381,26 @@ public VideoInfo ReplaceAudio(VideoInfo source, FileInfo audio, FileInfo output,
)); ));
} }
public VideoInfo Convert(ArgumentContainer arguments) public VideoInfo Convert(ArgumentContainer arguments, bool skipExistsCheck = false)
{ {
var (sources, output) = GetInputOutput(arguments); var (sources, output) = GetInputOutput(arguments);
if (sources != null) if (sources != null)
_totalTime = TimeSpan.FromSeconds(sources.Sum(source => source.Duration.TotalSeconds)); _totalTime = TimeSpan.FromSeconds(sources.Sum(source => source.Duration.TotalSeconds));
if (!RunProcess(arguments, output)) if (!RunProcess(arguments, output, skipExistsCheck))
throw new FFMpegException(FFMpegExceptionType.Operation, "Could not replace the video audio."); throw new FFMpegException(FFMpegExceptionType.Conversion, "Could not process file without error");
_totalTime = TimeSpan.MinValue; _totalTime = TimeSpan.MinValue;
return new VideoInfo(output); return new VideoInfo(output);
} }
public async Task<VideoInfo> ConvertAsync(ArgumentContainer arguments) public async Task<VideoInfo> ConvertAsync(ArgumentContainer arguments, bool skipExistsCheck = false)
{ {
var (sources, output) = GetInputOutput(arguments); var (sources, output) = GetInputOutput(arguments);
if (sources != null) if (sources != null)
_totalTime = TimeSpan.FromSeconds(sources.Sum(source => source.Duration.TotalSeconds)); _totalTime = TimeSpan.FromSeconds(sources.Sum(source => source.Duration.TotalSeconds));
if (!await RunProcessAsync(arguments, output)) if (!await RunProcessAsync(arguments, output, skipExistsCheck))
throw new FFMpegException(FFMpegExceptionType.Operation, "Could not replace the video audio."); throw new FFMpegException(FFMpegExceptionType.Conversion, "Could not process file without error");
_totalTime = TimeSpan.MinValue; _totalTime = TimeSpan.MinValue;
return new VideoInfo(output); return new VideoInfo(output);
@ -442,7 +442,7 @@ public void Stop()
private readonly string _ffmpegPath; private readonly string _ffmpegPath;
private TimeSpan _totalTime; private TimeSpan _totalTime;
private bool RunProcess(ArgumentContainer container, FileInfo output) private bool RunProcess(ArgumentContainer container, FileInfo output, bool skipExistsCheck)
{ {
_instance?.Dispose(); _instance?.Dispose();
var arguments = ArgumentBuilder.BuildArguments(container); var arguments = ArgumentBuilder.BuildArguments(container);
@ -478,7 +478,7 @@ private bool RunProcess(ArgumentContainer container, FileInfo output)
exitCode = _instance.BlockUntilFinished(); exitCode = _instance.BlockUntilFinished();
} }
if (!File.Exists(output.FullName) || new FileInfo(output.FullName).Length == 0) if (!skipExistsCheck && (!File.Exists(output.FullName) || new FileInfo(output.FullName).Length == 0))
throw new FFMpegException(FFMpegExceptionType.Process, string.Join("\n", _instance.ErrorData)); throw new FFMpegException(FFMpegExceptionType.Process, string.Join("\n", _instance.ErrorData));
return exitCode == 0; return exitCode == 0;
@ -489,10 +489,11 @@ private bool RunProcess(ArgumentContainer container, FileInfo output)
inputPipeArgument.ClosePipe(); inputPipeArgument.ClosePipe();
} }
} }
private async Task<bool> RunProcessAsync(ArgumentContainer container, FileInfo output) private async Task<bool> RunProcessAsync(ArgumentContainer container, FileInfo output, bool skipExistsCheck)
{ {
_instance?.Dispose(); _instance?.Dispose();
var arguments = ArgumentBuilder.BuildArguments(container); var arguments = ArgumentBuilder.BuildArguments(container);
int exitCode = -1; int exitCode = -1;
if (container.TryGetArgument<InputPipeArgument>(out var inputPipeArgument)) if (container.TryGetArgument<InputPipeArgument>(out var inputPipeArgument))
{ {
@ -517,7 +518,7 @@ private async Task<bool> RunProcessAsync(ArgumentContainer container, FileInfo o
exitCode = await _instance.FinishedRunning(); exitCode = await _instance.FinishedRunning();
} }
if (!File.Exists(output.FullName) || new FileInfo(output.FullName).Length == 0) if (!skipExistsCheck && (!File.Exists(output.FullName) || new FileInfo(output.FullName).Length == 0))
throw new FFMpegException(FFMpegExceptionType.Process, string.Join("\n", _instance.ErrorData)); throw new FFMpegException(FFMpegExceptionType.Process, string.Join("\n", _instance.ErrorData));
return exitCode == 0; return exitCode == 0;

View file

@ -10,10 +10,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>Add more argument types and make ffprobe output capacity configurable <PackageReleaseNotes>Adds AudioSamplingRateArgument </PackageReleaseNotes>
Update dependency </PackageReleaseNotes>
<LangVersion>8</LangVersion> <LangVersion>8</LangVersion>
<PackageVersion>1.3.1</PackageVersion> <PackageVersion>1.3.3</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>