Skip to content

Commit

Permalink
Version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Etienne Charland committed May 23, 2018
1 parent 54afd7c commit c1017bf
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 556 deletions.
16 changes: 16 additions & 0 deletions FFmpeg/EncoderApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EmergenceGuardian.FFmpeg {
/// <summary>
/// Represents the application to use for encoding.
/// </summary>
public enum EncoderApp {
Other,
FFmpeg,
x264
}
}
1 change: 1 addition & 0 deletions FFmpeg/EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public StartedEventArgs(FFmpegProcess process) {
/// </summary>
public class ProcessEventArgs : EventArgs {
public Process Process { get; set; }
public bool Handled { get; set; } = false;

public ProcessEventArgs() {
}
Expand Down
90 changes: 6 additions & 84 deletions FFmpeg/FFmpeg.csproj
Original file line number Diff line number Diff line change
@@ -1,86 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C01178B4-A869-45F8-9B2B-7683F9EBB53D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EmergenceGuardian.FFmpeg</RootNamespace>
<AssemblyName>FFmpeg</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Management" />
</ItemGroup>
<ItemGroup>
<None Include="FfmpegBusiness.cs" />
<Compile Include="CompletionStatus.cs" />
<Compile Include="FFmpegConfig.cs" />
<Compile Include="FFmpegDisplayMode.cs" />
<Compile Include="FFmpegParser.cs" />
<Compile Include="FFmpegStatus.cs" />
<Compile Include="FFmpegStream.cs" />
<Compile Include="FFmpegStreamInfo.cs" />
<Compile Include="FFmpegProcess.cs" />
<Compile Include="FFmpegStreamType.cs" />
<Compile Include="MediaProcesses.cs" />
<Compile Include="TimeLeftCalculator.cs" />
<Compile Include="UserInterfaceManagerBase.cs" />
<Compile Include="MediaInfo.cs" />
<Compile Include="MediaEncoder.cs" />
<Compile Include="MediaMuxer.cs" />
<Compile Include="CompletedEventHandler.cs" />
<Compile Include="ProcessStartOptions.cs" />
<Compile Include="EventHandlers.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

</Project>
2 changes: 1 addition & 1 deletion FFmpeg/FFmpeg.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>EmergenceGuardian.FFmpeg</id>
<version>1.0.1.0</version>
<version>1.1.0.0</version>
<title>FFmpeg.NET</title>
<authors>Etienne Charland</authors>
<owners>Etienne Charland</owners>
Expand Down
75 changes: 61 additions & 14 deletions FFmpeg/FFmpegParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ internal static FFmpegStreamInfo ParseStreamInfo(string item) {
string[] ColorSpaceValues = StreamInfo[1].Split('(', ')');
V.ColorSpace = ColorSpaceValues[0];
if (ColorSpaceValues.Length > 1) {
string[] ColorRange = ColorSpaceValues[1].Split(';');
string[] ColorRange = ColorSpaceValues[1].Split(new string[] { "; " }, StringSplitOptions.RemoveEmptyEntries);
if (ColorRange.Any(c => c == "tv"))
V.ColorRange = "tv";
else if (ColorRange.Any(c => c == "pc"))
Expand All @@ -124,10 +124,12 @@ internal static FFmpegStreamInfo ParseStreamInfo(string item) {
V.DAR2 = int.Parse(Size[7], CultureInfo.InvariantCulture);
V.DisplayAspectRatio = Math.Round((double)V.DAR1 / V.DAR2, 3);
}
string Fps = StreamInfo.First(s => s.EndsWith("fps"));
Fps = Fps.Substring(0, Fps.Length - 4);
if (Fps != "1k") // sometimes it returns 1k ?
V.FrameRate = double.Parse(Fps, CultureInfo.InvariantCulture);
string Fps = StreamInfo.FirstOrDefault(s => s.EndsWith("fps"));
if (Fps != null && Fps.Length > 4) {
Fps = Fps.Substring(0, Fps.Length - 4);
if (Fps != "1k") // sometimes it returns 1k ?
V.FrameRate = double.Parse(Fps, CultureInfo.InvariantCulture);
}
}
catch {
}
Expand Down Expand Up @@ -159,20 +161,65 @@ internal static FFmpegStreamInfo ParseStreamInfo(string item) {
/// </summary>
/// <param name="text">The raw output line from FFmpeg.</param>
/// <returns>A FFmpegProgress object.</returns>
internal static FFmpegStatus ParseProgress(string text) {
internal static FFmpegStatus ParseFFmpegProgress(string text) {
FFmpegStatus Result = new FFmpegStatus();
// frame= 929 fps=0.0 q=-0.0 size= 68483kB time=00:00:37.00 bitrate=15162.6kbits/s speed= 74x
string[] Values = text.Split('=');
try {
Result.Frame = int.Parse(Values[1].TrimStart().Split(' ')[0], CultureInfo.InvariantCulture);
Result.Fps = float.Parse(Values[2].TrimStart().Split(' ')[0], CultureInfo.InvariantCulture);
Result.Quantizer = float.Parse(Values[3].TrimStart().Split(' ')[0], CultureInfo.InvariantCulture);
Result.Size = Values[4].TrimStart().Split(' ')[0];
Result.Time = TimeSpan.Parse(Values[5].TrimStart().Split(' ')[0], CultureInfo.InvariantCulture);
Result.Bitrate = Values[6].TrimStart().Split(' ')[0];
string SpeedString = Values[7].Trim().Split('x')[0];
Result.Frame = long.Parse(ParseAttribute(text, "frame"), CultureInfo.InvariantCulture);
Result.Fps = float.Parse(ParseAttribute(text, "fps"), CultureInfo.InvariantCulture);
Result.Quantizer = float.Parse(ParseAttribute(text, "q"), CultureInfo.InvariantCulture);
Result.Size = ParseAttribute(text, "size");
Result.Time = TimeSpan.Parse(ParseAttribute(text, "time"), CultureInfo.InvariantCulture);
Result.Bitrate = ParseAttribute(text, "bitrate");
string SpeedString = ParseAttribute(text, "speed");
if (SpeedString != "N/A")
Result.Speed = float.Parse(SpeedString, CultureInfo.InvariantCulture);
Result.Speed = float.Parse(SpeedString.TrimEnd('x'), CultureInfo.InvariantCulture);
} catch {
}
return Result;
}

/// <summary>
/// Returns the value of specified attribute within a line of text. It will search 'key=' and return the following value until a space is found.
/// </summary>
/// <param name="text">The line of text to parse.</param>
/// <param name="key">The key of the attribute to look for.</param>
/// <returns></returns>
internal static string ParseAttribute(string text, string key) {
int Pos = text.IndexOf(key + "=");
if (Pos >= 0) {
// Find first non-space character.
Pos += key.Length + 1;
while (Pos < text.Length && text[Pos] == ' ') {
Pos++;
}
// Find space after value.
int PosEnd = text.IndexOf(' ', Pos);
if (PosEnd == -1)
PosEnd = text.Length;
return text.Substring(Pos, PosEnd - Pos);
} else
return null;
}

/// <summary>
/// Parses x264's progress into an object.
/// </summary>
/// <param name="text">The raw output line from FFmpeg.</param>
/// <returns>A FFmpegProgress object.</returns>
internal static FFmpegStatus ParseX264Progress(string text) {
FFmpegStatus Result = new FFmpegStatus();
if (text.Length != 48)
return Result;

// 1 0.10 10985.28 0:00:10 22.35 KB
string[] Values = text.Split('=');
try {
Result.Frame = int.Parse(text.Substring(0, 6).Trim());
Result.Fps = float.Parse(text.Substring(6, 7).Trim());
Result.Bitrate = text.Substring(13, 10).Trim();
Result.Size = text.Substring(34, 12).Trim();
}
catch {
}
Expand Down
Loading

0 comments on commit c1017bf

Please sign in to comment.