Former-commit-id: 72366d573a
This commit is contained in:
Malte Rosenbjerg 2020-05-09 17:53:03 +02:00
parent e8dcdc2238
commit c3b5cd997e
73 changed files with 238 additions and 137 deletions

View file

@ -1,7 +1,7 @@
using FFMpegCore.FFMPEG.Argument; using Microsoft.VisualStudio.TestTools.UnitTesting;
using FFMpegCore.FFMPEG.Enums;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System; using System;
using FFMpegCore.Arguments;
using FFMpegCore.Enums;
namespace FFMpegCore.Test namespace FFMpegCore.Test
{ {
@ -89,6 +89,76 @@ public void Builder_BuildString_Copy_Both()
Assert.AreEqual("-i \"input.mp4\" -c copy \"output.mp4\"", str); Assert.AreEqual("-i \"input.mp4\" -c copy \"output.mp4\"", str);
} }
[TestMethod]
public void Builder_BuildString_DisableChannel_Audio()
{
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").DisableChannel(Channel.Audio).OutputToFile("output.mp4").Arguments;
Assert.AreEqual("-i \"input.mp4\" -an \"output.mp4\"", str);
}
[TestMethod]
public void Builder_BuildString_DisableChannel_Video()
{
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").DisableChannel(Channel.Video).OutputToFile("output.mp4").Arguments;
Assert.AreEqual("-i \"input.mp4\" -vn \"output.mp4\"", str);
}
[TestMethod]
public void Builder_BuildString_DisableChannel_Both()
{
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").DisableChannel(Channel.Both).OutputToFile("output.mp4").Arguments;
Assert.AreEqual("-i \"input.mp4\" \"output.mp4\"", str);
}
[TestMethod]
public void Builder_BuildString_AudioSamplingRate_Default()
{
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithAudioSamplingRate().OutputToFile("output.mp4").Arguments;
Assert.AreEqual("-i \"input.mp4\" -ar 48000 \"output.mp4\"", str);
}
[TestMethod]
public void Builder_BuildString_AudioSamplingRate()
{
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithAudioSamplingRate(44000).OutputToFile("output.mp4").Arguments;
Assert.AreEqual("-i \"input.mp4\" -ar 44000 \"output.mp4\"", str);
}
[TestMethod]
public void Builder_BuildString_VariableBitrate()
{
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithVariableBitrate(5).OutputToFile("output.mp4").Arguments;
Assert.AreEqual("-i \"input.mp4\" -vbr 5 \"output.mp4\"", str);
}
[TestMethod]
public void Builder_BuildString_Faststart()
{
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithFastStart().OutputToFile("output.mp4").Arguments;
Assert.AreEqual("-i \"input.mp4\" -movflags faststart \"output.mp4\"", str);
}
[TestMethod]
public void Builder_BuildString_Overwrite()
{
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").OverwriteExisting().OutputToFile("output.mp4").Arguments;
Assert.AreEqual("-i \"input.mp4\" -y \"output.mp4\"", str);
}
[TestMethod]
public void Builder_BuildString_RemoveMetadata()
{
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").WithoutMetadata().OutputToFile("output.mp4").Arguments;
Assert.AreEqual("-i \"input.mp4\" -map_metadata -1 \"output.mp4\"", str);
}
[TestMethod]
public void Builder_BuildString_Transpose()
{
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").Transpose(Transposition.CounterClockwise90).OutputToFile("output.mp4").Arguments;
Assert.AreEqual("-i \"input.mp4\" -vf \"transpose=2\" \"output.mp4\"", str);
}
[TestMethod] [TestMethod]
public void Builder_BuildString_CpuSpeed() public void Builder_BuildString_CpuSpeed()
{ {
@ -170,6 +240,18 @@ public void Builder_BuildString_DrawtextFilter()
Assert.AreEqual("-i \"input.mp4\" -vf drawtext=\"text='Stack Overflow':fontfile=/path/to/font.ttf:fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2\" \"output.mp4\"", str); Assert.AreEqual("-i \"input.mp4\" -vf drawtext=\"text='Stack Overflow':fontfile=/path/to/font.ttf:fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2\" \"output.mp4\"", str);
} }
[TestMethod]
public void Builder_BuildString_DrawtextFilter_Alt()
{
var str = FFMpegArguments
.FromInputFiles(true, "input.mp4")
.DrawText(DrawTextOptions
.Create("Stack Overflow", "/path/to/font.ttf", ("fontcolor", "white"), ("fontsize", "24")))
.OutputToFile("output.mp4").Arguments;
Assert.AreEqual("-i \"input.mp4\" -vf drawtext=\"text='Stack Overflow':fontfile=/path/to/font.ttf:fontcolor=white:fontsize=24\" \"output.mp4\"", str);
}
[TestMethod] [TestMethod]
public void Builder_BuildString_StartNumber() public void Builder_BuildString_StartNumber()

View file

@ -3,8 +3,6 @@
using FFMpegCore.Test.Resources; using FFMpegCore.Test.Resources;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO; using System.IO;
using FFMpegCore.FFMPEG;
using FFMpegCore.FFMPEG.Argument;
namespace FFMpegCore.Test namespace FFMpegCore.Test
{ {

View file

@ -1,5 +1,4 @@
using FFMpegCore.FFMPEG; using FFMpegCore.Test.Resources;
using FFMpegCore.Test.Resources;
using System.IO; using System.IO;
namespace FFMpegCore.Test namespace FFMpegCore.Test

View file

@ -1,10 +1,10 @@
using FFMpegCore.Extend; using FFMpegCore.Extend;
using FFMpegCore.FFMPEG.Pipes;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Numerics; using System.Numerics;
using FFMpegCore.Pipes;
namespace FFMpegCore.Test namespace FFMpegCore.Test
{ {

View file

@ -1,5 +1,4 @@
using FFMpegCore.FFMPEG; using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.IO; using System.IO;

View file

@ -1,6 +1,5 @@
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFMpegCore.FFMPEG;
using FFMpegCore.Test.Resources; using FFMpegCore.Test.Resources;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -20,6 +19,35 @@ public void Probe_Success()
{ {
var info = FFProbe.Analyse(VideoLibrary.LocalVideo.FullName); var info = FFProbe.Analyse(VideoLibrary.LocalVideo.FullName);
Assert.AreEqual(13, info.Duration.Seconds); Assert.AreEqual(13, info.Duration.Seconds);
Assert.AreEqual(".mp4", info.Extension);
Assert.AreEqual(VideoLibrary.LocalVideo.FullName, info.Path);
Assert.AreEqual("5.1", info.PrimaryAudioStream.ChannelLayout);
Assert.AreEqual(6, info.PrimaryAudioStream.Channels);
Assert.AreEqual("AAC (Advanced Audio Coding)", info.PrimaryAudioStream.CodecLongName);
Assert.AreEqual("aac", info.PrimaryAudioStream.CodecName);
Assert.AreEqual(381988, info.PrimaryAudioStream.BitRate);
Assert.AreEqual(48000, info.PrimaryAudioStream.SampleRateHz);
Assert.AreEqual(862991, info.PrimaryVideoStream.BitRate);
Assert.AreEqual(16, info.PrimaryVideoStream.DisplayAspectRatio.Width);
Assert.AreEqual(9, info.PrimaryVideoStream.DisplayAspectRatio.Height);
Assert.AreEqual("yuv420p", info.PrimaryVideoStream.PixelFormat);
Assert.AreEqual(1280, info.PrimaryVideoStream.Width);
Assert.AreEqual(720, info.PrimaryVideoStream.Height);
Assert.AreEqual(25, info.PrimaryVideoStream.AvgFrameRate);
Assert.AreEqual(25, info.PrimaryVideoStream.FrameRate);
Assert.AreEqual("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10", info.PrimaryVideoStream.CodecLongName);
Assert.AreEqual("h264", info.PrimaryVideoStream.CodecName);
Assert.AreEqual(8, info.PrimaryVideoStream.BitsPerRawSample);
Assert.AreEqual("Main", info.PrimaryVideoStream.Profile);
}
[TestMethod]
public async Task Probe_Async_Success()
{
var info = await FFProbe.AnalyseAsync(VideoLibrary.LocalVideo.FullName);
Assert.AreEqual(13, info.Duration.Seconds);
} }
[TestMethod] [TestMethod]

View file

@ -1,8 +1,4 @@
using FFMpegCore.Enums; using FFMpegCore.Enums;
using FFMpegCore.FFMPEG.Argument;
using FFMpegCore.FFMPEG.Enums;
using FFMpegCore.FFMPEG.Exceptions;
using FFMpegCore.FFMPEG.Pipes;
using FFMpegCore.Test.Resources; using FFMpegCore.Test.Resources;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using System; using System;
@ -11,7 +7,9 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFMpegCore.FFMPEG; using FFMpegCore.Arguments;
using FFMpegCore.Exceptions;
using FFMpegCore.Pipes;
namespace FFMpegCore.Test namespace FFMpegCore.Test
{ {

View file

@ -1,11 +1,10 @@
using System; using System;
using FFMpegCore.FFMPEG.Enums;
namespace FFMpegCore.Enums namespace FFMpegCore.Enums
{ {
public static class FileExtension public static class FileExtension
{ {
public static string ForType(VideoType type) public static string Extension(this VideoType type)
{ {
return type switch return type switch
{ {
@ -16,7 +15,7 @@ public static string ForType(VideoType 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 string ForCodec(VideoCodec type) public static string Extension(this VideoCodec type)
{ {
return type switch return type switch
{ {

View file

@ -1,7 +1,6 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using FFMpegCore.FFMPEG;
namespace FFMpegCore.Extend namespace FFMpegCore.Extend
{ {

View file

@ -1,10 +1,9 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFMpegCore.FFMPEG.Pipes; using FFMpegCore.Pipes;
namespace FFMpegCore.Extend namespace FFMpegCore.Extend
{ {
@ -24,7 +23,7 @@ public BitmapVideoFrameWrapper(Bitmap bitmap)
Format = ConvertStreamFormat(bitmap.PixelFormat); Format = ConvertStreamFormat(bitmap.PixelFormat);
} }
public void Serialize(Stream stream) public void Serialize(System.IO.Stream stream)
{ {
var data = Source.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, Source.PixelFormat); var data = Source.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, Source.PixelFormat);
@ -40,7 +39,7 @@ public void Serialize(Stream stream)
} }
} }
public async Task SerializeAsync(Stream stream) public async Task SerializeAsync(System.IO.Stream stream)
{ {
var data = Source.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, Source.PixelFormat); var data = Source.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, Source.PixelFormat);

View file

@ -1,5 +1,4 @@
using System; using System;
using FFMpegCore.FFMPEG;
namespace FFMpegCore.Extend namespace FFMpegCore.Extend
{ {

View file

@ -1,6 +1,6 @@
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Enums;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents parameter of audio codec and it's quality /// Represents parameter of audio codec and it's quality

View file

@ -1,6 +1,6 @@
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Enums;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents parameter of audio codec and it's quality /// Represents parameter of audio codec and it's quality

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Audio sampling rate argument. Defaults to 48000 (Hz) /// Audio sampling rate argument. Defaults to 48000 (Hz)

View file

@ -1,6 +1,6 @@
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Enums;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents parameter of bitstream filter /// Represents parameter of bitstream filter

View file

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>

View file

@ -1,6 +1,6 @@
using System; using System;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Constant Rate Factor (CRF) argument /// Constant Rate Factor (CRF) argument

View file

@ -1,6 +1,6 @@
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Enums;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents parameter of copy parameter /// Represents parameter of copy parameter

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents cpu speed parameter /// Represents cpu speed parameter

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
public class CustomArgument : IArgument public class CustomArgument : IArgument
{ {

View file

@ -1,7 +1,7 @@
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Enums;
using FFMpegCore.FFMPEG.Exceptions; using FFMpegCore.Exceptions;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents cpu speed parameter /// Represents cpu speed parameter

View file

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Drawtext video filter argument /// Drawtext video filter argument
@ -9,9 +9,6 @@ namespace FFMpegCore.FFMPEG.Argument
public class DrawTextArgument : IArgument public class DrawTextArgument : IArgument
{ {
public readonly DrawTextOptions Options; public readonly DrawTextOptions Options;
public DrawTextArgument(string text, string fontPath, params (string, string)[] optionalArguments)
: this(DrawTextOptions.Create(text, fontPath, optionalArguments)) { }
public DrawTextArgument(DrawTextOptions options) public DrawTextArgument(DrawTextOptions options)
{ {
@ -31,7 +28,7 @@ public static DrawTextOptions Create(string text, string font)
{ {
return new DrawTextOptions(text, font, new List<(string, string)>()); return new DrawTextOptions(text, font, new List<(string, string)>());
} }
public static DrawTextOptions Create(string text, string font, IEnumerable<(string key, string value)> parameters) public static DrawTextOptions Create(string text, string font, params (string key, string value)[] parameters)
{ {
return new DrawTextOptions(text, font, parameters); return new DrawTextOptions(text, font, parameters);
} }

View file

@ -1,6 +1,6 @@
using System; using System;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents duration parameter /// Represents duration parameter

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Faststart argument - for moving moov atom to the start of file /// Faststart argument - for moving moov atom to the start of file

View file

@ -1,6 +1,6 @@
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Enums;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents force format parameter /// Represents force format parameter

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents frame output count parameter /// Represents frame output count parameter
@ -6,8 +6,6 @@
public class FrameOutputCountArgument : IArgument public class FrameOutputCountArgument : IArgument
{ {
public readonly int Frames; public readonly int Frames;
public FrameOutputCountArgument() { }
public FrameOutputCountArgument(int frames) public FrameOutputCountArgument(int frames)
{ {
Frames = frames; Frames = frames;

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents frame rate parameter /// Represents frame rate parameter

View file

@ -4,7 +4,7 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents input parameter /// Represents input parameter
@ -41,19 +41,23 @@ public void Pre()
public interface IArgument public interface IArgument
{ {
/// <summary>
/// The textual representation of the argument
/// </summary>
string Text { get; } string Text { get; }
}
public interface IInputOutputArgument : IArgument
{
void Pre() {}
Task During(CancellationToken? cancellationToken = null) => Task.CompletedTask;
void Post() {}
} }
public interface IInputArgument : IArgument public interface IInputArgument : IInputOutputArgument
{ {
void Pre() {}
Task During(CancellationToken? cancellationToken = null) => Task.CompletedTask;
void Post() {}
} }
public interface IOutputArgument : IArgument public interface IOutputArgument : IInputOutputArgument
{ {
void Pre() {}
Task During(CancellationToken? cancellationToken = null) => Task.CompletedTask;
void Post() {}
} }
} }

View file

@ -1,9 +1,9 @@
using System.IO.Pipes; using System.IO.Pipes;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFMpegCore.FFMPEG.Pipes; using FFMpegCore.Pipes;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents input parameter for a named pipe /// Represents input parameter for a named pipe

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents loop parameter /// Represents loop parameter

View file

@ -1,8 +1,8 @@
using System; using System;
using System.IO; using System.IO;
using FFMpegCore.FFMPEG.Exceptions; using FFMpegCore.Exceptions;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents output parameter /// Represents output parameter

View file

@ -1,9 +1,9 @@
using System.IO.Pipes; using System.IO.Pipes;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFMpegCore.FFMPEG.Pipes; using FFMpegCore.Pipes;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
public class OutputPipeArgument : PipeArgument public class OutputPipeArgument : PipeArgument
{ {

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents overwrite parameter /// Represents overwrite parameter

View file

@ -2,9 +2,9 @@
using System.IO.Pipes; using System.IO.Pipes;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFMpegCore.FFMPEG.Pipes; using FFMpegCore.Pipes;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
public abstract class PipeArgument : IInputArgument, IOutputArgument public abstract class PipeArgument : IInputArgument, IOutputArgument
{ {

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
public class QuietArgument : IArgument public class QuietArgument : IArgument
{ {

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Remove metadata argument /// Remove metadata argument

View file

@ -1,7 +1,7 @@
using System.Drawing; using System.Drawing;
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Enums;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents scale parameter /// Represents scale parameter

View file

@ -1,6 +1,6 @@
using System; using System;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents seek parameter /// Represents seek parameter

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents shortest parameter /// Represents shortest parameter

View file

@ -1,7 +1,7 @@
using System.Drawing; using System.Drawing;
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Enums;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents size parameter /// Represents size parameter

View file

@ -1,6 +1,6 @@
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Enums;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents speed parameter /// Represents speed parameter

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents start number parameter /// Represents start number parameter

View file

@ -1,6 +1,6 @@
using System; using System;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents threads parameter /// Represents threads parameter

View file

@ -1,6 +1,6 @@
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Enums;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Transpose argument. /// Transpose argument.

View file

@ -1,6 +1,6 @@
using System; using System;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Variable Bitrate Argument (VBR) argument /// Variable Bitrate Argument (VBR) argument

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents video bitrate parameter /// Represents video bitrate parameter

View file

@ -1,6 +1,6 @@
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Enums;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore.Arguments
{ {
/// <summary> /// <summary>
/// Represents video codec parameter /// Represents video codec parameter

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Enums namespace FFMpegCore.Enums
{ {
public enum AudioQuality public enum AudioQuality
{ {

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Enums namespace FFMpegCore.Enums
{ {
public enum VideoCodec public enum VideoCodec
{ {

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Enums namespace FFMpegCore.Enums
{ {
public enum Speed public enum Speed
{ {

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Enums namespace FFMpegCore.Enums
{ {
public enum Transposition public enum Transposition
{ {

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG.Enums namespace FFMpegCore.Enums
{ {
public enum VideoSize public enum VideoSize
{ {

View file

@ -1,6 +1,6 @@
using System; using System;
namespace FFMpegCore.FFMPEG.Exceptions namespace FFMpegCore.Exceptions
{ {
public enum FFMpegExceptionType public enum FFMpegExceptionType
{ {

View file

@ -5,11 +5,9 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using FFMpegCore.Enums; using FFMpegCore.Enums;
using FFMpegCore.FFMPEG.Argument;
using FFMpegCore.FFMPEG.Enums;
using FFMpegCore.Helpers; using FFMpegCore.Helpers;
namespace FFMpegCore.FFMPEG namespace FFMpegCore
{ {
public static class FFMpeg public static class FFMpeg
{ {
@ -98,7 +96,7 @@ public static bool Convert(
AudioQuality audioQuality = AudioQuality.Normal, AudioQuality audioQuality = AudioQuality.Normal,
bool multithreaded = false) bool multithreaded = false)
{ {
FFMpegHelper.ExtensionExceptionCheck(output, FileExtension.ForType(type)); FFMpegHelper.ExtensionExceptionCheck(output, type.Extension());
FFMpegHelper.ConversionSizeExceptionCheck(source); FFMpegHelper.ConversionSizeExceptionCheck(source);
var scale = VideoSize.Original == size ? 1 : (double)source.PrimaryVideoStream.Height / (int)size; var scale = VideoSize.Original == size ? 1 : (double)source.PrimaryVideoStream.Height / (int)size;

View file

@ -7,7 +7,7 @@
using FFMpegCore.Helpers; using FFMpegCore.Helpers;
using Instances; using Instances;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore
{ {
public class FFMpegArgumentProcessor public class FFMpegArgumentProcessor
{ {

View file

@ -5,10 +5,11 @@
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFMpegCore.FFMPEG.Enums; using FFMpegCore.Arguments;
using FFMpegCore.FFMPEG.Pipes; using FFMpegCore.Enums;
using FFMpegCore.Pipes;
namespace FFMpegCore.FFMPEG.Argument namespace FFMpegCore
{ {
public class FFMpegArguments public class FFMpegArguments
{ {
@ -71,7 +72,7 @@ private FFMpegArguments(IInputArgument inputArgument)
public FFMpegArguments WithCustomArgument(string argument) => WithArgument(new CustomArgument(argument)); public FFMpegArguments WithCustomArgument(string argument) => WithArgument(new CustomArgument(argument));
public FFMpegArguments Seek(TimeSpan? seekTo) => WithArgument(new SeekArgument(seekTo)); public FFMpegArguments Seek(TimeSpan? seekTo) => WithArgument(new SeekArgument(seekTo));
public FFMpegArguments Transpose(TimeSpan? seekTo) => WithArgument(new SeekArgument(seekTo)); public FFMpegArguments Transpose(Transposition transposition) => WithArgument(new TransposeArgument(transposition));
public FFMpegArguments Loop(int times) => WithArgument(new LoopArgument(times)); public FFMpegArguments Loop(int times) => WithArgument(new LoopArgument(times));
public FFMpegArguments OverwriteExisting() => WithArgument(new OverwriteArgument()); public FFMpegArguments OverwriteExisting() => WithArgument(new OverwriteArgument());
public FFMpegArguments Quiet() => WithArgument(new QuietArgument()); public FFMpegArguments Quiet() => WithArgument(new QuietArgument());

View file

@ -3,7 +3,7 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.Json; using System.Text.Json;
namespace FFMpegCore.FFMPEG namespace FFMpegCore
{ {
public class FFMpegOptions public class FFMpegOptions
{ {

View file

@ -1,6 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Pipes namespace FFMpegCore.Pipes
{ {
public interface IPipeDataReader public interface IPipeDataReader
{ {

View file

@ -1,6 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Pipes namespace FFMpegCore.Pipes
{ {
/// <summary> /// <summary>
/// Interface for ffmpeg pipe source data IO /// Interface for ffmpeg pipe source data IO

View file

@ -1,6 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Pipes namespace FFMpegCore.Pipes
{ {
/// <summary> /// <summary>
/// Interface for Video frame /// Interface for Video frame

View file

@ -1,14 +1,18 @@
using System; using System;
using System.Runtime.InteropServices;
namespace FFMpegCore.FFMPEG.Pipes namespace FFMpegCore.Pipes
{ {
static class PipeHelpers static class PipeHelpers
{ {
public static string GetUnqiuePipeName() => "FFMpegCore_Pipe_" + Guid.NewGuid(); public static string GetUnqiuePipeName() => "FFMpegCore_" + Guid.NewGuid();
public static string GetPipePath(string pipeName) public static string GetPipePath(string pipeName)
{ {
return $@"\\.\pipe\{pipeName}"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return $@"\\.\pipe\{pipeName}";
else
return $"unix:/tmp/CoreFxPipe_{pipeName}"; // dotnet uses unix sockets on unix, for more see https://github.com/dotnet/runtime/issues/24390
} }
} }
} }

View file

@ -1,9 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFMpegCore.FFMPEG.Exceptions; using FFMpegCore.Exceptions;
namespace FFMpegCore.FFMPEG.Pipes namespace FFMpegCore.Pipes
{ {
/// <summary> /// <summary>
/// Implementation of <see cref="IPipeDataWriter"/> for a raw video stream that is gathered from <see cref="IEnumerator{IVideoFrame}"/> /// Implementation of <see cref="IPipeDataWriter"/> for a raw video stream that is gathered from <see cref="IEnumerator{IVideoFrame}"/>

View file

@ -1,6 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Pipes namespace FFMpegCore.Pipes
{ {
public class StreamPipeDataReader : IPipeDataReader public class StreamPipeDataReader : IPipeDataReader
{ {

View file

@ -1,6 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Pipes namespace FFMpegCore.Pipes
{ {
/// <summary> /// <summary>
/// Implementation of <see cref="IPipeDataWriter"/> used for stream redirection /// Implementation of <see cref="IPipeDataWriter"/> used for stream redirection

View file

@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=ffmpeg/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=ffprobe/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View file

@ -1,4 +1,4 @@
namespace FFMpegCore.FFMPEG namespace FFMpegCore
{ {
public class AudioStream : MediaStream public class AudioStream : MediaStream
{ {

View file

@ -2,13 +2,13 @@
using System.IO; using System.IO;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFMpegCore.FFMPEG.Argument; using FFMpegCore.Arguments;
using FFMpegCore.FFMPEG.Exceptions; using FFMpegCore.Exceptions;
using FFMpegCore.FFMPEG.Pipes;
using FFMpegCore.Helpers; using FFMpegCore.Helpers;
using FFMpegCore.Pipes;
using Instances; using Instances;
namespace FFMpegCore.FFMPEG namespace FFMpegCore
{ {
public static class FFProbe public static class FFProbe
{ {

View file

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace FFMpegCore.FFMPEG namespace FFMpegCore
{ {
public class FFProbeAnalysis public class FFProbeAnalysis
{ {
@ -37,9 +37,6 @@ public class Stream
[JsonPropertyName("codec_long_name")] [JsonPropertyName("codec_long_name")]
public string CodecLongName { get; set; } = null!; public string CodecLongName { get; set; } = null!;
[JsonPropertyName("codec_tag_string")]
public string CodecTagString { get; set; } = null!;
[JsonPropertyName("display_aspect_ratio")] [JsonPropertyName("display_aspect_ratio")]
public string DisplayAspectRatio { get; set; } = null!; public string DisplayAspectRatio { get; set; } = null!;

View file

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace FFMpegCore.FFMPEG namespace FFMpegCore
{ {
public class MediaAnalysis public class MediaAnalysis
{ {
@ -41,7 +41,7 @@ private VideoStream ParseVideoStream(Stream stream)
CodecLongName = stream.CodecLongName, CodecLongName = stream.CodecLongName,
DisplayAspectRatio = ParseRatioInt(stream.DisplayAspectRatio, ':'), DisplayAspectRatio = ParseRatioInt(stream.DisplayAspectRatio, ':'),
Duration = ParseDuration(stream), Duration = ParseDuration(stream),
FrameRate = DivideRatio(ParseRatioDouble(stream.AvgFrameRate, '/')), FrameRate = DivideRatio(ParseRatioDouble(stream.FrameRate, '/')),
Height = stream.Height!.Value, Height = stream.Height!.Value,
Width = stream.Width!.Value, Width = stream.Width!.Value,
Profile = stream.Profile, Profile = stream.Profile,
@ -74,15 +74,15 @@ private AudioStream ParseAudioStream(Stream stream)
private static double DivideRatio((double, double) ratio) => ratio.Item1 / ratio.Item2; private static double DivideRatio((double, double) ratio) => ratio.Item1 / ratio.Item2;
private static (int, int) ParseRatioInt(string input, char separator) private static (int, int) ParseRatioInt(string input, char separator)
{ {
if (string.IsNullOrEmpty(input)) return (default, default); if (string.IsNullOrEmpty(input)) return (0, 0);
var ratio = input.Split(separator); var ratio = input.Split(separator);
return (int.Parse(ratio[0]), int.Parse(ratio[1])); return (int.Parse(ratio[0]), int.Parse(ratio[1]));
} }
private static (double, double) ParseRatioDouble(string input, char separator) private static (double, double) ParseRatioDouble(string input, char separator)
{ {
if (string.IsNullOrEmpty(input)) return (default, default); if (string.IsNullOrEmpty(input)) return (0, 0);
var ratio = input.Split(separator); var ratio = input.Split(separator);
return (ratio.Length > 0 ? int.Parse(ratio[0]) : default, ratio.Length > 1 ? int.Parse(ratio[1]) : default); return (ratio.Length > 0 ? double.Parse(ratio[0]) : 0, ratio.Length > 1 ? double.Parse(ratio[1]) : 0);
} }
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
namespace FFMpegCore.FFMPEG namespace FFMpegCore
{ {
public class MediaStream public class MediaStream
{ {

View file

@ -1,10 +1,10 @@
namespace FFMpegCore.FFMPEG namespace FFMpegCore
{ {
public class VideoStream : MediaStream public class VideoStream : MediaStream
{ {
public double AvgFrameRate { get; internal set; } public double AvgFrameRate { get; internal set; }
public int BitsPerRawSample { get; internal set; } public int BitsPerRawSample { get; internal set; }
public (int width, int height) DisplayAspectRatio { get; internal set; } public (int Width, int Height) DisplayAspectRatio { get; internal set; }
public string Profile { get; internal set; } = null!; public string Profile { get; internal set; } = null!;
public int Width { get; internal set; } public int Width { get; internal set; }
public int Height { get; internal set; } public int Height { get; internal set; }

View file

@ -1,8 +1,7 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using FFMpegCore.FFMPEG; using FFMpegCore.Exceptions;
using FFMpegCore.FFMPEG.Exceptions;
namespace FFMpegCore.Helpers namespace FFMpegCore.Helpers
{ {

View file

@ -1,4 +1,4 @@
using FFMpegCore.FFMPEG.Exceptions; using FFMpegCore.Exceptions;
namespace FFMpegCore.Helpers namespace FFMpegCore.Helpers
{ {